Skip to content

Commit 21cd41f

Browse files
authored
fix(v8-to-istanbul): fixes shebang handling/ignore behavior (bcoe#267)
1 parent 225d431 commit 21cd41f

File tree

6 files changed

+82
-41
lines changed

6 files changed

+82
-41
lines changed

package-lock.json

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

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
"istanbul-reports": "^3.0.2",
4444
"rimraf": "^3.0.0",
4545
"test-exclude": "^6.0.0",
46-
"v8-to-istanbul": "^6.0.1",
46+
"v8-to-istanbul": "^7.0.0",
4747
"yargs": "^16.0.0",
4848
"yargs-parser": "^20.0.0"
4949
},

test/fixtures/shebang.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env node
2+
'use strict'
3+
4+
if (true) {
5+
console.info('hello world')
6+
} else {
7+
console.info('goodnight moon')
8+
}

test/integration.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,4 +561,15 @@ describe('c8', () => {
561561
output.toString('utf8').should.matchSnapshot()
562562
})
563563
})
564+
565+
it('collects coverage for script with shebang', () => {
566+
const { output } = spawnSync(nodePath, [
567+
c8Path,
568+
'--exclude="test/*.js"',
569+
'--temp-directory=tmp/shebang',
570+
'--clean=false',
571+
require.resolve('./fixtures/shebang')
572+
])
573+
output.toString('utf8').should.matchSnapshot()
574+
})
564575
})

test/integration.js.snap

Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ exports[`c8 /* c8 ignore next */ does not incorrectly mark previous branch as un
44
",--------------|---------|----------|---------|---------|-------------------
55
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
66
--------------|---------|----------|---------|---------|-------------------
7-
All files | 100 | 66.67 | 100 | 100 |
8-
issue-254.js | 100 | 66.67 | 100 | 100 | 2
7+
All files | 100 | 100 | 100 | 100 |
8+
issue-254.js | 100 | 100 | 100 | 100 |
99
--------------|---------|----------|---------|---------|-------------------
1010
,"
1111
`;
@@ -48,9 +48,9 @@ negative
4848
-----------------|---------|----------|---------|---------|-------------------
4949
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
5050
-----------------|---------|----------|---------|---------|-------------------
51-
All files | 64.29 | 66.67 | 50 | 64.29 |
52-
ts-compiled | 78.26 | 75 | 100 | 78.26 |
53-
loaded.ts | 73.68 | 71.43 | 100 | 73.68 | 4-5,16-18
51+
All files | 64.29 | 57.14 | 50 | 64.29 |
52+
ts-compiled | 78.26 | 66.67 | 100 | 78.26 |
53+
loaded.ts | 73.68 | 66.67 | 100 | 73.68 | 4-5,16-18
5454
main.ts | 100 | 100 | 100 | 100 |
5555
ts-compiled/dir | 0 | 0 | 0 | 0 |
5656
unloaded.ts | 0 | 0 | 0 | 0 | 1-5
@@ -65,9 +65,9 @@ negative
6565
--------------|---------|----------|---------|---------|-------------------
6666
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
6767
--------------|---------|----------|---------|---------|-------------------
68-
All files | 64.29 | 66.67 | 50 | 64.29 |
69-
ts-only | 78.26 | 75 | 100 | 78.26 |
70-
loaded.ts | 73.68 | 71.43 | 100 | 73.68 | 4-5,16-18
68+
All files | 64.29 | 57.14 | 50 | 64.29 |
69+
ts-only | 78.26 | 66.67 | 100 | 78.26 |
70+
loaded.ts | 73.68 | 66.67 | 100 | 73.68 | 4-5,16-18
7171
main.ts | 100 | 100 | 100 | 100 |
7272
ts-only/dir | 0 | 0 | 0 | 0 |
7373
unloaded.ts | 0 | 0 | 0 | 0 | 1-5
@@ -215,6 +215,17 @@ exports[`c8 cobertura report escapes special characters 1`] = `
215215
"
216216
`;
217217
218+
exports[`c8 collects coverage for script with shebang 1`] = `
219+
",hello world
220+
------------|---------|----------|---------|---------|-------------------
221+
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
222+
------------|---------|----------|---------|---------|-------------------
223+
All files | 75 | 50 | 100 | 75 |
224+
shebang.js | 75 | 50 | 100 | 75 | 7-8
225+
------------|---------|----------|---------|---------|-------------------
226+
,"
227+
`;
228+
218229
exports[`c8 merges reports from subprocesses together 1`] = `
219230
",first
220231
@@ -336,8 +347,8 @@ a = false
336347
------------------------|---------|----------|---------|---------|-------------------
337348
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
338349
------------------------|---------|----------|---------|---------|-------------------
339-
All files | 84 | 57.14 | 100 | 84 |
340-
branches.typescript.ts | 84 | 57.14 | 100 | 84 | 7,11-12,18
350+
All files | 84 | 50 | 100 | 84 |
351+
branches.typescript.ts | 84 | 50 | 100 | 84 | 7,11-12,18
341352
------------------------|---------|----------|---------|---------|-------------------
342353
,"
343354
`;
@@ -351,8 +362,8 @@ covered
351362
-----------------------|---------|----------|---------|---------|-------------------
352363
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
353364
-----------------------|---------|----------|---------|---------|-------------------
354-
All files | 81.82 | 87.5 | 60 | 81.82 |
355-
classes.typescript.ts | 81.82 | 87.5 | 60 | 81.82 | 12-13,21-22,27-28
365+
All files | 81.82 | 85.71 | 60 | 81.82 |
366+
classes.typescript.ts | 81.82 | 85.71 | 60 | 81.82 | 12-13,21-22,27-28
356367
-----------------------|---------|----------|---------|---------|-------------------
357368
,"
358369
`;
@@ -364,8 +375,8 @@ a = false
364375
-------------|---------|----------|---------|---------|-------------------
365376
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
366377
-------------|---------|----------|---------|---------|-------------------
367-
All files | 80 | 50 | 100 | 80 |
368-
branches.js | 80 | 50 | 100 | 80 | 2,5-6,13
378+
All files | 80 | 40 | 100 | 80 |
379+
branches.js | 80 | 40 | 100 | 80 | 2,5-6,13
369380
-------------|---------|----------|---------|---------|-------------------
370381
,"
371382
`;
@@ -379,8 +390,8 @@ covered
379390
------------|---------|----------|---------|---------|-------------------
380391
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
381392
------------|---------|----------|---------|---------|-------------------
382-
All files | 85.19 | 83.33 | 60 | 85.19 |
383-
classes.js | 85.19 | 83.33 | 60 | 85.19 | 6-7,15,21
393+
All files | 85.19 | 80 | 60 | 85.19 |
394+
classes.js | 85.19 | 80 | 60 | 85.19 | 6-7,15,21
384395
------------|---------|----------|---------|---------|-------------------
385396
,"
386397
`;
@@ -402,8 +413,8 @@ a = false
402413
-------------|---------|----------|---------|---------|-------------------
403414
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
404415
-------------|---------|----------|---------|---------|-------------------
405-
All files | 80 | 55.56 | 100 | 80 |
406-
branches.js | 80 | 55.56 | 100 | 80 | 2,6-7,13
416+
All files | 80 | 40 | 100 | 80 |
417+
branches.js | 80 | 40 | 100 | 80 | 2,6-7,13
407418
-------------|---------|----------|---------|---------|-------------------
408419
,"
409420
`;
@@ -417,8 +428,8 @@ covered
417428
------------|---------|----------|---------|---------|-------------------
418429
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
419430
------------|---------|----------|---------|---------|-------------------
420-
All files | 77.78 | 80 | 71.43 | 77.78 |
421-
classes.js | 77.78 | 80 | 71.43 | 77.78 | 7-8,15-16,21-22
431+
All files | 77.78 | 83.33 | 60 | 77.78 |
432+
classes.js | 77.78 | 83.33 | 60 | 77.78 | 7-8,15-16,21-22
422433
------------|---------|----------|---------|---------|-------------------
423434
,"
424435
`;
@@ -446,9 +457,9 @@ covered
446457
------------|---------|----------|---------|---------|-------------------
447458
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
448459
------------|---------|----------|---------|---------|-------------------
449-
All files | 78.57 | 85.71 | 60 | 78.57 |
460+
All files | 78.57 | 83.33 | 60 | 78.57 |
450461
class-1.js | 100 | 100 | 100 | 100 |
451-
class-2.js | 73.91 | 85.71 | 60 | 73.91 | 7-8,15-16,21-22
462+
class-2.js | 73.91 | 83.33 | 60 | 73.91 | 7-8,15-16,21-22
452463
------------|---------|----------|---------|---------|-------------------
453464
,"
454465
`;
@@ -462,8 +473,8 @@ covered
462473
------------------|---------|----------|---------|---------|-------------------
463474
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
464475
------------------|---------|----------|---------|---------|-------------------
465-
All files | 88.24 | 87.5 | 80 | 88.24 |
466-
ts-node-basic.ts | 88.24 | 87.5 | 80 | 88.24 | 12-13,28-29
476+
All files | 88.24 | 85.71 | 80 | 88.24 |
477+
ts-node-basic.ts | 88.24 | 85.71 | 80 | 88.24 | 12-13,28-29
467478
------------------|---------|----------|---------|---------|-------------------
468479
,"
469480
`;

test/integration.js_10.snap

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ exports[`c8 /* c8 ignore next */ does not incorrectly mark previous branch as un
44
",--------------|---------|----------|---------|---------|-------------------
55
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
66
--------------|---------|----------|---------|---------|-------------------
7-
All files | 100 | 66.67 | 100 | 100 |
8-
issue-254.js | 100 | 66.67 | 100 | 100 | 2
7+
All files | 100 | 100 | 100 | 100 |
8+
issue-254.js | 100 | 100 | 100 | 100 |
99
--------------|---------|----------|---------|---------|-------------------
1010
,"
1111
`;
@@ -59,9 +59,9 @@ negative
5959
-----------------|---------|----------|---------|---------|-------------------
6060
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
6161
-----------------|---------|----------|---------|---------|-------------------
62-
All files | 64.29 | 66.67 | 50 | 64.29 |
63-
ts-compiled | 78.26 | 75 | 100 | 78.26 |
64-
loaded.ts | 73.68 | 71.43 | 100 | 73.68 | 4-5,16-18
62+
All files | 64.29 | 57.14 | 50 | 64.29 |
63+
ts-compiled | 78.26 | 66.67 | 100 | 78.26 |
64+
loaded.ts | 73.68 | 66.67 | 100 | 73.68 | 4-5,16-18
6565
main.ts | 100 | 100 | 100 | 100 |
6666
ts-compiled/dir | 0 | 0 | 0 | 0 |
6767
unloaded.ts | 0 | 0 | 0 | 0 | 1-5
@@ -245,6 +245,17 @@ exports[`c8 cobertura report escapes special characters 1`] = `
245245
"
246246
`;
247247
248+
exports[`c8 collects coverage for script with shebang 1`] = `
249+
",hello world
250+
------------|---------|----------|---------|---------|-------------------
251+
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
252+
------------|---------|----------|---------|---------|-------------------
253+
All files | 75 | 50 | 100 | 75 |
254+
shebang.js | 75 | 50 | 100 | 75 | 7-8
255+
------------|---------|----------|---------|---------|-------------------
256+
,"
257+
`;
258+
248259
exports[`c8 merges reports from subprocesses together 1`] = `
249260
",first
250261
@@ -404,8 +415,8 @@ covered
404415
-----------------------|---------|----------|---------|---------|-------------------
405416
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
406417
-----------------------|---------|----------|---------|---------|-------------------
407-
All files | 81.82 | 87.5 | 60 | 81.82 |
408-
classes.typescript.ts | 81.82 | 87.5 | 60 | 81.82 | 12-13,21-22,27-28
418+
All files | 81.82 | 85.71 | 60 | 81.82 |
419+
classes.typescript.ts | 81.82 | 85.71 | 60 | 81.82 | 12-13,21-22,27-28
409420
-----------------------|---------|----------|---------|---------|-------------------
410421
,"
411422
`;
@@ -455,8 +466,8 @@ a = false
455466
-------------|---------|----------|---------|---------|-------------------
456467
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
457468
-------------|---------|----------|---------|---------|-------------------
458-
All files | 80 | 55.56 | 100 | 80 |
459-
branches.js | 80 | 55.56 | 100 | 80 | 2,6-7,13
469+
All files | 80 | 40 | 100 | 80 |
470+
branches.js | 80 | 40 | 100 | 80 | 2,6-7,13
460471
-------------|---------|----------|---------|---------|-------------------
461472
,"
462473
`;
@@ -470,8 +481,8 @@ covered
470481
------------|---------|----------|---------|---------|-------------------
471482
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
472483
------------|---------|----------|---------|---------|-------------------
473-
All files | 77.78 | 80 | 71.43 | 77.78 |
474-
classes.js | 77.78 | 80 | 71.43 | 77.78 | 7-8,15-16,21-22
484+
All files | 77.78 | 83.33 | 60 | 77.78 |
485+
classes.js | 77.78 | 83.33 | 60 | 77.78 | 7-8,15-16,21-22
475486
------------|---------|----------|---------|---------|-------------------
476487
,"
477488
`;
@@ -499,9 +510,9 @@ covered
499510
------------|---------|----------|---------|---------|-------------------
500511
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
501512
------------|---------|----------|---------|---------|-------------------
502-
All files | 78.57 | 85.71 | 60 | 78.57 |
513+
All files | 78.57 | 83.33 | 60 | 78.57 |
503514
class-1.js | 100 | 100 | 100 | 100 |
504-
class-2.js | 73.91 | 85.71 | 60 | 73.91 | 7-8,15-16,21-22
515+
class-2.js | 73.91 | 83.33 | 60 | 73.91 | 7-8,15-16,21-22
505516
------------|---------|----------|---------|---------|-------------------
506517
,"
507518
`;

0 commit comments

Comments
 (0)