diff options
author | 2022-01-19 23:07:03 -0800 | |
---|---|---|
committer | 2022-01-19 23:07:03 -0800 | |
commit | a09b99565138bb4bc73a5328397428fb5025817b (patch) | |
tree | 3412ae330b4a6078173d0048665b9d547b3d718b /integration/bunjs-only-snippets/transpiler.test.js | |
parent | 4098484ff5d1c66a5f146e773a9be25cbcd2a1f4 (diff) | |
download | bun-a09b99565138bb4bc73a5328397428fb5025817b.tar.gz bun-a09b99565138bb4bc73a5328397428fb5025817b.tar.zst bun-a09b99565138bb4bc73a5328397428fb5025817b.zip |
Bun.Transpiler – API for scanning imports/exports of JSX/TSX/TS/JS files
Diffstat (limited to 'integration/bunjs-only-snippets/transpiler.test.js')
-rw-r--r-- | integration/bunjs-only-snippets/transpiler.test.js | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/integration/bunjs-only-snippets/transpiler.test.js b/integration/bunjs-only-snippets/transpiler.test.js new file mode 100644 index 000000000..2c59c10b8 --- /dev/null +++ b/integration/bunjs-only-snippets/transpiler.test.js @@ -0,0 +1,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); + }); + }); +}); |