Skip to content

Commit

Permalink
feat: adds support for 1:many source maps (bcoe#238)
Browse files Browse the repository at this point in the history
Adds support for 1:many source-maps. These source maps are used by tools
like rollup or WebPack to bundle multiple JavaScript source files into one.

Refs: istanbuljs/v8-to-istanbul#102
  • Loading branch information
bcoe authored Aug 3, 2020
1 parent e3c025d commit a7e2c12
Show file tree
Hide file tree
Showing 13 changed files with 190 additions and 7 deletions.
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"istanbul-reports": "^3.0.2",
"rimraf": "^3.0.0",
"test-exclude": "^6.0.0",
"v8-to-istanbul": "^4.1.2",
"v8-to-istanbul": "^5.0.0",
"yargs": "^15.0.0",
"yargs-parser": "^18.0.0"
},
Expand Down
12 changes: 12 additions & 0 deletions test/fixtures/source-maps/branches/branch-1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const branch = require('./branch-2')

if (false) {
console.info('unreachable')
} else if (true) {
console.info('reachable')
} else {
console.info('unreachable')
}

branch(true)
branch(false)
9 changes: 9 additions & 0 deletions test/fixtures/source-maps/branches/branch-2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = function branch (a) {
if (a) {
console.info('a = true')
} else if (undefined) {
console.info('unreachable')
} else {
console.info('a = false')
}
}
17 changes: 17 additions & 0 deletions test/fixtures/source-maps/branches/branches.rollup.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions test/fixtures/source-maps/branches/branches.rollup.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions test/fixtures/source-maps/classes/class-1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const Foo = require('./class-2')

const a = new Foo(0)
const b = new Foo(33)
a.methodA()
23 changes: 23 additions & 0 deletions test/fixtures/source-maps/classes/class-2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module.exports = class Foo {
constructor (x=33) {
this.x = x ? x : 99
if (this.x) {
console.info('covered')
} else {
console.info('uncovered')
}
this.methodC()
}
methodA () {
console.info('covered')
}
methodB () {
console.info('uncovered')
}
methodC () {
console.info('covered')
}
methodD () {
console.info('uncovered')
}
}
30 changes: 30 additions & 0 deletions test/fixtures/source-maps/classes/classes.rollup.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions test/fixtures/source-maps/classes/classes.rollup.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions test/integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,31 @@ describe('c8', () => {
output.toString('utf8').should.matchSnapshot()
})
})
describe('rollup', () => {
it('remaps branches', () => {
const { output } = spawnSync(nodePath, [
c8Path,
'--exclude="test/*.js"',
'--temp-directory=tmp/source-map',
'--clean=true',
nodePath,
require.resolve('./fixtures/source-maps/branches/branches.rollup.js')
])
output.toString('utf8').should.matchSnapshot()
})

it('remaps classes', () => {
const { output } = spawnSync(nodePath, [
c8Path,
'--exclude="test/*.js"',
'--temp-directory=tmp/source-map',
'--clean=true',
nodePath,
require.resolve('./fixtures/source-maps/classes/classes.rollup.js')
])
output.toString('utf8').should.matchSnapshot()
})
})
describe('ts-node', () => {
it('reads source-map from cache, and applies to coverage', () => {
const { output } = spawnSync(nodePath, [
Expand Down
30 changes: 30 additions & 0 deletions test/integration.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,36 @@ All files | 70.37 | 66.67 | 60 | 70.37 |
,"
`;
exports[`c8 source-maps rollup remaps branches 1`] = `
",reachable
a = true
a = false
-------------|---------|----------|---------|---------|-------------------
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
-------------|---------|----------|---------|---------|-------------------
All files | 100 | 100 | 100 | 100 |
branch-1.js | 100 | 100 | 100 | 100 |
branch-2.js | 100 | 100 | 100 | 100 |
-------------|---------|----------|---------|---------|-------------------
,"
`;
exports[`c8 source-maps rollup remaps classes 1`] = `
",covered
covered
covered
covered
covered
------------|---------|----------|---------|---------|-------------------
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
------------|---------|----------|---------|---------|-------------------
All files | 78.57 | 85.71 | 60 | 78.57 |
class-1.js | 100 | 100 | 100 | 100 |
class-2.js | 73.91 | 85.71 | 60 | 73.91 | 7-8,15-16,21-22
------------|---------|----------|---------|---------|-------------------
,"
`;
exports[`c8 source-maps ts-node reads source-map from cache, and applies to coverage 1`] = `
",covered
covered
Expand Down
30 changes: 30 additions & 0 deletions test/integration.js_10.snap
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,36 @@ All files | 70.37 | 66.67 | 60 | 70.37 |
,"
`;
exports[`c8 source-maps rollup remaps branches 1`] = `
",reachable
a = true
a = false
-------------|---------|----------|---------|---------|-------------------
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
-------------|---------|----------|---------|---------|-------------------
All files | 100 | 100 | 100 | 100 |
branch-1.js | 100 | 100 | 100 | 100 |
branch-2.js | 100 | 100 | 100 | 100 |
-------------|---------|----------|---------|---------|-------------------
,"
`;
exports[`c8 source-maps rollup remaps classes 1`] = `
",covered
covered
covered
covered
covered
------------|---------|----------|---------|---------|-------------------
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
------------|---------|----------|---------|---------|-------------------
All files | 78.57 | 85.71 | 60 | 78.57 |
class-1.js | 100 | 100 | 100 | 100 |
class-2.js | 73.91 | 85.71 | 60 | 73.91 | 7-8,15-16,21-22
------------|---------|----------|---------|---------|-------------------
,"
`;
exports[`c8 source-maps ts-node reads source-map from cache, and applies to coverage 1`] = `
",covered
covered
Expand Down

0 comments on commit a7e2c12

Please sign in to comment.