Skip to content

test_runner: support coverage with isolation:'none' via run() API#63079

Open
Han5991 wants to merge 4 commits intonodejs:mainfrom
Han5991:fix/test-runner-coverage-isolation-none
Open

test_runner: support coverage with isolation:'none' via run() API#63079
Han5991 wants to merge 4 commits intonodejs:mainfrom
Han5991:fix/test-runner-coverage-isolation-none

Conversation

@Han5991
Copy link
Copy Markdown
Contributor

@Han5991 Han5991 commented May 2, 2026

Summary

Fixes #60023.

run({ coverage: true, isolation: 'none' }) returned an empty file list because V8 precise coverage is only enabled at bootstrap when NODE_V8_COVERAGE or --experimental-test-coverage is set, neither of which the API path requires. The reporter also surfaced a related inconsistency: with isolation: 'process', test files (e.g. foo.test.mjs) appeared in the coverage report via the API path, while the CLI path excluded them by default.

This PR fixes both halves:

  • Coverage now collects on the parent isolate when run() is the entry point. A new profiler.startCoverage() internal binding enables V8 precise coverage at run() time. It is idempotent against the existing bootstrap path and a no-op when the inspector is unavailable (the parent of --test --test-isolation=process, where workers handle coverage themselves).
  • Default test-file exclusion is applied consistently across CLI and API paths. When coverage: true is passed to run() without coverageExcludeGlobs, [kDefaultPattern] is applied — matching parseCommandLine's behavior. Two existing run() coverage tests that depended on the absent default are updated to opt out via coverageExcludeGlobs: '!test/**'.

Test plan

  • New regression test test/parallel/test-runner-coverage-isolation-none-api.mjs passes — covers isolation=none reports src files, default exclusion drops *.test.mjs in both isolation modes, and idempotency under --experimental-test-coverage.
  • All 70 parallel/test-runner-* tests pass.
  • Full tools/test.py suite passes; unrelated FFI fixture-build setup and watch-mode flakiness verified independent of this change.
  • Issue's original reproduction yields identical, correct coverage in both isolation modes (src file present, test file excluded by default).

Refs: #60023

Han5991 added 4 commits May 2, 2026 15:45
Add a `startCoverage` method on the `profiler` internal binding so
that V8 precise coverage can be enabled after bootstrap. The method
is idempotent against the existing bootstrap path (which creates a
V8CoverageConnection when NODE_V8_COVERAGE or
--experimental-test-coverage is set) and a no-op when the inspector
is unavailable, e.g. in the parent process of
`--test --test-isolation=process` where workers handle coverage and
Environment::should_create_inspector() returns false.

Refs: nodejs#60023
Signed-off-by: sangwook <rewq5991@gmail.com>
run({ coverage: true, isolation: 'none' }) previously returned an
empty file list because V8 precise coverage is only started at
bootstrap when NODE_V8_COVERAGE or --experimental-test-coverage is
set, neither of which the API path requires. Call the new
profiler.startCoverage() binding from setupCoverage() so the parent
isolate is instrumented when the run() API is the entry point.

Fixes: nodejs#60023
Signed-off-by: sangwook <rewq5991@gmail.com>
The CLI path defaults coverageExcludeGlobs to [kDefaultPattern] when
--experimental-test-coverage is set, dropping test files from the
coverage report. The run() API skipped this default, so callers got
test files mixed into their coverage data. Apply the same default
when run() is invoked with coverage: true and no explicit
coverageExcludeGlobs, so both entry points behave consistently.

Update the existing run() coverage tests that depended on the absent
default to opt out via coverageExcludeGlobs: '!test/**'.

Refs: nodejs#60023
Signed-off-by: sangwook <rewq5991@gmail.com>
Verify that:
  - run({ coverage: true, isolation: 'none' }) reports src files,
  - default test-file exclusion drops *.test.mjs in both isolation
    modes,
  - the path is idempotent when --experimental-test-coverage is set
    on the same process.

Refs: nodejs#60023
Signed-off-by: sangwook <rewq5991@gmail.com>
@nodejs-github-bot
Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/inspector
  • @nodejs/test_runner

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run. labels May 2, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented May 2, 2026

Codecov Report

❌ Patch coverage is 82.35294% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.67%. Comparing base (5e61a07) to head (711ac87).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
src/inspector_profiler.cc 76.92% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #63079      +/-   ##
==========================================
+ Coverage   89.65%   89.67%   +0.02%     
==========================================
  Files         712      712              
  Lines      220498   220515      +17     
  Branches    42278    42286       +8     
==========================================
+ Hits       197683   197745      +62     
+ Misses      14663    14613      -50     
- Partials     8152     8157       +5     
Files with missing lines Coverage Δ
lib/internal/test_runner/coverage.js 67.42% <100.00%> (+3.24%) ⬆️
lib/internal/test_runner/runner.js 93.77% <100.00%> (+0.10%) ⬆️
src/inspector_profiler.cc 82.19% <76.92%> (-0.18%) ⬇️

... and 32 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Test runner with isolation=none does not work with coverage

3 participants