SupercovCompare
← All comparisons

JavaScript & TypeScript · Comparison

Which test covers this line? Per-test coverage in Vitest

Vitest reports coverage for the whole run, not per test. Supercov runs your Vitest command and shows which tests cover any line, and what each test covers.

Which test covers this line?

Vitest’s coverage report shows which lines ran during the whole run, not which test ran them. Supercov runs your Vitest command and records coverage for each test, so one run answers both questions: which tests cover this line, and what does this test cover.

npx supercov -- npx vitest run
npx supercov runs latest line src/price.js:7
src/price.js:7

Source
      7 | return subtotal - 10;

Covering tests
  takes 10 off orders over 100 [vitest:604050779_1] — unit/vitest

Recorded on October 1, 2026 with Supercov 2.0.1 and Vitest 5.0.0. The output is shortened; the full example is below.

The example

One function and three tests in two files:

// src/price.js
export function price(items, coupon) {
  const subtotal = items.reduce((sum, item) => sum + item.price * item.qty, 0);
  if (coupon === 'HALF') {
    return subtotal / 2;
  }
  if (subtotal > 100) {
    return subtotal - 10;
  }
  return subtotal;
}
// tests/cart.test.js
test('sums the cart', () => {
  expect(price([{ price: 20, qty: 2 }])).toBe(40);
});

test('takes 10 off orders over 100', () => {
  expect(price([{ price: 60, qty: 2 }])).toBe(110);
});

// tests/coupon.test.js
test('HALF halves the total', () => {
  expect(price([{ price: 30, qty: 2 }], 'HALF')).toBe(30);
});

What Vitest shows on its own

Vitest’s V8 and Istanbul coverage providers report one result for the run. To see what a single test covers, filter the run to it:

npx vitest run --coverage -t "takes 10 off orders over 100"
File      | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
 price.js |   71.42 |       50 |     100 |   66.66 | 4,9

That answers “what does this test cover?” for one test. To find every test that covers line 7, you would run each test this way and compare the reports.

Every test that covers a line

npx supercov runs latest line src/price.js:2
Covering tests
  HALF halves the total [vitest:1298185237_0] — unit/vitest
  sums the cart [vitest:604050779_0] — unit/vitest
  takes 10 off orders over 100 [vitest:604050779_1] — unit/vitest

All three tests compute the subtotal. Line 4 is covered by HALF halves the total alone, so it is the test to read before you change the coupon rule.

Everything one test covers

npx supercov runs latest test "takes 10 off orders over 100"
takes 10 off orders over 100
outcome passed; retry 0=passed
5 lines, 6 hits, 2 decisions, 1 phases
line: src/price.js:1
line: src/price.js:2
line: src/price.js:3
line: src/price.js:6
line: src/price.js:7
assertion: expect.toBe at tests/cart.test.js:9:3

It also names the assertion the test made. Add --json to any query for structured output a coding agent can read.

Limits

Supercov attributes coverage to each Vitest test exactly, with setup code kept separate and Browser Mode included; see runner support. It runs your tests in an isolated copy and does not change them. It does not replace Vitest’s coverage report: use that for the run’s totals, and Supercov when you need to know which test is responsible for a line. For V8 versus Istanbul, see Vitest coverage: V8 vs Istanbul.