diff options
author | 2023-01-12 15:37:03 -0800 | |
---|---|---|
committer | 2023-01-12 15:37:03 -0800 | |
commit | 0384d3c558b3f8e879fd5292d1613cc618962542 (patch) | |
tree | ae14075e9bda296f47397a02b49d49b765cc41b6 | |
parent | 00773e15f1e776aa6447bd607968623b3923d21a (diff) | |
download | bun-0384d3c558b3f8e879fd5292d1613cc618962542.tar.gz bun-0384d3c558b3f8e879fd5292d1613cc618962542.tar.zst bun-0384d3c558b3f8e879fd5292d1613cc618962542.zip |
less flaky
-rw-r--r-- | test/bun.js/esbuild-child_process.test.ts | 63 | ||||
-rw-r--r-- | test/bun.js/esbuild-test.js | 37 |
2 files changed, 54 insertions, 46 deletions
diff --git a/test/bun.js/esbuild-child_process.test.ts b/test/bun.js/esbuild-child_process.test.ts index 511779d9f..d64786602 100644 --- a/test/bun.js/esbuild-child_process.test.ts +++ b/test/bun.js/esbuild-child_process.test.ts @@ -1,49 +1,20 @@ -import { transform, transformSync } from "esbuild"; -import { describe, it, expect } from "bun:test"; +import { spawnSync } from "bun"; +import { describe, it, expect, test } from "bun:test"; +import { bunExe } from "bunExe"; -describe("child_process.spawn - esbuild", () => { - it("should transform successfully", async () => { - const result = await transform("console.log('hello world')", { - loader: "js", - target: "node12", - }); - expect(result.code).toBe('console.log("hello world");\n'); - }); +test("esbuild", () => { + const { exitCode, stderr, stdout } = spawnSync( + [bunExe(), import.meta.dir + "/esbuild-test.js"], + { + env: { + BUN_DEBUG_QUIET_LOGS: "1", + }, + }, + ); + const out = "" + stderr?.toString() + stdout?.toString(); + if (exitCode !== 0 && out?.length) { + throw new Error(out); + } - it("works for input exceeding the pipe capacity", async () => { - const hugeString = `console.log(${JSON.stringify("a".repeat(1000000))});`; - - for (let i = 0; i < 2; i++) { - const result = await transform(hugeString, { - loader: "js", - target: "node12", - }); - expect(result.code).toBe(hugeString + "\n"); - } - }); -}); - -describe("child_process.spawnSync - esbuild", () => { - it("should transform successfully", () => { - const result = transformSync("console.log('hello world')", { - loader: "js", - target: "node12", - }); - expect(result.code).toBe('console.log("hello world");\n'); - }); - - // This test is failing with the following error: - // error: Error - // path: "/Users/jarred/Code/bun/test/bun.js/node_modules/esbuild-darwin-arm64/bin/esbuild" - // code: "13" - // syscall: "spawnSync" - // errno: -1 - // it("works for input exceeding the pipe capacity", () => { - // const hugeString = `console.log(${JSON.stringify("a".repeat(100000))});`; - // const result = transformSync(hugeString, { - // loader: "js", - // target: "node12", - // }); - // expect(result.code).toBe(hugeString + "\n"); - // }); + expect(exitCode).toBe(0); }); diff --git a/test/bun.js/esbuild-test.js b/test/bun.js/esbuild-test.js new file mode 100644 index 000000000..beb34b283 --- /dev/null +++ b/test/bun.js/esbuild-test.js @@ -0,0 +1,37 @@ +import { transform, transformSync } from "esbuild"; + +{ + const result = await transform("console.log('hello world')", { + loader: "js", + target: "node12", + }); + if (result.code !== 'console.log("hello world");\n') { + throw new Error("Test failed."); + } +} + +{ + const hugeString = `console.log(${JSON.stringify("a".repeat(1000000))});`; + + for (let i = 0; i < 2; i++) { + const result = await transform(hugeString, { + loader: "js", + target: "node12", + }); + if (result.code !== hugeString + "\n") { + throw new Error("Test failed."); + } + } +} + +{ + const result = transformSync("console.log('hello world')", { + loader: "js", + target: "node12", + }); + if (result.code !== 'console.log("hello world");\n') { + throw new Error("Test failed."); + } +} + +process.exit(0); |