diff options
author | 2022-01-21 18:12:46 -0800 | |
---|---|---|
committer | 2022-01-21 18:12:46 -0800 | |
commit | 3e803b3a58e1d655e8a3e3c4a92fb0e40016dec8 (patch) | |
tree | e52d5a2fae92c95df4f1f7ce5bc3315b428e66d2 /integration/bunjs-only-snippets/transpiler.test.js | |
parent | 22c01ca14c72b73e64472b24f8adb227b586d3e6 (diff) | |
download | bun-3e803b3a58e1d655e8a3e3c4a92fb0e40016dec8.tar.gz bun-3e803b3a58e1d655e8a3e3c4a92fb0e40016dec8.tar.zst bun-3e803b3a58e1d655e8a3e3c4a92fb0e40016dec8.zip |
Add test coverage for macro import behavior
Diffstat (limited to 'integration/bunjs-only-snippets/transpiler.test.js')
-rw-r--r-- | integration/bunjs-only-snippets/transpiler.test.js | 40 |
1 files changed, 37 insertions, 3 deletions
diff --git a/integration/bunjs-only-snippets/transpiler.test.js b/integration/bunjs-only-snippets/transpiler.test.js index 34ec9f4aa..16956abfe 100644 --- a/integration/bunjs-only-snippets/transpiler.test.js +++ b/integration/bunjs-only-snippets/transpiler.test.js @@ -6,6 +6,11 @@ describe("Bun.Transpiler", () => { define: { "process.env.NODE_ENV": JSON.stringify("development"), }, + macro: { + react: { + bacon: `${import.meta.dir}/macro-check.js`, + }, + }, platform: "browser", }); @@ -56,7 +61,7 @@ describe("Bun.Transpiler", () => { import {keepSecondArgument} from 'macro:${ import.meta.dir }/macro-check.js'; - + export default keepSecondArgument("Test failed", "Test passed"); `); expect(out.includes("Test failed")).toBe(false); @@ -66,12 +71,12 @@ describe("Bun.Transpiler", () => { expect(out.includes("keepSecondArgument")).toBe(false); }); - it("sync supports macros", async () => { + it("sync supports macros", () => { const out = transpiler.transformSync(` import {keepSecondArgument} from 'macro:${ import.meta.dir }/macro-check.js'; - + export default keepSecondArgument("Test failed", "Test passed"); `); expect(out.includes("Test failed")).toBe(false); @@ -80,6 +85,35 @@ describe("Bun.Transpiler", () => { expect(out.includes("keepSecondArgument")).toBe(false); }); + it("sync supports macros remap", () => { + const out = transpiler.transformSync(` + import {createElement, bacon} from 'react'; + + export default bacon("Test failed", "Test passed"); + export function hi() { createElement("hi"); } + `); + + expect(out.includes("Test failed")).toBe(false); + expect(out.includes("Test passed")).toBe(true); + + expect(out.includes("bacon")).toBe(false); + expect(out.includes("createElement")).toBe(true); + }); + + it("macro remap removes import statement if its the only used one", () => { + const out = transpiler.transformSync(` + import {bacon} from 'react'; + + export default bacon("Test failed", "Test passed"); + `); + + expect(out.includes("Test failed")).toBe(false); + expect(out.includes("Test passed")).toBe(true); + + expect(out.includes("bacon")).toBe(false); + expect(out.includes("import")).toBe(false); + }); + it("removes types", () => { expect(code.includes("ActionFunction")).toBe(true); expect(code.includes("LoaderFunction")).toBe(true); |