Skip to content

Commit

Permalink
add test to setImmediate
Browse files Browse the repository at this point in the history
  • Loading branch information
cirospaciari committed Jun 30, 2023
1 parent 4bce91a commit 40a7862
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions test/js/web/timers/setImmediate.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { it, expect } from "bun:test";
import { bunExe, bunEnv } from "harness";
import path from "path";

it("setImmediate", async () => {
var lastID = -1;
Expand Down Expand Up @@ -45,3 +47,28 @@ it("clearImmediate", async () => {
});
expect(called).toBe(false);
});

it("setImmediate should not keep the process alive forever", async () => {
let process = null;
const success = async () => {
process = Bun.spawn({
cmd: [bunExe(), "run", path.join(import.meta.dir, "process-setImmediate-fixture.js")],
stdout: "ignore",
env: {
...bunEnv,
NODE_ENV: undefined,
},
});
await process.exited;
process = null;
return true;
};

const fail = async () => {
await Bun.sleep(3000);
process?.kill();
return false;
};

expect(await Promise.race([success(), fail()])).toBe(true);
});

0 comments on commit 40a7862

Please sign in to comment.