1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
import { describe, test, expect } from "bun:test";
import { bunExe, bunEnv } from "harness";
import { writeFileSync } from "fs";
import { join } from "path";
import { tmpdir } from "os";
describe("AbortSignal", () => {
test("spawn test", async () => {
const fileName = `/abort-${Date.now()}.test.ts`;
const testFileContents = await Bun.file(join(import.meta.dir, "abort.ts")).arrayBuffer();
writeFileSync(join(tmpdir(), fileName), testFileContents, "utf8");
const { stderr } = Bun.spawnSync({
cmd: [bunExe(), "test", fileName],
env: bunEnv,
cwd: tmpdir(),
});
expect(stderr?.toString()).not.toContain("✗");
});
test("AbortSignal.timeout(n) should not freeze the process", async () => {
const fileName = join(import.meta.dir, "abort.signal.ts");
const server = Bun.spawn({
cmd: [bunExe(), fileName],
env: bunEnv,
cwd: tmpdir(),
});
const exitCode = await Promise.race([
server.exited,
(async () => {
await Bun.sleep(5000);
server.kill();
return 2;
})(),
]);
expect(exitCode).toBe(0);
});
});
|