@@ -2,6 +2,8 @@ import * as common from '../common/index.mjs';
22import  *  as  tmpdir  from  '../common/tmpdir.js' ; 
33import  *  as  fixtures  from  '../common/fixtures.mjs' ; 
44import  assert  from  'node:assert' ; 
5+ import  path  from  'node:path' ; 
6+ import  fs  from  'node:fs/promises' ; 
57import  {  NodeInstance  }  from  '../common/inspector-helper.js' ; 
68
79
@@ -52,3 +54,31 @@ tmpdir.refresh();
5254  assert . strictEqual ( code ,  1 ) ; 
5355  assert . strictEqual ( signal ,  null ) ; 
5456} 
57+ 
58+ 
59+ // Outputs coverage when event loop is drained, with no async logic. 
60+ { 
61+   const  coverageDirectory  =  path . join ( tmpdir . path ,  'coverage' ) ; 
62+   async  function  getCoveredFiles ( )  { 
63+     const  coverageFiles  =  await  fs . readdir ( coverageDirectory ) ; 
64+     const  files  =  new  Set ( ) ; 
65+     for  ( const  coverageFile  of  coverageFiles )  { 
66+       const  coverage  =  JSON . parse ( await  fs . readFile ( path . join ( coverageDirectory ,  coverageFile ) ) ) ; 
67+       for  ( const  {  url }  of  coverage . result )  { 
68+         if  ( ! url . startsWith ( 'node:' ) )  files . add ( url ) ; 
69+       } 
70+     } 
71+     return  files ; 
72+   } 
73+ 
74+   const  {  stderr,  code,  signal }  =  await  common 
75+           . spawnPromisified ( process . execPath , 
76+                             [ '--test' ,  fixtures . path ( 'v8-coverage/basic.js' ) ] , 
77+                             {  env : {  ...process . env ,  NODE_V8_COVERAGE : coverageDirectory  }  } ) ; 
78+ 
79+   assert . strictEqual ( stderr ,  '' ) ; 
80+   assert . strictEqual ( code ,  0 ) ; 
81+   assert . strictEqual ( signal ,  null ) ; 
82+   const  files  =  await  getCoveredFiles ( coverageDirectory ) ; 
83+   assert . ok ( files . has ( fixtures . fileURL ( 'v8-coverage/basic.js' ) . href ) ) ; 
84+ } 
0 commit comments