From 3572b32c92f3b016012c541f6b0afdfbd59082d4 Mon Sep 17 00:00:00 2001 From: jan-kubica Date: Wed, 18 Nov 2026 21:38:31 +0100 Subject: [PATCH] docs(test-kit): a test's own timeout replaces the command's budget --- .changeset/test-kit-timeout-budgets.md | 5 +++++ packages/test-kit/README.md | 20 ++++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 .changeset/test-kit-timeout-budgets.md diff --git a/.changeset/test-kit-timeout-budgets.md b/.changeset/test-kit-timeout-budgets.md new file mode 100644 index 00000000..92e71364 --- /dev/null +++ b/.changeset/test-kit-timeout-budgets.md @@ -0,0 +1,5 @@ +--- +"@stll/test-kit": patch +--- + +The README explains how a test's own timeout interacts with `bun test --timeout`: the test's number replaces the command's in either direction, so a long test sized from a workstation run can fail on slower CI runners inside a budget the command allows. It recommends one budget sized from CI durations and per-phase hang guards with `settledWithin`. diff --git a/packages/test-kit/README.md b/packages/test-kit/README.md index a28b791d..ad42e084 100644 --- a/packages/test-kit/README.md +++ b/packages/test-kit/README.md @@ -17,6 +17,7 @@ bun add -d @stll/test-kit | Wait for something that happens | `deferred()`, `waitForEvent()`, `waitForAbort()` | sleeping and hoping | | Wait for state without an event (a row, a file) | `waitFor(probe, { description })` | a hand-written poll loop | | A deadline that only catches hangs | `settledWithin(promise, { description })` | `Promise.race` with a short timer as an assertion | +| A long test's own budget | the CI command's `bun test --timeout`; per phase, `settledWithin` with `timeoutMs` | a per-test timeout sized from one workstation run | | A private directory per test | `useTestTmpDir()`, `withTestTmpDir()`, `await using dir = await createTestTmpDir()` | `mkdtemp(tmpdir())` and manual cleanup | | No outbound network | preload `@stll/test-kit/forbid-network`, or `installNetworkGuard()` | relying on the CI network | | No inherited proxy settings during a network guard | `installNetworkGuard()` hides and later restores proxy environment variables | treating sandbox proxy settings as test network access | @@ -42,6 +43,25 @@ a suite raises that timeout) fails with "waiting for ", so a stuck says what it was waiting for. The guard is never a statement about speed: do not shorten it to assert that something is fast. Assert work counts instead. +## Test timeouts + +A test's own timeout (`test(name, fn, ms)`, `{ timeout: ms }`, a hook's +timeout or `setDefaultTimeout`) replaces `bun test --timeout` for that test, +in either direction. A long test that declares less than the command running +it is held to the smaller number, and nothing reports the conflict. + +A test timeout is a hang guard like the waits above, not a statement about +speed. Hosted runners take the same work two to three times longer than a +quiet run, so: + +- Size a long test's budget from its CI durations with headroom (about 2.5x + the slowest passing run), never from one workstation measurement. +- Keep one number. When the CI command sets `--timeout`, a test either + declares nothing or declares at least that budget. +- Split a long test into phases and give each a hang guard with + `settledWithin(phase, { description, timeoutMs })`, so a stuck run says + which phase hung instead of hitting the test's total. + ## Rejections `rejectionOf(promise)` awaits a promise and returns the reason it rejected