1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
import { expect, it, describe } from "bun:test";
describe("Bun.Transpiler", () => {
const transpiler = new Bun.Transpiler({
loader: "tsx",
define: {
"process.env.NODE_ENV": JSON.stringify("development"),
},
platform: "browser",
});
const code = `import { useParams } from "remix";
import type { LoaderFunction, ActionFunction } from "remix";
export const loader: LoaderFunction = async ({
params
}) => {
console.log(params.postId);
};
export const action: ActionFunction = async ({
params
}) => {
console.log(params.postId);
};
export default function PostRoute() {
const params = useParams();
console.log(params.postId);
}
`;
describe("scanImports", () => {
it("reports import paths, excluding types", () => {
const imports = transpiler.scanImports(code);
expect(imports.filter(({ path }) => path === "remix")).toHaveLength(1);
});
});
describe("scan", () => {
it("reports all export names", () => {
const { imports, exports } = transpiler.scan(code);
expect(exports[0]).toBe("loader");
expect(exports[1]).toBe("action");
expect(exports[2]).toBe("default");
expect(exports).toHaveLength(3);
});
});
});
|