Skip to content

Commit

Permalink
add failing test for calling FIle I/O in macro
Browse files Browse the repository at this point in the history
  • Loading branch information
brainkim committed Dec 26, 2024
1 parent b8f28ed commit 068765e
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
41 changes: 41 additions & 0 deletions test/bundler/bundler_macro.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { describe, expect } from "bun:test";
import { join } from "node:path";
import { itBundled } from "./expectBundled";
const fixturePath = join(import.meta.dir, "fixtures/hello.txt");
const macros = /* js */ String.raw`
export function identity(arg: any) {
return arg;
}
export function file(): Promise<string> {
return Bun.file(${JSON.stringify(fixturePath)}).text();
}
`;

describe("bundler", () => {
itBundled("identity macro", {
files: {
"/entry.ts": /* js */ `
import {identity} from "./macros.ts" with {type: "macro"};
console.log(identity(100));
`,
"/macros.ts": macros,
},
run: {
stdout: "100",
},
});

itBundled("file macro", {
files: {
"/entry.ts": /* js */ `
import {file} from "./macros.ts" with {type: "macro"};
console.log(file());
`,
"/macros.ts": macros,
},
run: {
stdout: "hello world\n123456\n",
},
});
});
2 changes: 2 additions & 0 deletions test/bundler/fixtures/hello.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
hello world
123456

0 comments on commit 068765e

Please sign in to comment.