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 800f7c4

Browse filesBrowse files
avivkelleraduh95
authored andcommitted
test_runner: throw on invalid source map
PR-URL: #55055 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
1 parent 0f7e3f0 commit 800f7c4
Copy full SHA for 800f7c4

File tree

Expand file treeCollapse file tree

7 files changed

+27
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

7 files changed

+27
-0
lines changed
Open diff view settings
Collapse file

‎doc/api/errors.md‎

Copy file name to clipboardExpand all lines: doc/api/errors.md
+6Lines changed: 6 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -2573,6 +2573,12 @@ disconnected socket.
25732573

25742574
A call was made and the UDP subsystem was not running.
25752575

2576+
<a id="ERR_SOURCE_MAP_CORRUPT"></a>
2577+
2578+
### `ERR_SOURCE_MAP_CORRUPT`
2579+
2580+
The source map could not be parsed because it does not exist, or is corrupt.
2581+
25762582
<a id="ERR_SOURCE_MAP_MISSING_SOURCE"></a>
25772583

25782584
### `ERR_SOURCE_MAP_MISSING_SOURCE`
Collapse file

‎lib/internal/errors.js‎

Copy file name to clipboardExpand all lines: lib/internal/errors.js
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1711,6 +1711,7 @@ E('ERR_SOCKET_CONNECTION_TIMEOUT',
17111711
E('ERR_SOCKET_DGRAM_IS_CONNECTED', 'Already connected', Error);
17121712
E('ERR_SOCKET_DGRAM_NOT_CONNECTED', 'Not connected', Error);
17131713
E('ERR_SOCKET_DGRAM_NOT_RUNNING', 'Not running', Error);
1714+
E('ERR_SOURCE_MAP_CORRUPT', `The source map for '%s' does not exist or is corrupt.`, Error);
17141715
E('ERR_SOURCE_MAP_MISSING_SOURCE', `Cannot find '%s' imported from the source map for '%s'`, Error);
17151716
E('ERR_SRI_PARSE',
17161717
'Subresource Integrity string %j had an unexpected %j at position %d',
Collapse file

‎lib/internal/test_runner/coverage.js‎

Copy file name to clipboardExpand all lines: lib/internal/test_runner/coverage.js
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ const { fileURLToPath } = require('internal/url');
3232
const { kMappings, SourceMap } = require('internal/source_map/source_map');
3333
const {
3434
codes: {
35+
ERR_SOURCE_MAP_CORRUPT,
3536
ERR_SOURCE_MAP_MISSING_SOURCE,
3637
},
3738
} = require('internal/errors');
@@ -353,6 +354,7 @@ class TestCoverage {
353354
continue;
354355
}
355356
const { data, lineLengths } = sourceMapCache[url];
357+
if (!data) throw new ERR_SOURCE_MAP_CORRUPT(url);
356358
let offset = 0;
357359
const executedLines = ArrayPrototypeMap(lineLengths, (length, i) => {
358360
const coverageLine = new CoverageLine(i + 1, offset, null, length + 1);
Collapse file

‎test/fixtures/test-runner/source-maps/invalid-json/index.js‎

Copy file name to clipboardExpand all lines: test/fixtures/test-runner/source-maps/invalid-json/index.js
+2Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Collapse file

‎test/fixtures/test-runner/source-maps/invalid-json/index.js.map‎

Copy file name to clipboardExpand all lines: test/fixtures/test-runner/source-maps/invalid-json/index.js.map
+1Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Collapse file

‎test/fixtures/test-runner/source-maps/missing-map.js‎

Copy file name to clipboardExpand all lines: test/fixtures/test-runner/source-maps/missing-map.js
+1Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
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
+14Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,18 @@ describe('Coverage with source maps', async () => {
8080
t.assert.ok(spawned.stdout.includes(error));
8181
t.assert.strictEqual(spawned.code, 1);
8282
});
83+
84+
for (const [file, message] of [
85+
[fixtures.path('test-runner', 'source-maps', 'invalid-json', 'index.js'), 'is not valid JSON'],
86+
[fixtures.path('test-runner', 'source-maps', 'missing-map.js'), 'does not exist'],
87+
]) {
88+
await it(`should throw when a source map ${message}`, async (t) => {
89+
const spawned = await common.spawnPromisified(process.execPath, [...flags, file]);
90+
91+
const error = `The source map for '${pathToFileURL(file)}' does not exist or is corrupt`;
92+
t.assert.strictEqual(spawned.stderr, '');
93+
t.assert.ok(spawned.stdout.includes(error));
94+
t.assert.strictEqual(spawned.code, 1);
95+
});
96+
}
8397
}).then(common.mustCall());

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.