···6767 BROWSER_TESTS,
68686969 // Other non-provider-specific tests that should be run on browser mode as well
7070+ '**/all.test.ts',
7071 '**/isolation.test.ts',
7172 '**/include-exclude.test.ts',
7273 '**/allow-external.test.ts',
···9293 BROWSER_TESTS,
93949495 // Other non-provider-specific tests that should be run on browser mode as well
9696+ '**/all.test.ts',
9597 '**/isolation.test.ts',
9698 '**/include-exclude.test.ts',
9799 '**/allow-external.test.ts',
+38-38
packages/coverage-v8/src/provider.ts
···103103 const coveredFiles = coverageMap.files()
104104 const untestedCoverage = await this.getUntestedFiles(coveredFiles)
105105106106- const converted = await this.convertCoverage(untestedCoverage)
107107- coverageMap.merge(await transformCoverage(converted))
106106+ coverageMap.merge(await transformCoverage(untestedCoverage))
108107 }
109108110109 if (this.options.excludeAfterRemap) {
···158157 )
159158 }
160159161161- private async getUntestedFiles(testedFiles: string[]): Promise<RawCoverage> {
160160+ private async getUntestedFiles(testedFiles: string[]): Promise<CoverageMap> {
162161 const transformResults = normalizeTransformResults(
163162 this.ctx.vitenode.fetchCache,
164163 )
···179178 .map(file => pathToFileURL(file))
180179 .filter(file => !testedFiles.includes(file.pathname))
181180182182- let merged: RawCoverage = { result: [] }
183181 let index = 0
182182+183183+ const coverageMap = this.createCoverageMap()
184184185185 for (const chunk of this.toSlices(uncoveredFiles, this.options.processingConcurrency)) {
186186 if (debug.enabled) {
···188188 debug('Uncovered files %d/%d', index, uncoveredFiles.length)
189189 }
190190191191- const coverages = await Promise.all(
192192- chunk.map(async (filename) => {
193193- const { originalSource } = await this.getSources(
194194- filename.href,
195195- transformResults,
196196- transform,
197197- )
191191+ await Promise.all(chunk.map(async (filename) => {
192192+ const sources = await this.getSources(
193193+ filename.href,
194194+ transformResults,
195195+ transform,
196196+ )
198197199199- const coverage = {
200200- url: filename.href,
201201- scriptId: '0',
202202- // Create a made up function to mark whole file as uncovered. Note that this does not exist in source maps.
203203- functions: [
198198+ const converter = v8ToIstanbul(
199199+ filename.href,
200200+ 0,
201201+ sources,
202202+ undefined,
203203+ this.options.ignoreEmptyLines,
204204+ )
205205+206206+ await converter.load()
207207+208208+ try {
209209+ // Create a made up function to mark whole file as uncovered. Note that this does not exist in source maps.
210210+ converter.applyCoverage([{
211211+ ranges: [
204212 {
205205- ranges: [
206206- {
207207- startOffset: 0,
208208- endOffset: originalSource.length,
209209- count: 0,
210210- },
211211- ],
212212- isBlockCoverage: true,
213213- // This is magical value that indicates an empty report: https://github.com/istanbuljs/v8-to-istanbul/blob/fca5e6a9e6ef38a9cdc3a178d5a6cf9ef82e6cab/lib/v8-to-istanbul.js#LL131C40-L131C40
214214- functionName: '(empty-report)',
213213+ startOffset: 0,
214214+ endOffset: sources.originalSource.length,
215215+ count: 0,
215216 },
216217 ],
217217- }
218218+ isBlockCoverage: true,
219219+ // This is magical value that indicates an empty report: https://github.com/istanbuljs/v8-to-istanbul/blob/fca5e6a9e6ef38a9cdc3a178d5a6cf9ef82e6cab/lib/v8-to-istanbul.js#LL131C40-L131C40
220220+ functionName: '(empty-report)',
221221+ }])
222222+ }
223223+ catch (error) {
224224+ this.ctx.logger.error(`Failed to convert coverage for uncovered ${filename.href}.\n`, error)
225225+ }
218226219219- return { result: [coverage] }
220220- }),
221221- )
222222-223223- merged = mergeProcessCovs([
224224- merged,
225225- ...coverages.filter(
226226- (cov): cov is NonNullable<typeof cov> => cov != null,
227227- ),
228228- ])
227227+ coverageMap.merge(converter.toIstanbul())
228228+ }))
229229 }
230230231231- return merged
231231+ return coverageMap
232232 }
233233234234 private async getSources<TransformResult extends (FetchResult | Awaited<ReturnType<typeof this.ctx.vitenode.transformRequest>>)>(