Exclusive Test Committed
ID |
javascript.exclusive_test |
Severity |
high |
Remediation Complexity |
trivial |
Remediation Risk |
low |
Remediation Effort |
low |
Resource |
Reliability |
Language |
JavaScript |
Tags |
reliability, testing |
Description
Reports a test or suite marked to run to the exclusion of its siblings: it.only(…), describe.only(…), test.only(…), and the prefixed spellings fit(…) and fdescribe(…).
Every exclusive declaration is reported, whichever spelling and at whatever nesting: the defect is that the marker reached version control at all.
Rationale
// Bad
describe('checkout', () => {
it.only('applies the discount', () => {
expect(discount(order)).toBe(1);
});
it('charges the card', () => { // never runs
expect(charge).toHaveBeenCalled();
});
});
-
The marker is a debugging aid — it narrows a run to the test being worked on — and committed it switches off every other test in the file, and in several runners every other test in the whole run.
-
The suite still reports green, because the tests that no longer run are counted neither as failures nor as skips.
-
No gate fires: the exit status is success, and the test count drops in a number nobody reads.
-
The next change to the code those tests covered lands unchecked, and the gap lasts until someone notices the run got suspiciously fast.
Remediation
Delete the marker before committing. To keep a narrow run locally, pass the filter on the command line instead, where it cannot be committed.
// Good
describe('checkout', () => {
it('applies the discount', () => {
expect(discount(order)).toBe(1);
});
it('charges the card', () => {
expect(charge).toHaveBeenCalled();
});
});
# Good — narrow the run without touching the source
npx vitest run --testNamePattern 'applies the discount'