Skip to content

Commit

Permalink
fix: escaping issue with cobertura reporter (bcoe#203)
Browse files Browse the repository at this point in the history
  • Loading branch information
bcoe authored Apr 29, 2020
1 parent 6410016 commit e93747b
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 19 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.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down Expand Up @@ -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",
Expand Down
15 changes: 15 additions & 0 deletions test/fixtures/computed-method.js
Original file line number Diff line number Diff line change
@@ -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();
18 changes: 18 additions & 0 deletions test/integration.js
Original file line number Diff line number Diff line change
@@ -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')
Expand Down Expand Up @@ -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()
})
})
73 changes: 61 additions & 12 deletions test/integration.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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
-------------------|---------|----------|---------|---------|-------------------
,"
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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 |
------------|---------|----------|---------|---------|-------------------
,"
Expand Down Expand Up @@ -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`] = `
"<?xml version=\\"1.0\\" ?>
<!DOCTYPE coverage SYSTEM \\"http://cobertura.sourceforge.net/xml/coverage-04.dtd\\">
<coverage lines-valid=\\"15\\" lines-covered=\\"15\\" line-rate=\\"1\\" branches-valid=\\"4\\" branches-covered=\\"4\\" branch-rate=\\"1\\" timestamp=\\"nnnn\\" complexity=\\"0\\" version=\\"0.1\\">
<sources>
<source>/Users/bencoe/oss/c8</source>
</sources>
<packages>
<class name=\\"computed-method.js\\" filename=\\"test/fixtures/computed-method.js\\" line-rate=\\"1\\" branch-rate=\\"1\\">
<methods>
<method name=\\"Test\\" hits=\\"1\\" signature=\\"()V\\">
<lines>
<line number=\\"2\\" hits=\\"1\\"/>
</lines>
</method>
<method name=\\"run\\" hits=\\"1\\" signature=\\"()V\\">
<lines>
<line number=\\"6\\" hits=\\"1\\"/>
</lines>
</method>
<method name=\\"map.&lt;computed&gt;.f\\" hits=\\"1\\" signature=\\"()V\\">
<lines>
<line number=\\"8\\" hits=\\"1\\"/>
</lines>
</method>
</methods>
<lines>
<line number=\\"1\\" hits=\\"1\\" branch=\\"true\\" condition-coverage=\\"100% (1/1)\\"/>
<line number=\\"2\\" hits=\\"1\\" branch=\\"true\\" condition-coverage=\\"100% (1/1)\\"/>
<line number=\\"3\\" hits=\\"1\\" branch=\\"false\\"/>
<line number=\\"4\\" hits=\\"1\\" branch=\\"false\\"/>
<line number=\\"5\\" hits=\\"1\\" branch=\\"false\\"/>
<line number=\\"6\\" hits=\\"1\\" branch=\\"true\\" condition-coverage=\\"100% (1/1)\\"/>
<line number=\\"7\\" hits=\\"1\\" branch=\\"false\\"/>
<line number=\\"8\\" hits=\\"1\\" branch=\\"true\\" condition-coverage=\\"100% (1/1)\\"/>
<line number=\\"9\\" hits=\\"1\\" branch=\\"false\\"/>
<line number=\\"10\\" hits=\\"1\\" branch=\\"false\\"/>
<line number=\\"11\\" hits=\\"1\\" branch=\\"false\\"/>
<line number=\\"12\\" hits=\\"1\\" branch=\\"false\\"/>
<line number=\\"13\\" hits=\\"1\\" branch=\\"false\\"/>
<line number=\\"14\\" hits=\\"1\\" branch=\\"false\\"/>
<line number=\\"15\\" hits=\\"1\\" branch=\\"false\\"/>
</lines>
</class>
</packages>
</coverage>
"
`;
exports[`c8 merges reports from subprocesses together 1`] = `
",first
Expand Down Expand Up @@ -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
------------------------|---------|----------|---------|---------|-------------------
,"
`;
Expand All @@ -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
-----------------------|---------|----------|---------|---------|-------------------
,"
`;
Expand All @@ -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
-------------|---------|----------|---------|---------|-------------------
,"
`;
Expand All @@ -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
------------|---------|----------|---------|---------|-------------------
,"
`;
Expand Down Expand Up @@ -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
------------|---------|----------|---------|---------|-------------------
,"
`;
Expand Down Expand Up @@ -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
------------------|---------|----------|---------|---------|-------------------
,"
`;

0 comments on commit e93747b

Please sign in to comment.