diff options
author | 2023-08-20 16:52:17 +0800 | |
---|---|---|
committer | 2023-08-20 01:52:17 -0700 | |
commit | 3a9a6c63ac58564d8bae126a3edfc368ca4be671 (patch) | |
tree | 4f39dec7658d733bf6dd12cc8df5749957a56c0a /test | |
parent | 360acf5a80d7e0191d13b87226c8122a633f701f (diff) | |
download | bun-3a9a6c63ac58564d8bae126a3edfc368ca4be671.tar.gz bun-3a9a6c63ac58564d8bae126a3edfc368ca4be671.tar.zst bun-3a9a6c63ac58564d8bae126a3edfc368ca4be671.zip |
Fix(bundler): use different alias mappings based on the target. (#4163)
* Fix(bundler): use different alias mappings based on the target.
Close: #3844
* chore: reduce duplicated code.
* chore: split to two separate ComptimeStringMap.
Diffstat (limited to 'test')
-rw-r--r-- | test/bundler/bun-build-api.test.ts | 28 | ||||
-rw-r--r-- | test/bundler/fixtures/trivial/bundle-ws.ts | 3 |
2 files changed, 31 insertions, 0 deletions
diff --git a/test/bundler/bun-build-api.test.ts b/test/bundler/bun-build-api.test.ts index 3b528b7be..3c2308d94 100644 --- a/test/bundler/bun-build-api.test.ts +++ b/test/bundler/bun-build-api.test.ts @@ -262,4 +262,32 @@ describe("Bun.build", () => { expect(x.logs[0].name).toBe("BuildMessage"); expect(x.logs[0].position).toBeTruthy(); }); + + test("test bun target", async () => { + const x = await Bun.build({ + entrypoints: [join(import.meta.dir, "./fixtures/trivial/bundle-ws.ts")], + target: "bun", + }); + expect(x.success).toBe(true); + const [blob] = x.outputs; + const content = await blob.text(); + + // use bun's ws + expect(content).toContain('import {WebSocket} from "ws"'); + expect(content).not.toContain("var websocket = __toESM(require_websocket(), 1);"); + }); + + test("test node target, issue #3844", async () => { + const x = await Bun.build({ + entrypoints: [join(import.meta.dir, "./fixtures/trivial/bundle-ws.ts")], + target: "node", + }); + expect(x.success).toBe(true); + const [blob] = x.outputs; + const content = await blob.text(); + + expect(content).not.toContain('import {WebSocket} from "ws"'); + // depends on the ws package in the test/node_modules. + expect(content).toContain("var websocket = __toESM(require_websocket(), 1);"); + }); }); diff --git a/test/bundler/fixtures/trivial/bundle-ws.ts b/test/bundler/fixtures/trivial/bundle-ws.ts new file mode 100644 index 000000000..0064bfdd9 --- /dev/null +++ b/test/bundler/fixtures/trivial/bundle-ws.ts @@ -0,0 +1,3 @@ +import { WebSocket } from "ws"; + +console.log(WebSocket); |