@@ -3,8 +3,9 @@ const furi = require('furi')
33const libCoverage = require ( 'istanbul-lib-coverage' )
44const libReport = require ( 'istanbul-lib-report' )
55const reports = require ( 'istanbul-reports' )
6- const { readdirSync, readFileSync } = require ( 'fs' )
7- const { isAbsolute, resolve } = require ( 'path' )
6+ const { readdirSync, readFileSync, statSync } = require ( 'fs' )
7+ const { isAbsolute, resolve, extname } = require ( 'path' )
8+ const getSourceMapFromFile = require ( './source-map-from-file' )
89// TODO: switch back to @c 88/v8-coverage once patch is landed.
910const v8toIstanbul = require ( 'v8-to-istanbul' )
1011const isCjsEsmBridgeCov = require ( './is-cjs-esm-bridge' )
@@ -19,7 +20,8 @@ class Report {
1920 watermarks,
2021 omitRelative,
2122 wrapperLength,
22- resolve : resolvePaths
23+ resolve : resolvePaths ,
24+ all
2325 } ) {
2426 this . reporter = reporter
2527 this . reportsDirectory = reportsDirectory
@@ -33,6 +35,8 @@ class Report {
3335 this . omitRelative = omitRelative
3436 this . sourceMapCache = { }
3537 this . wrapperLength = wrapperLength
38+ this . all = all
39+ this . src = process . cwd ( )
3640 }
3741
3842 async run ( ) {
@@ -56,8 +60,8 @@ class Report {
5660 // use-case.
5761 if ( this . _allCoverageFiles ) return this . _allCoverageFiles
5862
63+ const map = libCoverage . createCoverageMap ( )
5964 const v8ProcessCov = this . _getMergedProcessCov ( )
60- const map = libCoverage . createCoverageMap ( { } )
6165 const resultCountPerPath = new Map ( )
6266 const possibleCjsEsmBridges = new Map ( )
6367
@@ -94,7 +98,6 @@ class Report {
9498 map . merge ( converter . toIstanbul ( ) )
9599 }
96100 }
97-
98101 this . _allCoverageFiles = map
99102 return this . _allCoverageFiles
100103 }
@@ -139,14 +142,50 @@ class Report {
139142 _getMergedProcessCov ( ) {
140143 const { mergeProcessCovs } = require ( '@bcoe/v8-coverage' )
141144 const v8ProcessCovs = [ ]
145+ const fileIndex = new Set ( ) // Set<string>
142146 for ( const v8ProcessCov of this . _loadReports ( ) ) {
143147 if ( this . _isCoverageObject ( v8ProcessCov ) ) {
144148 if ( v8ProcessCov [ 'source-map-cache' ] ) {
145149 Object . assign ( this . sourceMapCache , v8ProcessCov [ 'source-map-cache' ] )
146150 }
147- v8ProcessCovs . push ( this . _normalizeProcessCov ( v8ProcessCov ) )
151+ v8ProcessCovs . push ( this . _normalizeProcessCov ( v8ProcessCov , fileIndex ) )
148152 }
149153 }
154+
155+ if ( this . all ) {
156+ const emptyReports = [ ]
157+ v8ProcessCovs . unshift ( {
158+ result : emptyReports
159+ } )
160+ const workingDir = process . cwd ( )
161+ this . exclude . globSync ( workingDir ) . forEach ( ( f ) => {
162+ const fullPath = resolve ( workingDir , f )
163+ if ( ! fileIndex . has ( fullPath ) ) {
164+ const ext = extname ( f )
165+ if ( ext === '.js' || ext === '.ts' || ext === '.mjs' ) {
166+ const stat = statSync ( f )
167+ const sourceMap = getSourceMapFromFile ( f )
168+ if ( sourceMap !== undefined ) {
169+ this . sourceMapCache [ `file://${ fullPath } ` ] = { data : JSON . parse ( readFileSync ( sourceMap ) . toString ( ) ) }
170+ }
171+ emptyReports . push ( {
172+ scriptId : 0 ,
173+ url : resolve ( f ) ,
174+ functions : [ {
175+ functionName : '(empty-report)' ,
176+ ranges : [ {
177+ startOffset : 0 ,
178+ endOffset : stat . size ,
179+ count : 0
180+ } ] ,
181+ isBlockCoverage : true
182+ } ]
183+ } )
184+ }
185+ }
186+ } )
187+ }
188+
150189 return mergeProcessCovs ( v8ProcessCovs )
151190 }
152191
@@ -193,15 +232,17 @@ class Report {
193232 * There is no deep cloning.
194233 *
195234 * @param v8ProcessCov V8 process coverage to normalize.
235+ * @param fileIndex a Set<string> of paths discovered in coverage
196236 * @return {v8ProcessCov } Normalized V8 process coverage.
197237 * @private
198238 */
199- _normalizeProcessCov ( v8ProcessCov ) {
239+ _normalizeProcessCov ( v8ProcessCov , fileIndex ) {
200240 const result = [ ]
201241 for ( const v8ScriptCov of v8ProcessCov . result ) {
202242 if ( / ^ f i l e : \/ \/ / . test ( v8ScriptCov . url ) ) {
203243 try {
204244 v8ScriptCov . url = furi . toSysPath ( v8ScriptCov . url )
245+ fileIndex . add ( v8ScriptCov . url )
205246 } catch ( err ) {
206247 console . warn ( err )
207248 continue
0 commit comments