bun:test/require-test-timeout
Require every test to set a timeout
A test without its own timeout gets the default, which is 5 seconds unless you pass --timeout to bun test. That's a long wait when a unit test hangs, and it's too short for a test that starts a server, which then fails now and then on a slow machine.
Set the timeout as a number after the test function, as { timeout } in the options, or for all the tests below with setDefaultTimeout() or jest.setTimeout().
Tests marked .skip or .todo aren't checked.
Configure#
Off by default. To turn it on:
[lint.rules]
"bun:test/require-test-timeout" = "error" # or "warn"Examples#
import { expect, test } from "bun:test";
test("loads the report", async () => {Test is missing a timeout.
expect(await loadReport()).toBeDefined();
});import { expect, test } from "bun:test";
test("loads the report", async () => {
expect(await loadReport()).toBeDefined();
}, 10_000);
test("exports the report", async () => {
expect(await exportReport()).toBeDefined();
}, { timeout: 30_000 });import { expect, setDefaultTimeout, test } from "bun:test";
setDefaultTimeout(10_000);
test("loads the report", async () => {
expect(await loadReport()).toBeDefined();
});The timeout must be written as a non-negative number. A variable is reported, and so are options without timeout:
import { test } from "bun:test";
const SLOW = 30_000;
test("exports the report", async () => {
await exportReport();
}, SLOWTimeout must be a number.);
test("prints the report", async () => {
await printReport();
}, { retry: 2 }Test options object is missing a timeout property.);When not to use it#
If the default timeout, or the one you pass to bun test --timeout, suits all your tests, a number on each test adds nothing.