diff options
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); |