diff options
Diffstat (limited to 'test/bun.js/child_process.test.ts')
-rw-r--r-- | test/bun.js/child_process.test.ts | 62 |
1 files changed, 53 insertions, 9 deletions
diff --git a/test/bun.js/child_process.test.ts b/test/bun.js/child_process.test.ts index 95a589401..83b0954fc 100644 --- a/test/bun.js/child_process.test.ts +++ b/test/bun.js/child_process.test.ts @@ -1,4 +1,5 @@ -import { describe, it, expect } from "bun:test"; +import { describe, it as it_, expect as expect_ } from "bun:test"; +import { gcTick } from "gc"; import { ChildProcess, spawn, @@ -11,6 +12,42 @@ import { } from "node:child_process"; import { tmpdir } from "node:os"; +const expect: typeof expect_ = (actual: unknown) => { + gcTick(); + const ret = expect_(actual); + gcTick(); + return ret; +}; + +const it: typeof it_ = (label, fn) => { + const hasDone = fn.length === 1; + if (fn.constructor.name === "AsyncFunction" && hasDone) { + return it_(label, async (done) => { + gcTick(); + await fn(done); + gcTick(); + }); + } else if (hasDone) { + return it_(label, (done) => { + gcTick(); + fn(done); + gcTick(); + }); + } else if (fn.constructor.name === "AsyncFunction") { + return it_(label, async () => { + gcTick(); + await fn(); + gcTick(); + }); + } else { + return it_(label, () => { + gcTick(); + fn(); + gcTick(); + }); + } +}; + const debug = process.env.DEBUG ? console.log : () => {}; const platformTmpDir = require("fs").realpathSync(tmpdir()); @@ -166,17 +203,24 @@ describe("spawn()", () => { }); it("should allow explicit setting of argv0", async () => { + var resolve; + const promise = new Promise((resolve1) => { + resolve = resolve1; + }); + process.env.NO_COLOR = "1"; const child = spawn("node", ["--help"], { argv0: "bun" }); - const result: string = await new Promise((resolve) => { - let msg; - child.stdout.on("data", (data) => { - msg += data.toString(); - }); + delete process.env.NO_COLOR; + let msg = ""; - child.stdout.on("close", () => { - resolve(msg); - }); + child.stdout.on("data", (data) => { + msg += data.toString(); }); + + child.stdout.on("close", () => { + resolve(msg); + }); + + const result = await promise; expect(/Open bun's Discord server/.test(result)).toBe(true); }); |