Fix test using afterAll inside of a test

This commit is contained in:
Jarred Sumner
2025-04-14 17:25:12 -07:00
parent 74ab6d9fe3
commit 27a580a4d5

View File

@@ -1,5 +1,5 @@
import { spawn } from "bun";
import { afterAll, describe, expect, mock, test } from "bun:test";
import { describe, expect, mock, test } from "bun:test";
import { bunEnv, bunExe } from "harness";
describe("Streaming body via", () => {
@@ -28,24 +28,18 @@ describe("Streaming body via", () => {
});
test("async generator function throws an error but continues to send the headers", async () => {
let subprocess;
afterAll(() => {
subprocess?.kill();
});
const onMessage = mock(async url => {
const response = await fetch(url);
expect(response.headers.get("X-Hey")).toBe("123");
subprocess?.kill();
});
subprocess = spawn({
await using subprocess = spawn({
cwd: import.meta.dirname,
cmd: [bunExe(), "async-iterator-throws.fixture.js"],
env: bunEnv,
ipc: onMessage,
stdout: "ignore",
stdout: "inherit",
stderr: "pipe",
});