avivkeller
b7d29fee74
test_runner: add support for --test-coverage-include-all
...
Signed-off-by: avivkeller <me@aviv.sh >
PR-URL: https://github.com/nodejs/node/pull/64830
Fixes: https://github.com/nodejs/node/issues/58887
Reviewed-By: Moshe Atlow <moshe@atlow.co.il >
Reviewed-By: Chemi Atlow <chemi@atlow.co.il >
2026-07-31 15:58:10 -07:00
Trivikram Kamat
266e1658b0
test_runner: improve coverage failure diagnostics
...
Include the coverage filename when parsing V8 coverage data fails,
and make test-runner coverage assertions report spawned child process
output when the expected coverage report is missing.
Signed-off-by: Kamat, Trivikram <16024985+trivikr@users.noreply.github.com >
Assisted-by: openai:gpt-5.5
PR-URL: https://github.com/nodejs/node/pull/64050
Refs: https://github.com/nodejs/reliability/issues?q=%22parallel%2Ftest-runner-coverage%22
Reviewed-By: Moshe Atlow <moshe@atlow.co.il >
Reviewed-By: Chemi Atlow <chemi@atlow.co.il >
2026-06-23 22:06:23 +00:00
sangwook
75b16f1f4e
test_runner: avoid recompiling coverage globs for every file
...
`shouldSkipFileCoverage()` called `matchGlobPattern()` for each covered
file, and `matchGlobPattern()` builds a fresh Minimatch (a full glob
parse and regexp compile) on every call. The coverage exclude/include
globs never change during a run, so the same patterns were recompiled
once per file, which dominated the coverage report time.
Compile `coverageExcludeGlobs`/`coverageIncludeGlobs` to matchers once
per `TestCoverage` instance and reuse them for every file. Expose
`createMatcher()` from `internal/fs/glob` for this.
On a synthetic 200-test-file project this drops shouldSkipFileCoverage
from ~117ms to ~11ms (cpu-prof, isolation=none); the saving scales with
files * globs.
Refs: https://github.com/nodejs/node/issues/55103
Signed-off-by: sangwook <rewq5991@gmail.com >
PR-URL: https://github.com/nodejs/node/pull/63675
Reviewed-By: Matteo Collina <matteo.collina@gmail.com >
Reviewed-By: Moshe Atlow <moshe@atlow.co.il >
Reviewed-By: Chemi Atlow <chemi@atlow.co.il >
2026-06-02 14:44:23 +02:00
sangwook
29aad20aa6
test_runner: cache shouldSkipFileCoverage result per URL
...
`shouldSkipFileCoverage(url)` is invoked twice for every covered
script (once during source-map mapping and once during merge), and
the same script URL is typically reported by every worker. The
result depends only on `options.cwd`, `coverageExcludeGlobs`, and
`coverageIncludeGlobs`, all of which are fixed for the lifetime of
a TestCoverage instance, so the URL -> boolean mapping is
deterministic and safe to cache.
Add a private `#skipCache` SafeMap and split the method into a thin
caching wrapper plus a private `#computeShouldSkipFileCoverage`
that holds the original logic. Callers are unchanged.
This eliminates redundant glob and URL parsing work proportional to
the number of workers x scripts in the coverage report.
Refs: https://github.com/nodejs/node/issues/55103
Signed-off-by: sangwook <rewq5991@gmail.com >
PR-URL: https://github.com/nodejs/node/pull/63675
Reviewed-By: Matteo Collina <matteo.collina@gmail.com >
Reviewed-By: Moshe Atlow <moshe@atlow.co.il >
Reviewed-By: Chemi Atlow <chemi@atlow.co.il >
2026-06-02 14:44:21 +02:00
Matteo Collina
8d0a3b84ff
test_runner: ignore erased TS lines in coverage
...
Fixes: https://github.com/nodejs/node/issues/54753
Signed-off-by: Matteo Collina <matteo.collina@gmail.com >
PR-URL: https://github.com/nodejs/node/pull/63510
Reviewed-By: Moshe Atlow <moshe@atlow.co.il >
Reviewed-By: Chemi Atlow <chemi@atlow.co.il >
Reviewed-By: Pietro Marchini <pietro.marchini94@gmail.com >
2026-05-28 07:47:24 +00:00
sangwook
c9dbb86683
inspector: expose precise coverage start to JS runtime
...
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: https://github.com/nodejs/node/issues/60023
Signed-off-by: sangwook <rewq5991@gmail.com >
PR-URL: https://github.com/nodejs/node/pull/63079
Reviewed-By: Chemi Atlow <chemi@atlow.co.il >
Reviewed-By: Pietro Marchini <pietro.marchini94@gmail.com >
Reviewed-By: Aviv Keller <me@aviv.sh >
2026-05-23 17:02:02 +00:00
Joyee Cheung
f46d501b7f
test_runner: use module.registerHooks in module mocks
...
Migrate away from module.register(). This no longer needs to
deal with the worker synchronization.
PR-URL: https://github.com/nodejs/node/pull/60326
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com >
Reviewed-By: Chemi Atlow <chemi@atlow.co.il >
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com >
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com >
2025-10-22 11:05:39 +00:00
Shima Ryuhei
220f5c644e
test: exclude mock from coverage
...
Fixes: https://github.com/nodejs/node/issues/59112
PR-URL: https://github.com/nodejs/node/pull/59348
Reviewed-By: Matteo Collina <matteo.collina@gmail.com >
Reviewed-By: Pietro Marchini <pietro.marchini94@gmail.com >
2025-08-11 05:49:53 +00:00
Marco Ippolito
8ccfcb5adc
lib: fix sourcemaps with ts module mocking
...
PR-URL: https://github.com/nodejs/node/pull/58193
Fixes: https://github.com/nodejs/node/issues/58119
Reviewed-By: Pietro Marchini <pietro.marchini94@gmail.com >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: Jacob Smith <jacob@frende.me >
Reviewed-By: Chemi Atlow <chemi@atlow.co.il >
2025-05-08 15:14:22 +00:00
Pietro Marchini
5ad2ca920c
test_runner: exclude test files from coverage by default
...
PR-URL: https://github.com/nodejs/node/pull/56060
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: Matteo Collina <matteo.collina@gmail.com >
Reviewed-By: Moshe Atlow <moshe@atlow.co.il >
2024-12-17 11:10:17 +00:00
Aviv Keller
9b6cea6ebe
test_runner: pass options directly to TestCoverage
...
PR-URL: https://github.com/nodejs/node/pull/55578
Reviewed-By: Moshe Atlow <moshe@atlow.co.il >
Reviewed-By: Raz Luvaton <rluvaton@gmail.com >
2024-11-01 14:20:19 +00:00
Aviv Keller
10addb0a20
test_runner: require --enable-source-maps for sourcemap coverage
...
PR-URL: https://github.com/nodejs/node/pull/55359
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: Matteo Collina <matteo.collina@gmail.com >
Reviewed-By: Moshe Atlow <moshe@atlow.co.il >
2024-10-14 13:19:17 +00:00
Aviv Keller
ccd4faf4bf
Revert "test_runner: ignore unmapped lines for coverage"
...
This reverts commit 3a42085ee4 .
PR-URL: https://github.com/nodejs/node/pull/55339
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: Chemi Atlow <chemi@atlow.co.il >
2024-10-11 11:36:03 +00:00
Aviv Keller
71785889c8
lib: prefer logical assignment
...
PR-URL: https://github.com/nodejs/node/pull/55044
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Chemi Atlow <chemi@atlow.co.il >
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com >
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com >
Reviewed-By: LiviaMedeiros <livia@cirno.name >
2024-10-09 06:42:16 +00:00
Edigleysson Silva (Edy)
3a42085ee4
test_runner: ignore unmapped lines for coverage
...
PR-URL: https://github.com/nodejs/node/pull/55228
Refs: https://github.com/nodejs/node/issues/55106
Reviewed-By: Moshe Atlow <moshe@atlow.co.il >
Reviewed-By: Chemi Atlow <chemi@atlow.co.il >
2024-10-08 19:55:54 +00:00
Aviv Keller
9a9409ff1f
test_runner: throw on invalid source map
...
PR-URL: https://github.com/nodejs/node/pull/55055
Reviewed-By: Matteo Collina <matteo.collina@gmail.com >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
2024-10-06 20:27:32 +00:00
Pietro Marchini
1c7795e52e
test_runner: add cwd option to run
...
PR-URL: https://github.com/nodejs/node/pull/54705
Reviewed-By: Matteo Collina <matteo.collina@gmail.com >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
2024-10-03 15:45:49 +00:00
4f881790e9
test_runner: report error on missing sourcemap source
...
Co-Authored-By: Jayden Seric <me@jaydenseric.com >
Co-Authored-By: Colin Ihrig <cjihrig@gmail.com >
PR-URL: https://github.com/nodejs/node/pull/55037
Reviewed-By: Chemi Atlow <chemi@atlow.co.il >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
2024-09-23 00:32:06 +00:00
Aviv Keller
99bbf80608
test_runner: report coverage thresholds in test:coverage
...
PR-URL: https://github.com/nodejs/node/pull/54813
Reviewed-By: Matteo Collina <matteo.collina@gmail.com >
Reviewed-By: Moshe Atlow <moshe@atlow.co.il >
Reviewed-By: Chemi Atlow <chemi@atlow.co.il >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
2024-09-13 13:31:37 +00:00
Colin Ihrig
123bb4cb22
test_runner: improve code coverage cleanup
...
The test runner's code coverage leaves old coverage data in the
temp directory. This commit updates the cleanup logic to:
- Stop code collection. Otherwise V8 would write collection data
again when the process exits.
- Remove the temp directory containing the coverage data.
- Attempt to clean up the coverage data even if parsing the
data resulted in an error.
With this change, I no longer see any coverage data left behind
in the system temp directory.
Refs: https://github.com/nodejs/build/issues/3864
Refs: https://github.com/nodejs/build/issues/3887
PR-URL: https://github.com/nodejs/node/pull/54856
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com >
Reviewed-By: Jake Yuesong Li <jake.yuesong@gmail.com >
Reviewed-By: Luigi Pinca <luigipinca@gmail.com >
Reviewed-By: Moshe Atlow <moshe@atlow.co.il >
Reviewed-By: James M Snell <jasnell@gmail.com >
2024-09-11 02:50:28 +00:00
Colin Ihrig and Simon Chan
821ffab0f7
test_runner: account for newline in source maps
...
This commit updates the source mapping logic in the test runner
to account for newline characters that are not included in line
length calculations.
Co-authored-by: Simon Chan <1330321+yume-chan@users.noreply.github.com >
Fixes: https://github.com/nodejs/node/issues/54240
PR-URL: https://github.com/nodejs/node/pull/54444
Reviewed-By: Jake Yuesong Li <jake.yuesong@gmail.com >
Reviewed-By: Matteo Collina <matteo.collina@gmail.com >
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com >
Reviewed-By: Moshe Atlow <moshe@atlow.co.il >
2024-08-21 02:38:55 +00:00
Colin Ihrig
ea837a0db9
test_runner: refactor coverage to pass in config options
...
This commit updates the test runner's code coverage so that
coverage options are explicitly passed in instead of pulled
from command line options.
PR-URL: https://github.com/nodejs/node/pull/53931
Refs: https://github.com/nodejs/node/issues/53924
Refs: https://github.com/nodejs/node/issues/53867
Refs: https://github.com/nodejs/node/pull/53866
Reviewed-By: Matteo Collina <matteo.collina@gmail.com >
Reviewed-By: Moshe Atlow <moshe@atlow.co.il >
Reviewed-By: Chemi Atlow <chemi@atlow.co.il >
Reviewed-By: James M Snell <jasnell@gmail.com >
2024-07-22 04:26:43 +00:00
Colin Ihrig
f09063752b
test_runner: consolidate option parsing
...
This commit consolidates all option parsing for the test runner
in the parseCommandLine() internal helper function. The exception
is a couple of temporary flags used for feature gating which
will eventually become no-ops. This consolidation is prep work
for supporting running test files in the test runner process.
PR-URL: https://github.com/nodejs/node/pull/53849
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Moshe Atlow <moshe@atlow.co.il >
Reviewed-By: Chemi Atlow <chemi@atlow.co.il >
2024-07-16 21:05:46 +00:00
Aviv Keller
4174b73153
test: support glob matching coverage files
...
PR-URL: https://github.com/nodejs/node/pull/53553
Reviewed-By: Moshe Atlow <moshe@atlow.co.il >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com >
2024-07-14 22:37:45 +00:00
Moshe Atlow
419172fba8
test_runner: calculate executed lines using source map
...
PR-URL: https://github.com/nodejs/node/pull/53315
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: Chemi Atlow <chemi@atlow.co.il >
2024-06-05 22:25:06 +00:00
Moshe Atlow
d4442a93e2
test_runner: avoid error when coverage line not found
...
PR-URL: https://github.com/nodejs/node/pull/53000
Fixes: https://github.com/nodejs/node/issues/52775
Reviewed-By: Chemi Atlow <chemi@atlow.co.il >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com >
Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io >
2024-05-17 08:46:52 +00:00
Antoine du Hamel
a596af0819
tools: add lint rule to keep primordials in ASCII order
...
PR-URL: https://github.com/nodejs/node/pull/52592
Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io >
Reviewed-By: Jacob Smith <jacob@frende.me >
Reviewed-By: Moshe Atlow <moshe@atlow.co.il >
2024-04-21 16:53:08 +00:00
Moshe Atlow
814fa1ae74
test_runner: use source maps when reporting coverage
...
PR-URL: https://github.com/nodejs/node/pull/52060
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com >
Reviewed-By: Chemi Atlow <chemi@atlow.co.il >
2024-03-15 06:33:42 +00:00
Deokjin Kim
b3fc9173ed
lib: use internal fileURLToPath
...
For internal usage, `internal/url` should be used.
Refs: https://github.com/nodejs/node/pull/49553
PR-URL: https://github.com/nodejs/node/pull/49558
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com >
Reviewed-By: Raz Luvaton <rluvaton@gmail.com >
Reviewed-By: Chemi Atlow <chemi@atlow.co.il >
Reviewed-By: LiviaMedeiros <livia@cirno.name >
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com >
Reviewed-By: Minwoo Jung <nodecorelab@gmail.com >
2023-09-10 14:57:37 +00:00
Moshe Atlow
47c5152545
test_runner: fix typescript coverage
...
PR-URL: https://github.com/nodejs/node/pull/49406
Fixes: https://github.com/nodejs/node/issues/49398
Reviewed-By: Chemi Atlow <chemi@atlow.co.il >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
2023-09-04 21:45:07 +00:00
Phil Nash
3a6a80a4e1
test_runner: report covered lines, functions and branches to reporters
...
This is a breaking change for the format of test:coverage events. But
the test coverage is still experimental, so I don't believe it requires
a semver-major bump.
Fixes https://github.com/nodejs/node/issues/49303
PR-URL: https://github.com/nodejs/node/pull/49320
Reviewed-By: Chemi Atlow <chemi@atlow.co.il >
Reviewed-By: Moshe Atlow <moshe@atlow.co.il >
2023-08-30 20:22:45 +00:00
Raz Luvaton
ee391f3781
test_runner: add __proto__ null
...
PR-URL: https://github.com/nodejs/node/pull/48663
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com >
Reviewed-By: Chemi Atlow <chemi@atlow.co.il >
2023-07-29 13:22:16 +00:00
Colin Ihrig
b47fce0762
test_runner: remove redundant check from coverage
...
The code coverage reporting logic already filters out URLs that
don't start with 'file:', so there is no need to also filter
out URLs that start with 'node:'.
PR-URL: https://github.com/nodejs/node/pull/48070
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com >
Reviewed-By: Moshe Atlow <moshe@atlow.co.il >
Reviewed-By: Debadree Chatterjee <debadree333@gmail.com >
2023-05-29 04:47:21 +00:00
cjihrig
4360389d67
test_runner: omit inaccessible files from coverage
...
If V8 generates code coverage for a file that is later
inaccessible to the test runner, then omit that file from the
coverage report.
PR-URL: https://github.com/nodejs/node/pull/47850
Reviewed-By: Moshe Atlow <moshe@atlow.co.il >
Reviewed-By: Beth Griggs <bethanyngriggs@gmail.com >
2023-05-10 14:08:00 +00:00
cjihrig
b31d587dc8
test_runner: support combining coverage reports
...
This commit adds support for combining code coverage reports
in the test runner. This allows coverage to be collected for
child processes, and by extension, the test runner CLI.
PR-URL: https://github.com/nodejs/node/pull/47686
Fixes: https://github.com/nodejs/node/issues/47669
Reviewed-By: Moshe Atlow <moshe@atlow.co.il >
Reviewed-By: Matteo Collina <matteo.collina@gmail.com >
2023-04-28 13:13:53 +00:00
cjihrig
53e3c0ebf8
test_runner: support coverage of unnamed functions
...
This commit updates the code coverage logic to skip the first
function in a file (which does not correspond to an actual
function) instead of skipping all functions without a name.
PR-URL: https://github.com/nodejs/node/pull/47652
Reviewed-By: Moshe Atlow <moshe@atlow.co.il >
Reviewed-By: Matteo Collina <matteo.collina@gmail.com >
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com >
2023-04-23 07:17:49 +00:00
Antoine du Hamel
fe514bf960
lib: enforce use of trailing commas for functions
...
PR-URL: https://github.com/nodejs/node/pull/46629
Reviewed-By: Jacob Smith <jacob@frende.me >
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com >
Reviewed-By: Chengzhong Wu <legendecas@gmail.com >
Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com >
2023-02-14 18:45:16 +01:00
cjihrig
8c95cb012b
test_runner: add initial code coverage support
...
This commit adds code coverage functionality to the node:test
module. When node:test is used in conjunction with the new
--test-coverage CLI flag, a coverage report is created when
the test runner finishes. The coverage summary is forwarded to
any test runner reporters so that the display can be customized
as desired. This new functionality is compatible with the
existing NODE_V8_COVERAGE environment variable as well.
There are still several limitations, which will be addressed in
subsequent pull requests:
- Coverage is only reported for a single process. It is possible
to merge coverage reports together. Once this is done, the
--test flag will be supported as well.
- Source maps are not currently supported.
- Excluding specific files or directories from the coverage
report is not currently supported. Node core modules and
node_modules/ are excluded though.
PR-URL: https://github.com/nodejs/node/pull/46017
Reviewed-By: Moshe Atlow <moshe@atlow.co.il >
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com >
2023-01-08 16:09:41 -05:00