Files
bun.sh/test/cli/test/test-timeout-behavior.test.ts
Jarred Sumner 2e02d9de28 Use ReadableStream.prototype.* in tests instead of new Response(...).* (#20937)
Co-authored-by: Jarred-Sumner <709451+Jarred-Sumner@users.noreply.github.com>
Co-authored-by: Alistair Smith <hi@alistair.sh>
Co-authored-by: Claude Bot <claude-bot@bun.sh>
Co-authored-by: Claude <noreply@anthropic.com>
2025-07-14 00:47:53 -07:00

36 lines
1.4 KiB
TypeScript

import { expect, test } from "bun:test";
import { bunEnv, bunExe, isFlaky, isLinux } from "harness";
import path from "path";
if (isFlaky && isLinux) {
test.todo("processes get killed");
} else {
test.each([true, false])(`processes get killed (sync: %p)`, async sync => {
const { exited, stdout, stderr } = Bun.spawn({
cmd: [
bunExe(),
"test",
path.join(import.meta.dir, sync ? "process-kill-fixture-sync.ts" : "process-kill-fixture.ts"),
],
stdout: "pipe",
stderr: "pipe",
stdin: "inherit",
env: bunEnv,
});
const [out, err, exitCode] = await Promise.all([stdout.text(), stderr.text(), exited]);
// merge outputs so that this test still works if we change which things are printed to stdout
// and which to stderr
const combined = out + err;
// exit code should indicate failed tests, not abort or anything
expect(exitCode).toBe(1);
expect(combined).not.toContain("This should not be printed!");
expect(combined).toContain("killed 1 dangling process");
// we should not expose the termination exception
expect(combined).not.toContain("Unhandled error between tests");
expect(combined).not.toContain("JavaScript execution terminated");
// both tests should have run with the expected result
expect(combined).toContain("(fail) test timeout kills dangling processes");
expect(combined).toContain("(pass) slow test after test timeout");
});
}