Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit b9200c3

Browse filesBrowse files
avivkellerruyadorno
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 5c3ee88 commit b9200c3
Copy full SHA for b9200c3

2 files changed

+33-2Lines changed: 33 additions & 2 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/internal/test_runner/coverage.js‎

Copy file name to clipboardExpand all lines: lib/internal/test_runner/coverage.js
+10-2Lines 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();
@@ -517,6 +524,7 @@ function setupCoverage(options) {
517524
cwd,
518525
options.coverageExcludeGlobs,
519526
options.coverageIncludeGlobs,
527+
options.sourceMaps,
520528
{
521529
__proto__: null,
522530
line: options.lineCoverage,
Collapse file

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

Copy file name to clipboardExpand all lines: test/parallel/test-runner-coverage-source-map.js
+23Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.