Skip to content

Commit

Permalink
test_runner: require --enable-source-maps for source map coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
RedYetiDev committed Sep 21, 2024
1 parent 8b8fc53 commit a478463
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
3 changes: 2 additions & 1 deletion lib/internal/test_runner/coverage.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const { tmpdir } = require('os');
const { join, resolve, relative, matchesGlob } = require('path');
const { fileURLToPath } = require('internal/url');
const { kMappings, SourceMap } = require('internal/source_map/source_map');
const { getOptionValue } = require('internal/options');
const kCoverageFileRegex = /^coverage-(\d+)-(\d{13})-(\d+)\.json$/;
const kIgnoreRegex = /\/\* node:coverage ignore next (?<count>\d+ )?\*\//;
const kLineEndingRegex = /\r?\n$/u;
Expand Down Expand Up @@ -335,7 +336,7 @@ class TestCoverage {
mapCoverageWithSourceMap(coverage) {
const { result } = coverage;
const sourceMapCache = coverage['source-map-cache'];
if (!sourceMapCache) {
if (!getOptionValue('--enable-source-maps') || !sourceMapCache) {
return result;
}
const newResult = new SafeMap();
Expand Down
10 changes: 8 additions & 2 deletions test/parallel/test-runner-coverage.js
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,10 @@ test('coverage with source maps', skipIfNoInspector, () => {

const fixture = fixtures.path('test-runner', 'coverage');
const args = [
'--test', '--experimental-test-coverage', '--test-reporter', 'tap',
'--enable-source-maps',
'--test',
'--experimental-test-coverage',
'--test-reporter', 'tap',
];
const result = spawnSync(process.execPath, args, { cwd: fixture });

Expand Down Expand Up @@ -489,7 +492,10 @@ test('coverage with included and excluded files', skipIfNoInspector, () => {
test('properly accounts for line endings in source maps', skipIfNoInspector, () => {
const fixture = fixtures.path('test-runner', 'source-map-line-lengths', 'index.js');
const args = [
'--test', '--experimental-test-coverage', '--test-reporter', 'tap',
'--enable-source-maps',
'--test',
'--experimental-test-coverage',
'--test-reporter', 'tap',
fixture,
];
const report = [
Expand Down

0 comments on commit a478463

Please sign in to comment.