Skip to content

Commit

Permalink
fix: ignore missing source maps in raw coverage output (#233)
Browse files Browse the repository at this point in the history
  • Loading branch information
bcoe committed Jul 11, 2020
1 parent 414844e commit eed98af
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 28 deletions.
2 changes: 2 additions & 0 deletions lib/report.js
Expand Up @@ -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
}
Expand Down
7 changes: 7 additions & 0 deletions 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'
25 changes: 17 additions & 8 deletions test/integration.js
Expand Up @@ -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()
})
Expand Down
25 changes: 25 additions & 0 deletions test/integration.js.snap
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
65 changes: 45 additions & 20 deletions test/integration.js_10.snap
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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%)
"
`;

Expand All @@ -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
Expand All @@ -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%)
"
`;

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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%)
"
`;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit eed98af

Please sign in to comment.