focused-test
.only on a test or a suite (test.only, it.only, describe.only, Jest's fit and fdescribe, node:test's { only: true }). Reported in test files. On by default, as an error.
Why: with .only, Vitest, Jest and Bun run the focused tests and skip the rest of the file (node:test does under --test-only). The skipped tests stop being checked while the run still passes, so a regression in them goes unseen. It is meant for a moment at the keyboard, and gets committed by accident. Guide: Testing.
✕ Rejectedfocused-test
ts
import assert from "node:assert/strict";
import { test } from "node:test";
function total(prices: readonly number[]): number {
return prices.reduce((sum, price) => sum + price, 0);
}
test("total adds the prices", { only: true }, () => {
assert.equal(total([3, 4]), 7);
});
test("an empty list totals 0", () => {
assert.equal(total([]), 0);
});✅ Accepted: every test runs; pick one from the command line (node --test --test-name-pattern="adds", vitest -t "adds")
✓ Accepted0 diagnostics
ts
import assert from "node:assert/strict";
import { test } from "node:test";
function total(prices: readonly number[]): number {
return prices.reduce((sum, price) => sum + price, 0);
}
test("total adds the prices", () => {
assert.equal(total([3, 4]), 7);
});
test("an empty list totals 0", () => {
assert.equal(total([]), 0);
});What the rule can't see
A runner's focus set somewhere else: t.runOnly(true), a config file's include or a CLI filter, and a test function reached through a name the checker doesn't know as a runner's (see "testRunners" in the adoption guide).