Skip to content

Commit e93747b

Browse files
authored
fix: escaping issue with cobertura reporter (bcoe#203)
1 parent 6410016 commit e93747b

File tree

5 files changed

+102
-19
lines changed

5 files changed

+102
-19
lines changed

package-lock.json

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"scripts": {
1313
"test": "node ./bin/c8.js --reporter=html --reporter=text mocha --timeout=8000 ./test/*.js",
1414
"test:snap": "CHAI_JEST_SNAPSHOT_UPDATE_ALL=true npm test",
15+
"fix": "standard --fix",
1516
"posttest": "standard",
1617
"coverage": "./bin/c8.js report --reporter=html --reporter=text-lcov | coveralls"
1718
},
@@ -39,7 +40,7 @@
3940
"furi": "^2.0.0",
4041
"istanbul-lib-coverage": "^3.0.0",
4142
"istanbul-lib-report": "^3.0.0",
42-
"istanbul-reports": "^3.0.0",
43+
"istanbul-reports": "^3.0.2",
4344
"rimraf": "^3.0.0",
4445
"test-exclude": "^6.0.0",
4546
"v8-to-istanbul": "^4.1.2",

test/fixtures/computed-method.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Test {
2+
constructor() {
3+
this.map = {};
4+
}
5+
6+
run(i) {
7+
this.map[i] = {};
8+
this.map[i].f = () => console.log("FUNC RUN");
9+
console.log("TEST RUN");
10+
}
11+
}
12+
13+
let t = new Test();
14+
t.run(20);
15+
t.map[20].f();

test/integration.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
/* global describe, before, beforeEach, it */
22

3+
const { readFileSync } = require('fs')
4+
const { resolve } = require('path')
35
const { spawnSync } = require('child_process')
46
const { statSync } = require('fs')
57
const c8Path = require.resolve('../bin/c8')
@@ -416,4 +418,20 @@ describe('c8', () => {
416418
output.toString('utf8').should.matchSnapshot()
417419
})
418420
})
421+
422+
// see: https://github.com/bcoe/c8/issues/149
423+
it('cobertura report escapes special characters', () => {
424+
spawnSync(nodePath, [
425+
c8Path,
426+
'--exclude="test/*.js"',
427+
'--temp-directory=tmp/cobertura',
428+
'--clean=false',
429+
'--reporter=cobertura',
430+
nodePath,
431+
require.resolve('./fixtures/computed-method')
432+
])
433+
const cobertura = readFileSync(resolve(process.cwd(), './coverage/cobertura-coverage.xml'), 'utf8')
434+
.replace(/[0-9]{13,}/, 'nnnn')
435+
cobertura.toString('utf8').should.matchSnapshot()
436+
})
419437
})

test/integration.js.snap

Lines changed: 61 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
88
-------------------|---------|----------|---------|---------|-------------------
99
All files | 86.21 | 91.67 | 66.67 | 86.21 |
1010
async.js | 100 | 100 | 100 | 100 |
11-
c8-ignore-next.js | 90.91 | 100 | 100 | 90.91 | 21,22
11+
c8-ignore-next.js | 90.91 | 100 | 100 | 90.91 | 21-22
1212
normal.js | 75 | 66.67 | 33.33 | 75 | 14-16,18-20
1313
-------------------|---------|----------|---------|---------|-------------------
1414
,"
@@ -23,7 +23,7 @@ File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
2323
--------------|---------|----------|---------|---------|-------------------
2424
All files | 64.29 | 66.67 | 50 | 64.29 |
2525
vanilla | 78.26 | 75 | 100 | 78.26 |
26-
loaded.js | 73.68 | 71.43 | 100 | 73.68 | 4,5,16-18
26+
loaded.js | 73.68 | 71.43 | 100 | 73.68 | 4-5,16-18
2727
main.js | 100 | 100 | 100 | 100 |
2828
vanilla/dir | 0 | 0 | 0 | 0 |
2929
unloaded.js | 0 | 0 | 0 | 0 | 1-5
@@ -40,7 +40,7 @@ File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
4040
-----------------|---------|----------|---------|---------|-------------------
4141
All files | 64.29 | 66.67 | 50 | 64.29 |
4242
ts-compiled | 78.26 | 75 | 100 | 78.26 |
43-
loaded.ts | 73.68 | 71.43 | 100 | 73.68 | 4,5,16-18
43+
loaded.ts | 73.68 | 71.43 | 100 | 73.68 | 4-5,16-18
4444
main.ts | 100 | 100 | 100 | 100 |
4545
ts-compiled/dir | 0 | 0 | 0 | 0 |
4646
unloaded.ts | 0 | 0 | 0 | 0 | 1-5
@@ -57,7 +57,7 @@ File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
5757
--------------|---------|----------|---------|---------|-------------------
5858
All files | 64.29 | 66.67 | 50 | 64.29 |
5959
ts-only | 78.26 | 75 | 100 | 78.26 |
60-
loaded.ts | 73.68 | 71.43 | 100 | 73.68 | 4,5,16-18
60+
loaded.ts | 73.68 | 71.43 | 100 | 73.68 | 4-5,16-18
6161
main.ts | 100 | 100 | 100 | 100 |
6262
ts-only/dir | 0 | 0 | 0 | 0 |
6363
unloaded.ts | 0 | 0 | 0 | 0 | 1-5
@@ -74,7 +74,7 @@ File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
7474
--------------|---------|----------|---------|---------|-------------------
7575
All files | 64.29 | 66.67 | 50 | 64.29 |
7676
vanilla | 78.26 | 75 | 100 | 78.26 |
77-
loaded.js | 73.68 | 71.43 | 100 | 73.68 | 4,5,16-18
77+
loaded.js | 73.68 | 71.43 | 100 | 73.68 | 4-5,16-18
7878
main.js | 100 | 100 | 100 | 100 |
7979
vanilla/dir | 0 | 0 | 0 | 0 |
8080
unloaded.js | 0 | 0 | 0 | 0 | 1-5
@@ -95,7 +95,7 @@ File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
9595
------------|---------|----------|---------|---------|-------------------
9696
All files | 83.33 | 100 | 66.67 | 83.33 |
9797
export.cjs | 100 | 100 | 100 | 100 |
98-
export.mjs | 71.43 | 100 | 50 | 71.43 | 2,3
98+
export.mjs | 71.43 | 100 | 50 | 71.43 | 2-3
9999
import.mjs | 100 | 100 | 100 | 100 |
100100
------------|---------|----------|---------|---------|-------------------
101101
,"
@@ -134,6 +134,55 @@ exports[`c8 check-coverage exits with 1 if coverage is below threshold 1`] = `
134134
"
135135
`;
136136

137+
exports[`c8 cobertura report escapes special characters 1`] = `
138+
"<?xml version=\\"1.0\\" ?>
139+
<!DOCTYPE coverage SYSTEM \\"http://cobertura.sourceforge.net/xml/coverage-04.dtd\\">
140+
<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\\">
141+
<sources>
142+
<source>/Users/bencoe/oss/c8</source>
143+
</sources>
144+
<packages>
145+
<class name=\\"computed-method.js\\" filename=\\"test/fixtures/computed-method.js\\" line-rate=\\"1\\" branch-rate=\\"1\\">
146+
<methods>
147+
<method name=\\"Test\\" hits=\\"1\\" signature=\\"()V\\">
148+
<lines>
149+
<line number=\\"2\\" hits=\\"1\\"/>
150+
</lines>
151+
</method>
152+
<method name=\\"run\\" hits=\\"1\\" signature=\\"()V\\">
153+
<lines>
154+
<line number=\\"6\\" hits=\\"1\\"/>
155+
</lines>
156+
</method>
157+
<method name=\\"map.&lt;computed&gt;.f\\" hits=\\"1\\" signature=\\"()V\\">
158+
<lines>
159+
<line number=\\"8\\" hits=\\"1\\"/>
160+
</lines>
161+
</method>
162+
</methods>
163+
<lines>
164+
<line number=\\"1\\" hits=\\"1\\" branch=\\"true\\" condition-coverage=\\"100% (1/1)\\"/>
165+
<line number=\\"2\\" hits=\\"1\\" branch=\\"true\\" condition-coverage=\\"100% (1/1)\\"/>
166+
<line number=\\"3\\" hits=\\"1\\" branch=\\"false\\"/>
167+
<line number=\\"4\\" hits=\\"1\\" branch=\\"false\\"/>
168+
<line number=\\"5\\" hits=\\"1\\" branch=\\"false\\"/>
169+
<line number=\\"6\\" hits=\\"1\\" branch=\\"true\\" condition-coverage=\\"100% (1/1)\\"/>
170+
<line number=\\"7\\" hits=\\"1\\" branch=\\"false\\"/>
171+
<line number=\\"8\\" hits=\\"1\\" branch=\\"true\\" condition-coverage=\\"100% (1/1)\\"/>
172+
<line number=\\"9\\" hits=\\"1\\" branch=\\"false\\"/>
173+
<line number=\\"10\\" hits=\\"1\\" branch=\\"false\\"/>
174+
<line number=\\"11\\" hits=\\"1\\" branch=\\"false\\"/>
175+
<line number=\\"12\\" hits=\\"1\\" branch=\\"false\\"/>
176+
<line number=\\"13\\" hits=\\"1\\" branch=\\"false\\"/>
177+
<line number=\\"14\\" hits=\\"1\\" branch=\\"false\\"/>
178+
<line number=\\"15\\" hits=\\"1\\" branch=\\"false\\"/>
179+
</lines>
180+
</class>
181+
</packages>
182+
</coverage>
183+
"
184+
`;
185+
137186
exports[`c8 merges reports from subprocesses together 1`] = `
138187
",first
139188
@@ -199,7 +248,7 @@ a = false
199248
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
200249
------------------------|---------|----------|---------|---------|-------------------
201250
All files | 84 | 57.14 | 100 | 84 |
202-
branches.typescript.ts | 84 | 57.14 | 100 | 84 | 7,11,12,18
251+
branches.typescript.ts | 84 | 57.14 | 100 | 84 | 7,11-12,18
203252
------------------------|---------|----------|---------|---------|-------------------
204253
,"
205254
`;
@@ -214,7 +263,7 @@ covered
214263
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
215264
-----------------------|---------|----------|---------|---------|-------------------
216265
All files | 81.82 | 87.5 | 60 | 81.82 |
217-
classes.typescript.ts | 81.82 | 87.5 | 60 | 81.82 | 12,13,21,22,27,28
266+
classes.typescript.ts | 81.82 | 87.5 | 60 | 81.82 | 12-13,21-22,27-28
218267
-----------------------|---------|----------|---------|---------|-------------------
219268
,"
220269
`;
@@ -227,7 +276,7 @@ a = false
227276
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
228277
-------------|---------|----------|---------|---------|-------------------
229278
All files | 80 | 50 | 100 | 80 |
230-
branches.js | 80 | 50 | 100 | 80 | 2,5,6,13
279+
branches.js | 80 | 50 | 100 | 80 | 2,5-6,13
231280
-------------|---------|----------|---------|---------|-------------------
232281
,"
233282
`;
@@ -242,7 +291,7 @@ covered
242291
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
243292
------------|---------|----------|---------|---------|-------------------
244293
All files | 85.19 | 83.33 | 60 | 85.19 |
245-
classes.js | 85.19 | 83.33 | 60 | 85.19 | 6,7,15,21
294+
classes.js | 85.19 | 83.33 | 60 | 85.19 | 6-7,15,21
246295
------------|---------|----------|---------|---------|-------------------
247296
,"
248297
`;
@@ -270,7 +319,7 @@ covered
270319
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
271320
------------|---------|----------|---------|---------|-------------------
272321
All files | 70.37 | 66.67 | 60 | 70.37 |
273-
classes.js | 70.37 | 66.67 | 60 | 70.37 | 5-8,15,16,21,22
322+
classes.js | 70.37 | 66.67 | 60 | 70.37 | 5-8,15-16,21-22
274323
------------|---------|----------|---------|---------|-------------------
275324
,"
276325
`;
@@ -304,7 +353,7 @@ covered
304353
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
305354
------------------|---------|----------|---------|---------|-------------------
306355
All files | 88.24 | 87.5 | 80 | 88.24 |
307-
ts-node-basic.ts | 88.24 | 87.5 | 80 | 88.24 | 12,13,28,29
356+
ts-node-basic.ts | 88.24 | 87.5 | 80 | 88.24 | 12-13,28-29
308357
------------------|---------|----------|---------|---------|-------------------
309358
,"
310359
`;

0 commit comments

Comments
 (0)