Skip to content

Commit 45b0250

Browse 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 <[email protected]> Fixes: #54240 PR-URL: #54444 Reviewed-By: Jake Yuesong Li <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Moshe Atlow <[email protected]>
1 parent 336496b commit 45b0250

File tree

5 files changed

+175
-2
lines changed

5 files changed

+175
-2
lines changed

lib/internal/test_runner/coverage.js

Lines 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) {

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

Lines changed: 77 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines 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();

test/parallel/test-runner-coverage.js

Lines 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)