diff --git a/package-lock.json b/package-lock.json index c27a64f8..d4611b7a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -51,9 +51,9 @@ "integrity": "sha512-tJ1rq04tGKuIJoWIH0Gyuwv4RQ3+tIu7wQrC0MV47raQ44kIzXSSFKfrxFUOWVRvesoF7mrTqigXmqoZJsXwTg==" }, "@types/istanbul-lib-coverage": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/@types/istanbul-lib-coverage/-/istanbul-lib-coverage-2.0.1.tgz", - "integrity": "sha512-hRJD2ahnnpLgsj6KWMYSrmXkM3rm2Dl1qkx6IOFD5FnuNPXJIG5L0dhgKXCYTRMGzU4n0wImQ/xfmRc4POUFlg==" + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/@types/istanbul-lib-coverage/-/istanbul-lib-coverage-2.0.3.tgz", + "integrity": "sha512-sz7iLqvVUg1gIedBOvlkxPlc8/uVzyS5OwGz1cKjXzkl3FpL3al0crU8YGU1WoHkxn0Wxbw5tyi6hvzJKNzFsw==" }, "acorn": { "version": "7.1.1", @@ -2885,9 +2885,9 @@ "dev": true }, "v8-to-istanbul": { - "version": "4.1.3", - "resolved": "https://registry.npmjs.org/v8-to-istanbul/-/v8-to-istanbul-4.1.3.tgz", - "integrity": "sha512-sAjOC+Kki6aJVbUOXJbcR0MnbfjvBzwKZazEJymA2IX49uoOdEdk+4fBq5cXgYgiyKtAyrrJNtBZdOeDIF+Fng==", + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/v8-to-istanbul/-/v8-to-istanbul-5.0.0.tgz", + "integrity": "sha512-x4Kbx2kGS+N+095L7Wgim6BECRTQUPtrbDhRFcfL1KLnzvhViKiJOy8Pl9FCRelja9ss4VsIzEHTT3cbc+fNFw==", "requires": { "@types/istanbul-lib-coverage": "^2.0.1", "convert-source-map": "^1.6.0", diff --git a/package.json b/package.json index 75f738f5..019088cd 100644 --- a/package.json +++ b/package.json @@ -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" }, diff --git a/test/fixtures/source-maps/branches/branch-1.js b/test/fixtures/source-maps/branches/branch-1.js new file mode 100644 index 00000000..ad972392 --- /dev/null +++ b/test/fixtures/source-maps/branches/branch-1.js @@ -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) diff --git a/test/fixtures/source-maps/branches/branch-2.js b/test/fixtures/source-maps/branches/branch-2.js new file mode 100644 index 00000000..169223a2 --- /dev/null +++ b/test/fixtures/source-maps/branches/branch-2.js @@ -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') + } +} \ No newline at end of file diff --git a/test/fixtures/source-maps/branches/branches.rollup.js b/test/fixtures/source-maps/branches/branches.rollup.js new file mode 100644 index 00000000..59c2eb8d --- /dev/null +++ b/test/fixtures/source-maps/branches/branches.rollup.js @@ -0,0 +1,17 @@ +'use strict'; + +var branch2 = function branch (a) { + if (a) { + console.info('a = true'); + } else { + console.info('a = false'); + } +}; + +{ + console.info('reachable'); +} + +branch2(true); +branch2(false); +//# sourceMappingURL=branches.rollup.js.map diff --git a/test/fixtures/source-maps/branches/branches.rollup.js.map b/test/fixtures/source-maps/branches/branches.rollup.js.map new file mode 100644 index 00000000..71139091 --- /dev/null +++ b/test/fixtures/source-maps/branches/branches.rollup.js.map @@ -0,0 +1 @@ +{"version":3,"file":"branches.rollup.js","sources":["branch-2.js","branch-1.js"],"sourcesContent":["module.exports = function branch (a) {\n if (a) {\n console.info('a = true')\n } else if (undefined) {\n console.info('unreachable')\n } else {\n console.info('a = false')\n }\n}","const branch = require('./branch-2')\n\nif (false) {\n console.info('unreachable')\n} else if (true) {\n console.info('reachable')\n} else {\n console.info('unreachable')\n}\n\nbranch(true)\nbranch(false)\n"],"names":["branch"],"mappings":";;AAAA,WAAc,GAAG,SAAS,MAAM,EAAE,CAAC,EAAE;AACrC,EAAE,IAAI,CAAC,EAAE;AACT,IAAI,OAAO,CAAC,IAAI,CAAC,UAAU,EAAC;AAC5B,GAAG,MAEM;AACT,IAAI,OAAO,CAAC,IAAI,CAAC,WAAW,EAAC;AAC7B,GAAG;AACH;;ACJiB;AACjB,EAAE,OAAO,CAAC,IAAI,CAAC,WAAW,EAAC;AAC3B,CAEC;AACD;AACAA,OAAM,CAAC,IAAI,EAAC;AACZA,OAAM,CAAC,KAAK"} \ No newline at end of file diff --git a/test/fixtures/source-maps/classes/class-1.js b/test/fixtures/source-maps/classes/class-1.js new file mode 100644 index 00000000..9039472c --- /dev/null +++ b/test/fixtures/source-maps/classes/class-1.js @@ -0,0 +1,5 @@ +const Foo = require('./class-2') + +const a = new Foo(0) +const b = new Foo(33) +a.methodA() diff --git a/test/fixtures/source-maps/classes/class-2.js b/test/fixtures/source-maps/classes/class-2.js new file mode 100644 index 00000000..bd2c9968 --- /dev/null +++ b/test/fixtures/source-maps/classes/class-2.js @@ -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') + } +} \ No newline at end of file diff --git a/test/fixtures/source-maps/classes/classes.rollup.js b/test/fixtures/source-maps/classes/classes.rollup.js new file mode 100644 index 00000000..baced383 --- /dev/null +++ b/test/fixtures/source-maps/classes/classes.rollup.js @@ -0,0 +1,30 @@ +'use strict'; + +var class2 = 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'); + } +}; + +const a = new class2(0); +const b = new class2(33); +a.methodA(); +//# sourceMappingURL=classes.rollup.js.map diff --git a/test/fixtures/source-maps/classes/classes.rollup.js.map b/test/fixtures/source-maps/classes/classes.rollup.js.map new file mode 100644 index 00000000..7a685837 --- /dev/null +++ b/test/fixtures/source-maps/classes/classes.rollup.js.map @@ -0,0 +1 @@ +{"version":3,"file":"classes.rollup.js","sources":["class-2.js","class-1.js"],"sourcesContent":["module.exports = class Foo {\n constructor (x=33) {\n this.x = x ? x : 99\n if (this.x) {\n console.info('covered')\n } else {\n console.info('uncovered')\n }\n this.methodC()\n }\n methodA () {\n console.info('covered')\n }\n methodB () {\n console.info('uncovered')\n }\n methodC () {\n console.info('covered')\n }\n methodD () {\n console.info('uncovered')\n }\n}","const Foo = require('./class-2')\n\nconst a = new Foo(0)\nconst b = new Foo(33)\na.methodA()\n"],"names":["Foo"],"mappings":";;AAAA,UAAc,GAAG,MAAM,GAAG,CAAC;AAC3B,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE;AACrB,IAAI,IAAI,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,GAAE;AACvB,IAAI,IAAI,IAAI,CAAC,CAAC,EAAE;AAChB,MAAM,OAAO,CAAC,IAAI,CAAC,SAAS,EAAC;AAC7B,KAAK,MAAM;AACX,MAAM,OAAO,CAAC,IAAI,CAAC,WAAW,EAAC;AAC/B,KAAK;AACL,IAAI,IAAI,CAAC,OAAO,GAAE;AAClB,GAAG;AACH,EAAE,OAAO,CAAC,GAAG;AACb,IAAI,OAAO,CAAC,IAAI,CAAC,SAAS,EAAC;AAC3B,GAAG;AACH,EAAE,OAAO,CAAC,GAAG;AACb,IAAI,OAAO,CAAC,IAAI,CAAC,WAAW,EAAC;AAC7B,GAAG;AACH,EAAE,OAAO,CAAC,GAAG;AACb,IAAI,OAAO,CAAC,IAAI,CAAC,SAAS,EAAC;AAC3B,GAAG;AACH,EAAE,OAAO,CAAC,GAAG;AACb,IAAI,OAAO,CAAC,IAAI,CAAC,WAAW,EAAC;AAC7B,GAAG;AACH;;ACpBA,MAAM,CAAC,GAAG,IAAIA,MAAG,CAAC,CAAC,EAAC;AACpB,MAAM,CAAC,GAAG,IAAIA,MAAG,CAAC,EAAE,EAAC;AACrB,CAAC,CAAC,OAAO"} \ No newline at end of file diff --git a/test/integration.js b/test/integration.js index 3a877d42..e98292b2 100644 --- a/test/integration.js +++ b/test/integration.js @@ -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, [ diff --git a/test/integration.js.snap b/test/integration.js.snap index 7133c1b4..80ffc7a8 100644 --- a/test/integration.js.snap +++ b/test/integration.js.snap @@ -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 diff --git a/test/integration.js_10.snap b/test/integration.js_10.snap index 491133c4..2b24328e 100644 --- a/test/integration.js_10.snap +++ b/test/integration.js_10.snap @@ -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