Which test covers this line? Vitest, Jest and pytest
Each way to find the tests that ran a line in Vitest, Jest and pytest, measured on the same project.

In pytest, run pytest --cov --cov-context=test, then coverage html --show-contexts: each line of the report lists the tests that ran it. Vitest
and Jest do not record this. Their coverage adds every test into one count per
line, so the only built-in way to tell is one coverage run per test.

Supercov, which we make, records coverage per test in one normal run of
Vitest, Jest, pytest and the other supported runners, and supercov runs latest line <file:line> lists the tests that ran a line. See
below.
At a glance
| Runner | Built in? | How |
|---|---|---|
| pytest | Yes | pytest --cov --cov-context=test, then coverage html --show-contexts or coverage json --show-contexts |
| Vitest | No | One vitest run --coverage -t "<test name>" per test |
| Jest | No | One jest --coverage -t "<test name>" per test |
| Any of them, with Supercov | npx supercov -- <test command> once, then npx supercov runs latest line <file:line> |
We measured each on the same small project: a discount function, three tests
for it, and one checkout test that calls it. Vitest 5.1.0 with the V8
provider, Jest 30.5.2, and coverage.py 7.17.2 with pytest-cov 7.1.0 and pytest
9.2.0. Every method that names tests gave the same answer: line 6, return cents - 1000;, runs in one test, and line 8, return cents;, in two.

pytest: coverage contexts
pytest --cov --cov-context=test
coverage html --show-contexts
coverage json --show-contexts -o contexts.json
--cov-context=test is pytest-cov’s option. It labels everything each test
runs with the test’s id. With coverage.py alone, set dynamic_context = test_function under [run]. In the HTML report, click a line to see its
tests. The JSON report lists them under each file’s contexts:
"5": ["tests/test_discount.py::test_tenoff_takes_ten_off_orders_of_ten_or_more|run"],
"6": ["tests/test_checkout.py::test_checkout_adds_up_the_items|run",
"tests/test_discount.py::test_tenoff_does_nothing_under_ten|run"]
|run means the line ran in the test body. Setup and teardown get their own
suffixes.
Vitest and Jest: one coverage run per test
coverage-final.json from either runner holds one hit count per statement for
the whole run. Line 8 reported 2 hits, with nothing to say which tests made
them. To find out, run coverage once per test name and check the line each
time:
vitest run --coverage -t "^TENOFF does nothing under ten$"
jest --coverage -t "^TENOFF does nothing under ten$"
That took four runs for four tests: 1.7 s in Vitest and 1.5 s in Jest, against 0.23 s for one Vitest run of all four. The number of runs grows with the number of tests, so on a real suite this is a script you leave running, not a question you ask.
vitest related src/discount.js and jest --findRelatedTests src/discount.js
answer a different question. They follow imports, so both picked all four
tests, including two that never reach line 8.
Supercov: one run, any runner
npx supercov -- npx vitest run
npx supercov runs latest line src/discount.js:8src/discount.js:8
Source
8 | return cents;
Status
COVERED
Evidence: execution only
Covering tests
TENOFF does nothing under ten [vitest:-1607981173_2] — unit/vitest
checkout adds up the items [vitest:2006354534_0] — unit/vitest
The same two commands, with npx jest or pytest in the first, gave the same
tests for Jest and pytest. The whole Vitest run under Supercov took 0.89 s.
Pass several lines at once, or --from-file with one per line, and add
--json for a script or a coding agent. Each line also lists its branches and
conditions with the tests for each. See the CLI
reference and runner support for every
runner and language, and Vitest per-test
coverage for the same question from the
test’s side.
More coverage guides
- Ruby && and || coverage: what SimpleCov's branch coverage misses
- Playwright code coverage of your server: Express, measured
- JaCoCo coverage per test: which test covers this line in Java
- Code coverage for AI coding agents: what the agent reads
- Jest coverageThreshold: global, per-folder and per-file
- JaCoCo aggregate report for multi-module Maven and Gradle builds
- pytest ignore directory: --ignore, norecursedirs and collect_ignore
- Merge coverage reports from shards: Vitest, Jest and coverage.py
- Statement vs branch coverage, with decision, line and path coverage
- JaCoCo report not generated: the causes in Maven and Gradle
- Kover exclude: classes, packages and generated code
- sonar.coverage.exclusions: why SonarQube ignores your JaCoCo excludes
- istanbul ignore next vs c8 ignore next: every hint, measured
- Go test coverage exclude: files, packages and mocks
- Jest coverage exclude: files, folders and lines
- pytest coverage exclude: omit files, folders and lines
- Vitest coverage exclude: files, folders and lines
- JaCoCo exclude in Maven and Gradle: packages, classes and generated code