diff options
author | 2023-02-27 22:53:28 -0300 | |
---|---|---|
committer | 2023-02-27 22:53:28 -0300 | |
commit | 38d6cd6d15f2745d02fc757cc299691d82c7b4f5 (patch) | |
tree | 4d802e35540420a98d4063b7136e91f1846f92a6 /test/bun.js/spawn.test.ts | |
parent | 14f02cb05e6ce538e6551e17be6397e0e7e34f21 (diff) | |
download | bun-38d6cd6d15f2745d02fc757cc299691d82c7b4f5.tar.gz bun-38d6cd6d15f2745d02fc757cc299691d82c7b4f5.tar.zst bun-38d6cd6d15f2745d02fc757cc299691d82c7b4f5.zip |
add tests, exited rejects when aborted, exitCode is null when aborted
Diffstat (limited to 'test/bun.js/spawn.test.ts')
-rw-r--r-- | test/bun.js/spawn.test.ts | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/test/bun.js/spawn.test.ts b/test/bun.js/spawn.test.ts index def0330ee..ea062de59 100644 --- a/test/bun.js/spawn.test.ts +++ b/test/bun.js/spawn.test.ts @@ -46,6 +46,18 @@ for (let [gcTick, label] of [ expect(exitCode2).toBe(1); gcTick(); }); + + it("AbortController.abort() works", async () => { + const controller = new AbortController(); + controller.abort(); //is sync so will only abort if already start aborted + const process = Bun.spawnSync({ + cmd: ["bash", "-c", "sleep 2"], + stdout: "pipe", + signal: controller.signal + }); + gcTick(); + expect(process.exitCode).toBe(null); + }); }); describe("spawn", () => { @@ -376,6 +388,28 @@ for (let [gcTick, label] of [ }); } }); + + it("AbortController.abort() works", async () => { + const controller = new AbortController(); + const process = Bun.spawn({ + cmd: ["bash", "-c", "sleep 2"], + stdout: "pipe", + signal: controller.signal + }); + gcTick(); + setTimeout(()=> { + controller.abort(); + }, 15) + + try { + await process.exited; + } catch(err) { + expect(err instanceof DOMException).toBe(true); + expect(err?.name).toBe("AbortError"); + expect(err?.message).toBe("The operation was aborted."); + } + + }); }); }); -} +}
\ No newline at end of file |