diff --git a/lib/internal/test_runner/coverage.js b/lib/internal/test_runner/coverage.js index b97965235e7d47..7d78bd69886566 100644 --- a/lib/internal/test_runner/coverage.js +++ b/lib/internal/test_runner/coverage.js @@ -340,8 +340,8 @@ class TestCoverage { const { data, lineLengths } = sourceMapCache[url]; let offset = 0; const executedLines = ArrayPrototypeMap(lineLengths, (length, i) => { - const coverageLine = new CoverageLine(i + 1, offset, null, length); - offset += length; + const coverageLine = new CoverageLine(i + 1, offset, null, length + 1); + offset += length + 1; return coverageLine; }); if (data.sourcesContent != null) { diff --git a/test/fixtures/test-runner/source-map-line-lengths/index.js b/test/fixtures/test-runner/source-map-line-lengths/index.js new file mode 100644 index 00000000000000..ff63423bfb3c8b --- /dev/null +++ b/test/fixtures/test-runner/source-map-line-lengths/index.js @@ -0,0 +1,77 @@ +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +function a() { + console.log(1); +} +a(); +//# sourceMappingURL=index.js.map diff --git a/test/fixtures/test-runner/source-map-line-lengths/index.js.map b/test/fixtures/test-runner/source-map-line-lengths/index.js.map new file mode 100644 index 00000000000000..ace65dc3ccdd14 --- /dev/null +++ b/test/fixtures/test-runner/source-map-line-lengths/index.js.map @@ -0,0 +1,7 @@ +{ + "version": 3, + "sources": ["index.ts"], + "sourcesContent": ["1;\n1;\n1;\n1;\n1;\n1;\n1;\n1;\n1;\n1;\n1;\n1;\n1;\n1;\n1;\n1;\n1;\n1;\n1;\n1;\n1;\n1;\n1;\n1;\n1;\n1;\n1;\n1;\n1;\n1;\n1;\n1;\n1;\n1;\n1;\n1;\n1;\n1;\n1;\n1;\n1;\n1;\n1;\n1;\n1;\n1;\n1;\n1;\n1;\n1;\n1;\n1;\n1;\n1;\n1;\n1;\n1;\n1;\n1;\n1;\n1;\n1;\n1;\n1;\n1;\n1;\n1;\n1;\n1;\n1;\n1;\n1;\nfunction a() {\n console.log(1);\n}\na();\n"], + "mappings": "AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS,IAAI;AACX,UAAQ,IAAI,CAAC;AACf;AACA,EAAE;", + "names": [] +} diff --git a/test/fixtures/test-runner/source-map-line-lengths/index.ts b/test/fixtures/test-runner/source-map-line-lengths/index.ts new file mode 100644 index 00000000000000..0eee24b0c75e45 --- /dev/null +++ b/test/fixtures/test-runner/source-map-line-lengths/index.ts @@ -0,0 +1,76 @@ +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +1; +function a() { + console.log(1); +} +a(); diff --git a/test/parallel/test-runner-coverage.js b/test/parallel/test-runner-coverage.js index 1283232a867246..8a6cb392de2585 100644 --- a/test/parallel/test-runner-coverage.js +++ b/test/parallel/test-runner-coverage.js @@ -428,3 +428,16 @@ test('coverage with included and excluded files', skipIfNoInspector, () => { assert.strictEqual(result.status, 0); assert(!findCoverageFileForPid(result.pid)); }); + +test('properly accounts for line endings in source maps', skipIfNoInspector, () => { + const fixture = fixtures.path('test-runner', 'source-map-line-lengths', 'index.js'); + const args = [ + '--test', '--experimental-test-coverage', '--test-reporter', 'tap', + fixture, + ]; + const result = spawnSync(process.execPath, args); + const report = 'index.ts | 100.00 | 100.00 | 100.00 |'; + assert.strictEqual(result.stderr.toString(), ''); + assert(result.stdout.toString().includes(report)); + assert.strictEqual(result.status, 0); +});