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 45b0250

Browse filesBrowse files
cjihrigyume-chan
authored andcommitted
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: #54240 PR-URL: #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>
1 parent 336496b commit 45b0250
Copy full SHA for 45b0250

5 files changed

+175-2Lines changed: 175 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
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -340,8 +340,8 @@ class TestCoverage {
340340
const { data, lineLengths } = sourceMapCache[url];
341341
let offset = 0;
342342
const executedLines = ArrayPrototypeMap(lineLengths, (length, i) => {
343-
const coverageLine = new CoverageLine(i + 1, offset, null, length);
344-
offset += length;
343+
const coverageLine = new CoverageLine(i + 1, offset, null, length + 1);
344+
offset += length + 1;
345345
return coverageLine;
346346
});
347347
if (data.sourcesContent != null) {
Collapse file

‎test/fixtures/test-runner/source-map-line-lengths/index.js‎

Copy file name to clipboardExpand all lines: test/fixtures/test-runner/source-map-line-lengths/index.js
+77Lines changed: 77 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-map-line-lengths/index.js.map‎

Copy file name to clipboardExpand all lines: test/fixtures/test-runner/source-map-line-lengths/index.js.map
+7Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Collapse file
+76Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
1;
2+
1;
3+
1;
4+
1;
5+
1;
6+
1;
7+
1;
8+
1;
9+
1;
10+
1;
11+
1;
12+
1;
13+
1;
14+
1;
15+
1;
16+
1;
17+
1;
18+
1;
19+
1;
20+
1;
21+
1;
22+
1;
23+
1;
24+
1;
25+
1;
26+
1;
27+
1;
28+
1;
29+
1;
30+
1;
31+
1;
32+
1;
33+
1;
34+
1;
35+
1;
36+
1;
37+
1;
38+
1;
39+
1;
40+
1;
41+
1;
42+
1;
43+
1;
44+
1;
45+
1;
46+
1;
47+
1;
48+
1;
49+
1;
50+
1;
51+
1;
52+
1;
53+
1;
54+
1;
55+
1;
56+
1;
57+
1;
58+
1;
59+
1;
60+
1;
61+
1;
62+
1;
63+
1;
64+
1;
65+
1;
66+
1;
67+
1;
68+
1;
69+
1;
70+
1;
71+
1;
72+
1;
73+
function a() {
74+
console.log(1);
75+
}
76+
a();
Collapse file

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

Copy file name to clipboardExpand all lines: test/parallel/test-runner-coverage.js
+13Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,3 +428,16 @@ test('coverage with included and excluded files', skipIfNoInspector, () => {
428428
assert.strictEqual(result.status, 0);
429429
assert(!findCoverageFileForPid(result.pid));
430430
});
431+
432+
test('properly accounts for line endings in source maps', skipIfNoInspector, () => {
433+
const fixture = fixtures.path('test-runner', 'source-map-line-lengths', 'index.js');
434+
const args = [
435+
'--test', '--experimental-test-coverage', '--test-reporter', 'tap',
436+
fixture,
437+
];
438+
const result = spawnSync(process.execPath, args);
439+
const report = 'index.ts | 100.00 | 100.00 | 100.00 |';
440+
assert.strictEqual(result.stderr.toString(), '');
441+
assert(result.stdout.toString().includes(report));
442+
assert.strictEqual(result.status, 0);
443+
});

0 commit comments

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