@@ -2,6 +2,8 @@ import * as common from '../common/index.mjs';
2
2
import * as tmpdir from '../common/tmpdir.js' ;
3
3
import * as fixtures from '../common/fixtures.mjs' ;
4
4
import assert from 'node:assert' ;
5
+ import path from 'node:path' ;
6
+ import fs from 'node:fs/promises' ;
5
7
import { NodeInstance } from '../common/inspector-helper.js' ;
6
8
7
9
@@ -52,3 +54,31 @@ tmpdir.refresh();
52
54
assert . strictEqual ( code , 1 ) ;
53
55
assert . strictEqual ( signal , null ) ;
54
56
}
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