(
coverage: RawCoverage,
project: TestProject = this.ctx.getRootProject(),
environment: string,
)
| 377 | } |
| 378 | |
| 379 | private async convertCoverage( |
| 380 | coverage: RawCoverage, |
| 381 | project: TestProject = this.ctx.getRootProject(), |
| 382 | environment: string, |
| 383 | ): Promise<CoverageMap> { |
| 384 | if (environment === '__browser__' && !project.browser) { |
| 385 | throw new Error(`Cannot access browser module graph because it was torn down.`) |
| 386 | } |
| 387 | |
| 388 | const onTransform = async (filepath: string) => { |
| 389 | const result = await this.transformFile(filepath, project, environment) |
| 390 | if (result && environment === '__browser__' && project.browser) { |
| 391 | return { ...result, code: `${result.code}// <inline-source-map>` } |
| 392 | } |
| 393 | return result |
| 394 | } |
| 395 | |
| 396 | const scriptCoverages = [] |
| 397 | |
| 398 | for (const result of coverage.result) { |
| 399 | if (environment === '__browser__') { |
| 400 | if (result.url.startsWith('/@fs')) { |
| 401 | result.url = `${FILE_PROTOCOL}${removeStartsWith(result.url, '/@fs')}` |
| 402 | } |
| 403 | else if (result.url.startsWith(project.config.root)) { |
| 404 | result.url = `${FILE_PROTOCOL}${result.url}` |
| 405 | } |
| 406 | else { |
| 407 | result.url = `${FILE_PROTOCOL}${project.config.root}${result.url}` |
| 408 | } |
| 409 | } |
| 410 | |
| 411 | if (this.isIncluded(fileURLToPath(result.url))) { |
| 412 | scriptCoverages.push({ ...result, url: decodeURIComponent(result.url) }) |
| 413 | } |
| 414 | } |
| 415 | |
| 416 | const coverageMap = this.createCoverageMap() |
| 417 | let index = 0 |
| 418 | |
| 419 | for (const chunk of this.toSlices(scriptCoverages, this.options.processingConcurrency)) { |
| 420 | if (debug.enabled) { |
| 421 | index += chunk.length |
| 422 | debug('Converting %d/%d', index, scriptCoverages.length) |
| 423 | } |
| 424 | |
| 425 | await Promise.all( |
| 426 | chunk.map(async ({ url, functions, startOffset }) => { |
| 427 | let timeout: ReturnType<typeof setTimeout> | undefined |
| 428 | let start: number | undefined |
| 429 | |
| 430 | if (debug.enabled) { |
| 431 | start = performance.now() |
| 432 | timeout = setTimeout(() => debug(c.bgRed(`File "${fileURLToPath(url)}" is taking longer than 3s`)), 3_000) |
| 433 | } |
| 434 | |
| 435 | const sources = await this.getSources( |
| 436 | url, |
no test coverage detected