From d969d2a280dd52a38905613ad624be855eebf1af Mon Sep 17 00:00:00 2001 From: Don Isaac Date: Mon, 14 Apr 2025 19:35:52 -0700 Subject: [PATCH] test(bun:test): add lots of test.failing timeout cases --- .../fixtures/failing-test-timeout.fixture.ts | 33 ++++++++++++++----- test/js/bun/test/test-failing.test.ts | 11 ++++--- 2 files changed, 31 insertions(+), 13 deletions(-) diff --git a/test/js/bun/test/fixtures/failing-test-timeout.fixture.ts b/test/js/bun/test/fixtures/failing-test-timeout.fixture.ts index 14b1001420..32e8e2bc88 100644 --- a/test/js/bun/test/fixtures/failing-test-timeout.fixture.ts +++ b/test/js/bun/test/fixtures/failing-test-timeout.fixture.ts @@ -1,20 +1,35 @@ -import { isCI, isWindows } from "harness"; +beforeEach(() => jest.setTimeout(5)); -jest.setTimeout(5); +describe("sync test functions with a done() cb", () => { + test.failing("fail when done is never called", done => { + // nada + }); -describe("test.failing", () => { - test.failing("Timeouts still count as failures", async () => { + test.failing("fail when done is called after timeout", done => { + setTimeout(() => done(), 1000); + }); +}); + +describe("async test functions", () => { + test.failing("fail when they never resolve", () => { + return new Promise((_resolve, _reject) => { + // lol + }); + }); + + test.failing("fail when they don't resolve in time", async () => { await Bun.sleep(1000); }); - // fixme: hangs on windows. Timer callback never fires - describe.skipIf(isWindows && isCI)("when using a done() callback", () => { - test.failing("fails when an async test never calls done()", async _done => { + describe("with a done() cb", () => { + test.failing("fail when done is never called", async done => { // nada }); - test.failing("fails when a sync test never calls done()", _done => { - // nada + test.failing("fail when done is called after timeout", done => { + return new Promise(resolve => { + setTimeout(() => resolve(done()), 1000); + }); }); }); }); diff --git a/test/js/bun/test/test-failing.test.ts b/test/js/bun/test/test-failing.test.ts index 5c06bb0d8f..8cdcc4a697 100644 --- a/test/js/bun/test/test-failing.test.ts +++ b/test/js/bun/test/test-failing.test.ts @@ -1,9 +1,12 @@ import path from "path"; -import { bunExe } from "harness"; +import { bunEnv, bunExe } from "harness"; import { $ } from "bun"; import { fail } from "assert"; const fixtureDir = path.join(import.meta.dir, "fixtures"); + +const bunTest = (fixture: string) => $.cwd(fixtureDir).env(bunEnv)`${bunExe()} test ${fixture}`.quiet(); + describe("test.failing", () => { it("is a function", () => { expect(test.failing).toBeFunction(); @@ -18,13 +21,13 @@ describe("test.failing", () => { }); it("passes if an error is thrown or a promise rejects ", async () => { - const result = await $.cwd(fixtureDir)`${bunExe()} test ./failing-test-fails.fixture.ts`.quiet(); + const result = await bunTest("./failing-test-fails.fixture.ts"); const stderr = result.stderr.toString(); expect(stderr).toContain(" 2 pass\n"); }); it("fails if no error is thrown or promise resolves", async () => { - const result = await $.cwd(fixtureDir).nothrow()`${bunExe()} test ./failing-test-passes.fixture.ts`.quiet(); + const result = await bunTest("./failing-test-passes.fixture.ts"); const stderr = result.stderr.toString(); if (result.exitCode === 0) { fail("Expected exit code to be non-zero\n\n" + stderr); @@ -34,7 +37,7 @@ describe("test.failing", () => { }); it("timeouts still count as failures", async () => { - const result = await $.cwd(fixtureDir).nothrow()`${bunExe()} test ./failing-test-timeout.fixture.ts`.quiet(); + const result = await bunTest("./failing-test-timeout.fixture.ts"); const stderr = result.stderr.toString(); if (result.exitCode === 0) { fail("Expected exit code to be non-zero\n\n" + stderr);