diff --git a/lib/report.js b/lib/report.js index c8593126..1d1ddbf5 100644 --- a/lib/report.js +++ b/lib/report.js @@ -131,6 +131,8 @@ class Report { const sources = {} if (this.sourceMapCache[`file://${v8ScriptCov.url}`]) { const sourceMapAndLineLengths = this.sourceMapCache[`file://${v8ScriptCov.url}`] + // See: https://github.com/nodejs/node/pull/34305 + if (!sourceMapAndLineLengths.data) return sources.sourceMap = { sourcemap: sourceMapAndLineLengths.data } diff --git a/test/fixtures/source-maps/fake-source-map.js b/test/fixtures/source-maps/fake-source-map.js new file mode 100644 index 00000000..1b91d816 --- /dev/null +++ b/test/fixtures/source-maps/fake-source-map.js @@ -0,0 +1,7 @@ +const a = 99; +if (true) { + const b = 101; +} else { + const c = 102; +} +const sm = '//# sourceMappingURL=https://ci.nodejs.org/402' diff --git a/test/integration.js b/test/integration.js index fe177f69..3a877d42 100644 --- a/test/integration.js +++ b/test/integration.js @@ -374,19 +374,28 @@ describe('c8', () => { output.toString('utf8').should.matchSnapshot() }) }) - }) - - describe('ts-node', () => { - beforeEach(cb => rimraf('tmp/source-map', cb)) - - it('reads source-map from cache, and applies to coverage', () => { + describe('ts-node', () => { + it('reads source-map from cache, and applies to coverage', () => { + const { output } = spawnSync(nodePath, [ + c8Path, + '--exclude="test/*.js"', + '--temp-directory=tmp/source-map', + '--clean=true', + tsNodePath, + require.resolve('./fixtures/ts-node-basic.ts') + ]) + output.toString('utf8').should.matchSnapshot() + }) + }) + // See: https://github.com/bcoe/c8/issues/232 + it("does not attempt to load source map URLs that aren't", () => { const { output } = spawnSync(nodePath, [ c8Path, '--exclude="test/*.js"', '--temp-directory=tmp/source-map', '--clean=true', - tsNodePath, - require.resolve('./fixtures/ts-node-basic.ts') + nodePath, + require.resolve('./fixtures/source-maps/fake-source-map.js') ]) output.toString('utf8').should.matchSnapshot() }) diff --git a/test/integration.js.snap b/test/integration.js.snap index 94a4f80f..7133c1b4 100644 --- a/test/integration.js.snap +++ b/test/integration.js.snap @@ -375,6 +375,16 @@ All files | 85.19 | 83.33 | 60 | 85.19 | ," `; +exports[`c8 source-maps does not attempt to load source map URLs that aren't 1`] = ` +",--------------------|---------|----------|---------|---------|------------------- +File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s +--------------------|---------|----------|---------|---------|------------------- +All files | 71.43 | 50 | 100 | 71.43 | + fake-source-map.js | 71.43 | 50 | 100 | 71.43 | 5-6 +--------------------|---------|----------|---------|---------|------------------- +," +`; + exports[`c8 source-maps nyc remaps branches 1`] = ` ",reachable a = true @@ -403,6 +413,21 @@ All files | 70.37 | 66.67 | 60 | 70.37 | ," `; +exports[`c8 source-maps ts-node reads source-map from cache, and applies to coverage 1`] = ` +",covered +covered +covered +covered +covered +------------------|---------|----------|---------|---------|------------------- +File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s +------------------|---------|----------|---------|---------|------------------- +All files | 88.24 | 87.5 | 80 | 88.24 | + ts-node-basic.ts | 88.24 | 87.5 | 80 | 88.24 | 12-13,28-29 +------------------|---------|----------|---------|---------|------------------- +," +`; + exports[`c8 supports exeternally set NODE_V8_COVERAGE 1`] = ` ",hey i am a line of code diff --git a/test/integration.js_10.snap b/test/integration.js_10.snap index da34f241..491133c4 100644 --- a/test/integration.js_10.snap +++ b/test/integration.js_10.snap @@ -6,13 +6,13 @@ covered --------------------------|---------|----------|---------|---------|-------------------------------- File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s --------------------------|---------|----------|---------|---------|-------------------------------- -All files | 76.53 | 61.9 | 68.57 | 76.53 | +All files | 76.3 | 61.9 | 68.57 | 76.3 | bin | 78.85 | 60 | 66.67 | 78.85 | c8.js | 78.85 | 60 | 66.67 | 78.85 | 22,27-29,32-33,41-43,50-51 - lib | 81.24 | 53.7 | 84.21 | 81.24 | + lib | 80.89 | 53.7 | 84.21 | 80.89 | is-cjs-esm-bridge.js | 90 | 25 | 100 | 90 | 9 parse-args.js | 96.13 | 45.45 | 100 | 96.13 | 109-110,118-119,132-133 - report.js | 75.99 | 61.76 | 84.62 | 75.99 | ...165,171-204,235-236,264-266 + report.js | 75.44 | 61.76 | 84.62 | 75.44 | ...167,173-206,237-238,266-268 source-map-from-file.js | 44 | 100 | 0 | 44 | 10-23 lib/commands | 44.44 | 75 | 16.67 | 44.44 | check-coverage.js | 21.31 | 100 | 0 | 21.31 | 9-11,14-27,30-44,46-61 @@ -130,13 +130,13 @@ hey --------------------------|---------|----------|---------|---------|-------------------------------- File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s --------------------------|---------|----------|---------|---------|-------------------------------- -All files | 76.04 | 59.49 | 67.65 | 76.04 | +All files | 75.81 | 59.49 | 67.65 | 75.81 | bin | 78.85 | 60 | 66.67 | 78.85 | c8.js | 78.85 | 60 | 66.67 | 78.85 | 22,27-29,32-33,41-43,50-51 - lib | 81.24 | 53.7 | 84.21 | 81.24 | + lib | 80.89 | 53.7 | 84.21 | 80.89 | is-cjs-esm-bridge.js | 90 | 25 | 100 | 90 | 9 parse-args.js | 96.13 | 45.45 | 100 | 96.13 | 109-110,118-119,132-133 - report.js | 75.99 | 61.76 | 84.62 | 75.99 | ...165,171-204,235-236,264-266 + report.js | 75.44 | 61.76 | 84.62 | 75.44 | ...167,173-206,237-238,266-268 source-map-from-file.js | 44 | 100 | 0 | 44 | 10-23 lib/commands | 44.44 | 75 | 16.67 | 44.44 | check-coverage.js | 21.31 | 100 | 0 | 21.31 | 9-11,14-27,30-44,46-61 @@ -145,9 +145,9 @@ All files | 76.04 | 59.49 | 67.65 | 76.04 | async.js | 100 | 100 | 100 | 100 | normal.js | 75 | 66.67 | 33.33 | 75 | 14-16,18-20 --------------------------|---------|----------|---------|---------|-------------------------------- -,ERROR: Coverage for lines (76.04%) does not meet global threshold (101%) +,ERROR: Coverage for lines (75.81%) does not meet global threshold (101%) ERROR: Coverage for branches (59.49%) does not meet global threshold (82%) -ERROR: Coverage for statements (76.04%) does not meet global threshold (96%) +ERROR: Coverage for statements (75.81%) does not meet global threshold (96%) " `; @@ -165,9 +165,9 @@ ERROR: Coverage for branches (25%) does not meet threshold (82%) for lib/is-cjs- ERROR: Coverage for statements (90%) does not meet threshold (96%) for lib/is-cjs-esm-bridge.js ERROR: Coverage for lines (96.13%) does not meet threshold (101%) for lib/parse-args.js ERROR: Coverage for branches (45.45%) does not meet threshold (82%) for lib/parse-args.js -ERROR: Coverage for lines (75.99%) does not meet threshold (101%) for lib/report.js +ERROR: Coverage for lines (75.44%) does not meet threshold (101%) for lib/report.js ERROR: Coverage for branches (61.76%) does not meet threshold (82%) for lib/report.js -ERROR: Coverage for statements (75.99%) does not meet threshold (96%) for lib/report.js +ERROR: Coverage for statements (75.44%) does not meet threshold (96%) for lib/report.js ERROR: Coverage for lines (44%) does not meet threshold (101%) for lib/source-map-from-file.js ERROR: Coverage for statements (44%) does not meet threshold (96%) for lib/source-map-from-file.js ERROR: Coverage for lines (100%) does not meet threshold (101%) for test/fixtures/async.js @@ -180,9 +180,9 @@ ERROR: Coverage for statements (75%) does not meet threshold (96%) for test/fixt exports[`c8 check-coverage exits with 0 if coverage within threshold 1`] = `",,"`; exports[`c8 check-coverage exits with 1 if coverage is below threshold 1`] = ` -",,ERROR: Coverage for lines (76.04%) does not meet global threshold (101%) +",,ERROR: Coverage for lines (75.81%) does not meet global threshold (101%) ERROR: Coverage for branches (59.49%) does not meet global threshold (82%) -ERROR: Coverage for statements (76.04%) does not meet global threshold (96%) +ERROR: Coverage for statements (75.81%) does not meet global threshold (96%) " `; @@ -254,13 +254,13 @@ exports[`c8 report generates report from existing temporary files 1`] = ` ",--------------------------|---------|----------|---------|---------|-------------------------------- File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s --------------------------|---------|----------|---------|---------|-------------------------------- -All files | 76.04 | 59.49 | 67.65 | 76.04 | +All files | 75.81 | 59.49 | 67.65 | 75.81 | bin | 78.85 | 60 | 66.67 | 78.85 | c8.js | 78.85 | 60 | 66.67 | 78.85 | 22,27-29,32-33,41-43,50-51 - lib | 81.24 | 53.7 | 84.21 | 81.24 | + lib | 80.89 | 53.7 | 84.21 | 80.89 | is-cjs-esm-bridge.js | 90 | 25 | 100 | 90 | 9 parse-args.js | 96.13 | 45.45 | 100 | 96.13 | 109-110,118-119,132-133 - report.js | 75.99 | 61.76 | 84.62 | 75.99 | ...165,171-204,235-236,264-266 + report.js | 75.44 | 61.76 | 84.62 | 75.44 | ...167,173-206,237-238,266-268 source-map-from-file.js | 44 | 100 | 0 | 44 | 10-23 lib/commands | 44.44 | 75 | 16.67 | 44.44 | check-coverage.js | 21.31 | 100 | 0 | 21.31 | 9-11,14-27,30-44,46-61 @@ -276,13 +276,13 @@ exports[`c8 report supports --check-coverage, when generating reports 1`] = ` ",--------------------------|---------|----------|---------|---------|-------------------------------- File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s --------------------------|---------|----------|---------|---------|-------------------------------- -All files | 76.04 | 59.49 | 67.65 | 76.04 | +All files | 75.81 | 59.49 | 67.65 | 75.81 | bin | 78.85 | 60 | 66.67 | 78.85 | c8.js | 78.85 | 60 | 66.67 | 78.85 | 22,27-29,32-33,41-43,50-51 - lib | 81.24 | 53.7 | 84.21 | 81.24 | + lib | 80.89 | 53.7 | 84.21 | 80.89 | is-cjs-esm-bridge.js | 90 | 25 | 100 | 90 | 9 parse-args.js | 96.13 | 45.45 | 100 | 96.13 | 109-110,118-119,132-133 - report.js | 75.99 | 61.76 | 84.62 | 75.99 | ...165,171-204,235-236,264-266 + report.js | 75.44 | 61.76 | 84.62 | 75.44 | ...167,173-206,237-238,266-268 source-map-from-file.js | 44 | 100 | 0 | 44 | 10-23 lib/commands | 44.44 | 75 | 16.67 | 44.44 | check-coverage.js | 21.31 | 100 | 0 | 21.31 | 9-11,14-27,30-44,46-61 @@ -291,9 +291,9 @@ All files | 76.04 | 59.49 | 67.65 | 76.04 | async.js | 100 | 100 | 100 | 100 | normal.js | 75 | 66.67 | 33.33 | 75 | 14-16,18-20 --------------------------|---------|----------|---------|---------|-------------------------------- -,ERROR: Coverage for lines (76.04%) does not meet global threshold (101%) +,ERROR: Coverage for lines (75.81%) does not meet global threshold (101%) ERROR: Coverage for branches (59.49%) does not meet global threshold (82%) -ERROR: Coverage for statements (76.04%) does not meet global threshold (96%) +ERROR: Coverage for statements (75.81%) does not meet global threshold (96%) " `; @@ -428,6 +428,16 @@ All files | 85.19 | 83.33 | 60 | 85.19 | ," `; +exports[`c8 source-maps does not attempt to load source map URLs that aren't 1`] = ` +",--------------------|---------|----------|---------|---------|------------------- +File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s +--------------------|---------|----------|---------|---------|------------------- +All files | 71.43 | 50 | 100 | 71.43 | + fake-source-map.js | 71.43 | 50 | 100 | 71.43 | 5-6 +--------------------|---------|----------|---------|---------|------------------- +," +`; + exports[`c8 source-maps nyc remaps branches 1`] = ` ",reachable a = true @@ -456,6 +466,21 @@ All files | 70.37 | 66.67 | 60 | 70.37 | ," `; +exports[`c8 source-maps ts-node reads source-map from cache, and applies to coverage 1`] = ` +",covered +covered +covered +covered +covered +------------------|---------|----------|---------|---------|------------------- +File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s +------------------|---------|----------|---------|---------|------------------- +All files | 79.41 | 85.71 | 66.67 | 79.41 | + ts-node-basic.ts | 79.41 | 85.71 | 66.67 | 79.41 | 15-17,29-32 +------------------|---------|----------|---------|---------|------------------- +," +`; + exports[`c8 supports exeternally set NODE_V8_COVERAGE 1`] = ` ",hey i am a line of code