@@ -335,3 +335,96 @@ test('coverage with ESM hook - source transpiled', skipIfNoInspector, () => {
335335 assert ( result . stdout . toString ( ) . includes ( report ) ) ;
336336 assert . strictEqual ( result . status , 0 ) ;
337337} ) ;
338+
339+ test ( 'coverage with excluded files' , skipIfNoInspector , ( ) => {
340+ const fixture = fixtures . path ( 'test-runner' , 'coverage.js' ) ;
341+ const args = [
342+ '--experimental-test-coverage' , '--test-reporter' , 'tap' ,
343+ '--test-coverage-exclude=test/*/test-runner/invalid-tap.js' ,
344+ fixture ] ;
345+ const result = spawnSync ( process . execPath , args ) ;
346+ const report = [
347+ '# start of coverage report' ,
348+ '# ' + '-' . repeat ( 112 ) ,
349+ '# file | line % | branch % | funcs % | uncovered lines' ,
350+ '# ' + '-' . repeat ( 112 ) ,
351+ '# test/fixtures/test-runner/coverage.js | 78.65 | 38.46 | 60.00 | 12-13 16-22 27 39 43-44 61-62 66-67 71-72' ,
352+ '# test/fixtures/v8-coverage/throw.js | 71.43 | 50.00 | 100.00 | 5-6' ,
353+ '# ' + '-' . repeat ( 112 ) ,
354+ '# all files | 78.13 | 40.00 | 60.00 |' ,
355+ '# ' + '-' . repeat ( 112 ) ,
356+ '# end of coverage report' ,
357+ ] . join ( '\n' ) ;
358+
359+
360+ if ( common . isWindows ) {
361+ return report . replaceAll ( '/' , '\\' ) ;
362+ }
363+
364+ assert ( result . stdout . toString ( ) . includes ( report ) ) ;
365+ assert . strictEqual ( result . status , 0 ) ;
366+ assert ( ! findCoverageFileForPid ( result . pid ) ) ;
367+ } ) ;
368+
369+ test ( 'coverage with included files' , skipIfNoInspector , ( ) => {
370+ const fixture = fixtures . path ( 'test-runner' , 'coverage.js' ) ;
371+ const args = [
372+ '--experimental-test-coverage' , '--test-reporter' , 'tap' ,
373+ '--test-coverage-include=test/fixtures/test-runner/coverage.js' ,
374+ '--test-coverage-include=test/fixtures/v8-coverage/throw.js' ,
375+ fixture ,
376+ ] ;
377+ const result = spawnSync ( process . execPath , args ) ;
378+ const report = [
379+ '# start of coverage report' ,
380+ '# ' + '-' . repeat ( 112 ) ,
381+ '# file | line % | branch % | funcs % | uncovered lines' ,
382+ '# ' + '-' . repeat ( 112 ) ,
383+ '# test/fixtures/test-runner/coverage.js | 78.65 | 38.46 | 60.00 | 12-13 16-22 27 39 43-44 61-62 66-67 71-72' ,
384+ '# test/fixtures/v8-coverage/throw.js | 71.43 | 50.00 | 100.00 | 5-6' ,
385+ '# ' + '-' . repeat ( 112 ) ,
386+ '# all files | 78.13 | 40.00 | 60.00 |' ,
387+ '# ' + '-' . repeat ( 112 ) ,
388+ '# end of coverage report' ,
389+ ] . join ( '\n' ) ;
390+
391+
392+ if ( common . isWindows ) {
393+ return report . replaceAll ( '/' , '\\' ) ;
394+ }
395+
396+ assert ( result . stdout . toString ( ) . includes ( report ) ) ;
397+ assert . strictEqual ( result . status , 0 ) ;
398+ assert ( ! findCoverageFileForPid ( result . pid ) ) ;
399+ } ) ;
400+
401+ test ( 'coverage with included and excluded files' , skipIfNoInspector , ( ) => {
402+ const fixture = fixtures . path ( 'test-runner' , 'coverage.js' ) ;
403+ const args = [
404+ '--experimental-test-coverage' , '--test-reporter' , 'tap' ,
405+ '--test-coverage-include=test/fixtures/test-runner/*.js' ,
406+ '--test-coverage-exclude=test/fixtures/test-runner/*-tap.js' ,
407+ fixture ,
408+ ] ;
409+ const result = spawnSync ( process . execPath , args ) ;
410+ const report = [
411+ '# start of coverage report' ,
412+ '# ' + '-' . repeat ( 112 ) ,
413+ '# file | line % | branch % | funcs % | uncovered lines' ,
414+ '# ' + '-' . repeat ( 112 ) ,
415+ '# test/fixtures/test-runner/coverage.js | 78.65 | 38.46 | 60.00 | 12-13 16-22 27 39 43-44 61-62 66-67 71-72' ,
416+ '# ' + '-' . repeat ( 112 ) ,
417+ '# all files | 78.65 | 38.46 | 60.00 |' ,
418+ '# ' + '-' . repeat ( 112 ) ,
419+ '# end of coverage report' ,
420+ ] . join ( '\n' ) ;
421+
422+
423+ if ( common . isWindows ) {
424+ return report . replaceAll ( '/' , '\\' ) ;
425+ }
426+
427+ assert ( result . stdout . toString ( ) . includes ( report ) ) ;
428+ assert . strictEqual ( result . status , 0 ) ;
429+ assert ( ! findCoverageFileForPid ( result . pid ) ) ;
430+ } ) ;
0 commit comments