@@ -97,7 +97,11 @@ test('test coverage report', async (t) => {
9797test ( 'test tap coverage reporter' , skipIfNoInspector , async ( t ) => {
9898 await t . test ( 'coverage is reported and dumped to NODE_V8_COVERAGE if present' , ( t ) => {
9999 const fixture = fixtures . path ( 'test-runner' , 'coverage.js' ) ;
100- const args = [ '--experimental-test-coverage' , '--test-reporter' , 'tap' , fixture ] ;
100+ const args = [
101+ '--experimental-test-coverage' ,
102+ '--no-warnings' , '--test-coverage-include=**' ,
103+ '--test-reporter' , 'tap' , fixture ,
104+ ] ;
101105 const options = { env : { ...process . env , NODE_V8_COVERAGE : tmpdir . path } } ;
102106 const result = spawnSync ( process . execPath , args , options ) ;
103107 const report = getTapCoverageFixtureReport ( ) ;
@@ -109,7 +113,11 @@ test('test tap coverage reporter', skipIfNoInspector, async (t) => {
109113
110114 await t . test ( 'coverage is reported without NODE_V8_COVERAGE present' , ( t ) => {
111115 const fixture = fixtures . path ( 'test-runner' , 'coverage.js' ) ;
112- const args = [ '--experimental-test-coverage' , '--test-reporter' , 'tap' , fixture ] ;
116+ const args = [
117+ '--experimental-test-coverage' ,
118+ '--no-warnings' , '--test-coverage-include=**' ,
119+ '--test-reporter' , 'tap' , fixture ,
120+ ] ;
113121 const result = spawnSync ( process . execPath , args ) ;
114122 const report = getTapCoverageFixtureReport ( ) ;
115123
@@ -123,7 +131,11 @@ test('test tap coverage reporter', skipIfNoInspector, async (t) => {
123131test ( 'test spec coverage reporter' , skipIfNoInspector , async ( t ) => {
124132 await t . test ( 'coverage is reported and dumped to NODE_V8_COVERAGE if present' , ( t ) => {
125133 const fixture = fixtures . path ( 'test-runner' , 'coverage.js' ) ;
126- const args = [ '--experimental-test-coverage' , '--test-reporter' , 'spec' , fixture ] ;
134+ const args = [
135+ '--experimental-test-coverage' ,
136+ '--no-warnings' , '--test-coverage-include=**' ,
137+ '--test-reporter' , 'spec' , fixture ,
138+ ] ;
127139 const options = { env : { ...process . env , NODE_V8_COVERAGE : tmpdir . path } } ;
128140 const result = spawnSync ( process . execPath , args , options ) ;
129141 const report = getSpecCoverageFixtureReport ( ) ;
@@ -136,7 +148,11 @@ test('test spec coverage reporter', skipIfNoInspector, async (t) => {
136148
137149 await t . test ( 'coverage is reported without NODE_V8_COVERAGE present' , ( t ) => {
138150 const fixture = fixtures . path ( 'test-runner' , 'coverage.js' ) ;
139- const args = [ '--experimental-test-coverage' , '--test-reporter' , 'spec' , fixture ] ;
151+ const args = [
152+ '--experimental-test-coverage' ,
153+ '--no-warnings' , '--test-coverage-include=**' ,
154+ '--test-reporter' , 'spec' , fixture ,
155+ ] ;
140156 const result = spawnSync ( process . execPath , args ) ;
141157 const report = getSpecCoverageFixtureReport ( ) ;
142158
@@ -150,7 +166,9 @@ test('test spec coverage reporter', skipIfNoInspector, async (t) => {
150166test ( 'single process coverage is the same with --test' , skipIfNoInspector , ( ) => {
151167 const fixture = fixtures . path ( 'test-runner' , 'coverage.js' ) ;
152168 const args = [
153- '--test' , '--experimental-test-coverage' , '--test-reporter' , 'tap' , fixture ,
169+ '--test' , '--experimental-test-coverage' ,
170+ '--no-warnings' , '--test-coverage-include=**' ,
171+ '--test-reporter' , 'tap' , fixture ,
154172 ] ;
155173 const result = spawnSync ( process . execPath , args ) ;
156174 const report = getTapCoverageFixtureReport ( ) ;
@@ -183,7 +201,7 @@ test('coverage is combined for multiple processes', skipIfNoInspector, () => {
183201
184202 const fixture = fixtures . path ( 'v8-coverage' , 'combined_coverage' ) ;
185203 const args = [
186- '--test' , '--experimental-test-coverage' , '--test-reporter' , 'tap' ,
204+ '--test' , '--experimental-test-coverage' , '--no-warnings' , '--test-coverage-include=**' , '-- test-reporter', 'tap' ,
187205 ] ;
188206 const result = spawnSync ( process . execPath , args , {
189207 env : { ...process . env , NODE_TEST_TMPDIR : tmpdir . path } ,
@@ -236,7 +254,8 @@ test.skip('coverage works with isolation=none', skipIfNoInspector, () => {
236254test ( 'coverage reports on lines, functions, and branches' , skipIfNoInspector , async ( t ) => {
237255 const fixture = fixtures . path ( 'test-runner' , 'coverage.js' ) ;
238256 const child = spawnSync ( process . execPath ,
239- [ '--test' , '--experimental-test-coverage' , '--test-reporter' ,
257+ [ '--test' , '--experimental-test-coverage' ,
258+ '--no-warnings' , '--test-coverage-include=**' , '--test-reporter' ,
240259 fixtures . fileURL ( 'test-runner/custom_reporters/coverage.mjs' ) ,
241260 fixture ] ) ;
242261 assert . strictEqual ( child . stderr . toString ( ) , '' ) ;
@@ -297,7 +316,6 @@ test('coverage with ESM hook - source irrelevant', skipIfNoInspector, () => {
297316 '# ------------------------------------------------------------------' ,
298317 '# hooks.mjs | 100.00 | 100.00 | 100.00 | ' ,
299318 '# register-hooks.js | 100.00 | 100.00 | 100.00 | ' ,
300- '# virtual.js | 100.00 | 100.00 | 100.00 | ' ,
301319 '# ------------------------------------------------------------------' ,
302320 '# all files | 100.00 | 100.00 | 100.00 | ' ,
303321 '# ------------------------------------------------------------------' ,
@@ -327,7 +345,6 @@ test('coverage with ESM hook - source transpiled', skipIfNoInspector, () => {
327345 '# ------------------------------------------------------------------' ,
328346 '# hooks.mjs | 100.00 | 100.00 | 100.00 | ' ,
329347 '# register-hooks.js | 100.00 | 100.00 | 100.00 | ' ,
330- '# sum.test.ts | 100.00 | 100.00 | 100.00 | ' ,
331348 '# sum.ts | 100.00 | 100.00 | 100.00 | ' ,
332349 '# ------------------------------------------------------------------' ,
333350 '# all files | 100.00 | 100.00 | 100.00 | ' ,
@@ -384,7 +401,38 @@ test('coverage with excluded files', skipIfNoInspector, () => {
384401 assert . strictEqual ( result . status , 0 ) ;
385402 assert ( ! findCoverageFileForPid ( result . pid ) ) ;
386403} ) ;
404+ test ( 'coverage should not include test files by default' , skipIfNoInspector , ( ) => {
405+ const fixture = fixtures . path ( 'test-runner' , 'coverage.js' ) ;
406+ const args = [
407+ '--experimental-test-coverage' , '--test-reporter' , 'tap' ,
408+ fixture ,
409+ ] ;
410+ const result = spawnSync ( process . execPath , args ) ;
411+ const report = [
412+ '# start of coverage report' ,
413+ '# ---------------------------------------------------------------' ,
414+ '# file | line % | branch % | funcs % | uncovered lines' ,
415+ '# ---------------------------------------------------------------' ,
416+ '# test | | | | ' ,
417+ '# fixtures | | | | ' ,
418+ '# test-runner | | | | ' ,
419+ '# v8-coverage | | | | ' ,
420+ '# throw.js | 71.43 | 50.00 | 100.00 | 5-6' ,
421+ '# ---------------------------------------------------------------' ,
422+ '# all files | 78.13 | 40.00 | 60.00 | ' ,
423+ '# ---------------------------------------------------------------' ,
424+ '# end of coverage report' ,
425+ ] . join ( '\n' ) ;
387426
427+
428+ if ( common . isWindows ) {
429+ return report . replaceAll ( '/' , '\\' ) ;
430+ }
431+
432+ assert ( result . stdout . toString ( ) . includes ( report ) ) ;
433+ assert . strictEqual ( result . status , 0 ) ;
434+ assert ( ! findCoverageFileForPid ( result . pid ) ) ;
435+ } ) ;
388436test ( 'coverage with included files' , skipIfNoInspector , ( ) => {
389437 const fixture = fixtures . path ( 'test-runner' , 'coverage.js' ) ;
390438 const args = [
@@ -458,18 +506,17 @@ test('coverage with included and excluded files', skipIfNoInspector, () => {
458506test ( 'correctly prints the coverage report of files contained in parent directories' , skipIfNoInspector , ( ) => {
459507 let report = [
460508 '# start of coverage report' ,
461- '# -------------------------------------------------------------------------------------------- ' ,
509+ '# ------------------------------------------------------------------' ,
462510 '# file | line % | branch % | funcs % | uncovered lines' ,
463- '# -------------------------------------------------------------------------------------------- ' ,
511+ '# ------------------------------------------------------------------' ,
464512 '# .. | | | | ' ,
465- '# coverage.js | 78.65 | 38.46 | 60.00 | 12-13 16-22 27 39 43-44 61-62 66-67 71-72' ,
466513 '# invalid-tap.js | 100.00 | 100.00 | 100.00 | ' ,
467514 '# .. | | | | ' ,
468515 '# v8-coverage | | | | ' ,
469516 '# throw.js | 71.43 | 50.00 | 100.00 | 5-6' ,
470- '# -------------------------------------------------------------------------------------------- ' ,
471- '# all files | 78.35 | 43.75 | 60 .00 | ' ,
472- '# -------------------------------------------------------------------------------------------- ' ,
517+ '# ------------------------------------------------------------------' ,
518+ '# all files | 75.00 | 66.67 | 100 .00 | ' ,
519+ '# ------------------------------------------------------------------' ,
473520 '# end of coverage report' ,
474521 ] . join ( '\n' ) ;
475522
0 commit comments