# 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.

{/* Generated by src/codegen/lint-rule-docs.ts. Do not edit this section. */}

## Configure

Off by default. To turn it on:

```toml bunfig.toml
[lint.rules]
"bun:test/require-test-timeout" = "error" # or "warn"
```

{/* End of the generated section. */}

## Examples

Reported:

{/* bad */}
```ts
import { expect, test } from "bun:test";

test("loads the report", async () => {
  expect(await loadReport()).toBeDefined();
});
```

Not reported:

{/* good */}
```ts
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 });
```

{/* good */}
```ts
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`:

{/* bad {"count": 2} */}
```ts
import { test } from "bun:test";

const SLOW = 30_000;

test("exports the report", async () => {
  await exportReport();
}, SLOW);

test("prints the report", async () => {
  await printReport();
}, { retry: 2 });
```

## 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.
