From e93747b9e9044fa14f5ceebda9d0d789aba1c655 Mon Sep 17 00:00:00 2001 From: "Benjamin E. Coe" Date: Wed, 29 Apr 2020 16:37:18 -0700 Subject: [PATCH] fix: escaping issue with cobertura reporter (#203) --- package-lock.json | 12 +++--- package.json | 3 +- test/fixtures/computed-method.js | 15 +++++++ test/integration.js | 18 ++++++++ test/integration.js.snap | 73 ++++++++++++++++++++++++++------ 5 files changed, 102 insertions(+), 19 deletions(-) create mode 100644 test/fixtures/computed-method.js diff --git a/package-lock.json b/package-lock.json index 2d8de83d..c266a910 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1400,9 +1400,9 @@ "dev": true }, "html-escaper": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/html-escaper/-/html-escaper-2.0.0.tgz", - "integrity": "sha512-a4u9BeERWGu/S8JiWEAQcdrg9v4QArtP9keViQjGMdff20fBdd8waotXaNmODqBe6uZ3Nafi7K/ho4gCQHV3Ig==" + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/html-escaper/-/html-escaper-2.0.2.tgz", + "integrity": "sha512-H2iMtd0I4Mt5eYiapRdIDjp+XzelXQ0tFE4JS7YFwFevXXMmOp9myNrUvCg0D6ws8iqkRPBfKHgbwig1SmlLfg==" }, "http-signature": { "version": "1.2.0", @@ -1660,9 +1660,9 @@ } }, "istanbul-reports": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/istanbul-reports/-/istanbul-reports-3.0.0.tgz", - "integrity": "sha512-2osTcC8zcOSUkImzN2EWQta3Vdi4WjjKw99P2yWx5mLnigAM0Rd5uYFn1cf2i/Ois45GkNjaoTqc5CxgMSX80A==", + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/istanbul-reports/-/istanbul-reports-3.0.2.tgz", + "integrity": "sha512-9tZvz7AiR3PEDNGiV9vIouQ/EAcqMXFmkcA1CDFTwOB98OZVDL0PH9glHotf5Ugp6GCOTypfzGWI/OqjWNCRUw==", "requires": { "html-escaper": "^2.0.0", "istanbul-lib-report": "^3.0.0" diff --git a/package.json b/package.json index fa6d50c8..8015d599 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,7 @@ "scripts": { "test": "node ./bin/c8.js --reporter=html --reporter=text mocha --timeout=8000 ./test/*.js", "test:snap": "CHAI_JEST_SNAPSHOT_UPDATE_ALL=true npm test", + "fix": "standard --fix", "posttest": "standard", "coverage": "./bin/c8.js report --reporter=html --reporter=text-lcov | coveralls" }, @@ -39,7 +40,7 @@ "furi": "^2.0.0", "istanbul-lib-coverage": "^3.0.0", "istanbul-lib-report": "^3.0.0", - "istanbul-reports": "^3.0.0", + "istanbul-reports": "^3.0.2", "rimraf": "^3.0.0", "test-exclude": "^6.0.0", "v8-to-istanbul": "^4.1.2", diff --git a/test/fixtures/computed-method.js b/test/fixtures/computed-method.js new file mode 100644 index 00000000..9e8aa8a2 --- /dev/null +++ b/test/fixtures/computed-method.js @@ -0,0 +1,15 @@ +class Test { + constructor() { + this.map = {}; + } + + run(i) { + this.map[i] = {}; + this.map[i].f = () => console.log("FUNC RUN"); + console.log("TEST RUN"); + } +} + +let t = new Test(); +t.run(20); +t.map[20].f(); diff --git a/test/integration.js b/test/integration.js index 839766e0..e71992e6 100644 --- a/test/integration.js +++ b/test/integration.js @@ -1,5 +1,7 @@ /* global describe, before, beforeEach, it */ +const { readFileSync } = require('fs') +const { resolve } = require('path') const { spawnSync } = require('child_process') const { statSync } = require('fs') const c8Path = require.resolve('../bin/c8') @@ -416,4 +418,20 @@ describe('c8', () => { output.toString('utf8').should.matchSnapshot() }) }) + + // see: https://github.com/bcoe/c8/issues/149 + it('cobertura report escapes special characters', () => { + spawnSync(nodePath, [ + c8Path, + '--exclude="test/*.js"', + '--temp-directory=tmp/cobertura', + '--clean=false', + '--reporter=cobertura', + nodePath, + require.resolve('./fixtures/computed-method') + ]) + const cobertura = readFileSync(resolve(process.cwd(), './coverage/cobertura-coverage.xml'), 'utf8') + .replace(/[0-9]{13,}/, 'nnnn') + cobertura.toString('utf8').should.matchSnapshot() + }) }) diff --git a/test/integration.js.snap b/test/integration.js.snap index f6936bee..92eb1460 100644 --- a/test/integration.js.snap +++ b/test/integration.js.snap @@ -8,7 +8,7 @@ File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s -------------------|---------|----------|---------|---------|------------------- All files | 86.21 | 91.67 | 66.67 | 86.21 | async.js | 100 | 100 | 100 | 100 | - c8-ignore-next.js | 90.91 | 100 | 100 | 90.91 | 21,22 + c8-ignore-next.js | 90.91 | 100 | 100 | 90.91 | 21-22 normal.js | 75 | 66.67 | 33.33 | 75 | 14-16,18-20 -------------------|---------|----------|---------|---------|------------------- ," @@ -23,7 +23,7 @@ File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s --------------|---------|----------|---------|---------|------------------- All files | 64.29 | 66.67 | 50 | 64.29 | vanilla | 78.26 | 75 | 100 | 78.26 | - loaded.js | 73.68 | 71.43 | 100 | 73.68 | 4,5,16-18 + loaded.js | 73.68 | 71.43 | 100 | 73.68 | 4-5,16-18 main.js | 100 | 100 | 100 | 100 | vanilla/dir | 0 | 0 | 0 | 0 | unloaded.js | 0 | 0 | 0 | 0 | 1-5 @@ -40,7 +40,7 @@ File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s -----------------|---------|----------|---------|---------|------------------- All files | 64.29 | 66.67 | 50 | 64.29 | ts-compiled | 78.26 | 75 | 100 | 78.26 | - loaded.ts | 73.68 | 71.43 | 100 | 73.68 | 4,5,16-18 + loaded.ts | 73.68 | 71.43 | 100 | 73.68 | 4-5,16-18 main.ts | 100 | 100 | 100 | 100 | ts-compiled/dir | 0 | 0 | 0 | 0 | unloaded.ts | 0 | 0 | 0 | 0 | 1-5 @@ -57,7 +57,7 @@ File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s --------------|---------|----------|---------|---------|------------------- All files | 64.29 | 66.67 | 50 | 64.29 | ts-only | 78.26 | 75 | 100 | 78.26 | - loaded.ts | 73.68 | 71.43 | 100 | 73.68 | 4,5,16-18 + loaded.ts | 73.68 | 71.43 | 100 | 73.68 | 4-5,16-18 main.ts | 100 | 100 | 100 | 100 | ts-only/dir | 0 | 0 | 0 | 0 | unloaded.ts | 0 | 0 | 0 | 0 | 1-5 @@ -74,7 +74,7 @@ File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s --------------|---------|----------|---------|---------|------------------- All files | 64.29 | 66.67 | 50 | 64.29 | vanilla | 78.26 | 75 | 100 | 78.26 | - loaded.js | 73.68 | 71.43 | 100 | 73.68 | 4,5,16-18 + loaded.js | 73.68 | 71.43 | 100 | 73.68 | 4-5,16-18 main.js | 100 | 100 | 100 | 100 | vanilla/dir | 0 | 0 | 0 | 0 | unloaded.js | 0 | 0 | 0 | 0 | 1-5 @@ -95,7 +95,7 @@ File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s ------------|---------|----------|---------|---------|------------------- All files | 83.33 | 100 | 66.67 | 83.33 | export.cjs | 100 | 100 | 100 | 100 | - export.mjs | 71.43 | 100 | 50 | 71.43 | 2,3 + export.mjs | 71.43 | 100 | 50 | 71.43 | 2-3 import.mjs | 100 | 100 | 100 | 100 | ------------|---------|----------|---------|---------|------------------- ," @@ -134,6 +134,55 @@ exports[`c8 check-coverage exits with 1 if coverage is below threshold 1`] = ` " `; +exports[`c8 cobertura report escapes special characters 1`] = ` +" + + + + /Users/bencoe/oss/c8 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +" +`; + exports[`c8 merges reports from subprocesses together 1`] = ` ",first @@ -199,7 +248,7 @@ a = false File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s ------------------------|---------|----------|---------|---------|------------------- All files | 84 | 57.14 | 100 | 84 | - branches.typescript.ts | 84 | 57.14 | 100 | 84 | 7,11,12,18 + branches.typescript.ts | 84 | 57.14 | 100 | 84 | 7,11-12,18 ------------------------|---------|----------|---------|---------|------------------- ," `; @@ -214,7 +263,7 @@ covered File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s -----------------------|---------|----------|---------|---------|------------------- All files | 81.82 | 87.5 | 60 | 81.82 | - classes.typescript.ts | 81.82 | 87.5 | 60 | 81.82 | 12,13,21,22,27,28 + classes.typescript.ts | 81.82 | 87.5 | 60 | 81.82 | 12-13,21-22,27-28 -----------------------|---------|----------|---------|---------|------------------- ," `; @@ -227,7 +276,7 @@ a = false File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s -------------|---------|----------|---------|---------|------------------- All files | 80 | 50 | 100 | 80 | - branches.js | 80 | 50 | 100 | 80 | 2,5,6,13 + branches.js | 80 | 50 | 100 | 80 | 2,5-6,13 -------------|---------|----------|---------|---------|------------------- ," `; @@ -242,7 +291,7 @@ covered File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s ------------|---------|----------|---------|---------|------------------- All files | 85.19 | 83.33 | 60 | 85.19 | - classes.js | 85.19 | 83.33 | 60 | 85.19 | 6,7,15,21 + classes.js | 85.19 | 83.33 | 60 | 85.19 | 6-7,15,21 ------------|---------|----------|---------|---------|------------------- ," `; @@ -270,7 +319,7 @@ covered File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s ------------|---------|----------|---------|---------|------------------- All files | 70.37 | 66.67 | 60 | 70.37 | - classes.js | 70.37 | 66.67 | 60 | 70.37 | 5-8,15,16,21,22 + classes.js | 70.37 | 66.67 | 60 | 70.37 | 5-8,15-16,21-22 ------------|---------|----------|---------|---------|------------------- ," `; @@ -304,7 +353,7 @@ 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 + ts-node-basic.ts | 88.24 | 87.5 | 80 | 88.24 | 12-13,28-29 ------------------|---------|----------|---------|---------|------------------- ," `;