mirror of
https://github.com/oven-sh/bun
synced 2026-02-16 13:51:47 +00:00
test(bun:test): add lots of test.failing timeout cases
This commit is contained in:
@@ -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);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user