Skip to content

Commit d9f0407

Browse files
avivkelleraduh95
authored andcommitted
test_runner: require --enable-source-maps for sourcemap coverage
PR-URL: #55359 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
1 parent c5abf50 commit d9f0407

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

lib/internal/test_runner/coverage.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,19 @@ class CoverageLine {
5757
}
5858

5959
class TestCoverage {
60-
constructor(coverageDirectory, originalCoverageDirectory, workingDirectory, excludeGlobs, includeGlobs, thresholds) {
60+
constructor(coverageDirectory,
61+
originalCoverageDirectory,
62+
workingDirectory,
63+
excludeGlobs,
64+
includeGlobs,
65+
sourceMaps,
66+
thresholds) {
6167
this.coverageDirectory = coverageDirectory;
6268
this.originalCoverageDirectory = originalCoverageDirectory;
6369
this.workingDirectory = workingDirectory;
6470
this.excludeGlobs = excludeGlobs;
6571
this.includeGlobs = includeGlobs;
72+
this.sourceMaps = sourceMaps;
6673
this.thresholds = thresholds;
6774
}
6875

@@ -341,7 +348,7 @@ class TestCoverage {
341348
mapCoverageWithSourceMap(coverage) {
342349
const { result } = coverage;
343350
const sourceMapCache = coverage['source-map-cache'];
344-
if (!sourceMapCache) {
351+
if (!this.sourceMaps || !sourceMapCache) {
345352
return result;
346353
}
347354
const newResult = new SafeMap();
@@ -514,6 +521,7 @@ function setupCoverage(options) {
514521
options.cwd,
515522
options.coverageExcludeGlobs,
516523
options.coverageIncludeGlobs,
524+
options.sourceMaps,
517525
{
518526
__proto__: null,
519527
line: options.lineCoverage,

test/parallel/test-runner-coverage-source-map.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ function generateReport(report) {
1919
}
2020

2121
const flags = [
22+
'--enable-source-maps',
2223
'--test', '--experimental-test-coverage', '--test-reporter', 'tap',
2324
];
2425

@@ -40,6 +41,28 @@ describe('Coverage with source maps', async () => {
4041
const spawned = await common.spawnPromisified(process.execPath, flags, {
4142
cwd: fixtures.path('test-runner', 'coverage')
4243
});
44+
45+
t.assert.strictEqual(spawned.stderr, '');
46+
t.assert.ok(spawned.stdout.includes(report));
47+
t.assert.strictEqual(spawned.code, 1);
48+
});
49+
50+
await it('should only work with --enable-source-maps', async (t) => {
51+
const report = generateReport([
52+
'# --------------------------------------------------------------',
53+
'# file | line % | branch % | funcs % | uncovered lines',
54+
'# --------------------------------------------------------------',
55+
'# a.test.mjs | 100.00 | 100.00 | 100.00 | ',
56+
'# index.test.js | 71.43 | 66.67 | 100.00 | 6-7',
57+
'# stdin.test.js | 100.00 | 100.00 | 100.00 | ',
58+
'# --------------------------------------------------------------',
59+
'# all files | 85.71 | 87.50 | 100.00 | ',
60+
'# --------------------------------------------------------------',
61+
]);
62+
63+
const spawned = await common.spawnPromisified(process.execPath, flags.slice(1), {
64+
cwd: fixtures.path('test-runner', 'coverage')
65+
});
4366
t.assert.strictEqual(spawned.stderr, '');
4467
t.assert.ok(spawned.stdout.includes(report));
4568
t.assert.strictEqual(spawned.code, 1);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy