Skip to content

Commit

Permalink
fix(test-runner-coverage-v8): modernweb-dev#2825 ignore invalid URLs …
Browse files Browse the repository at this point in the history
…during code coverage conversion
  • Loading branch information
Devin McIntyre committed Oct 15, 2024
1 parent aadcbea commit dcce65d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 18 deletions.
5 changes: 5 additions & 0 deletions .changeset/eleven-seahorses-wave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@web/test-runner-coverage-v8': patch
---

fix(test-runner-coverage-v8): #2825 ignore invalid URLs during code coverage conversion
42 changes: 24 additions & 18 deletions packages/test-runner-coverage-v8/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,21 +66,27 @@ export async function v8ToIstanbul(
const istanbulCoverage: CoverageMapData = {};

for (const entry of coverage) {
const url = new URL(entry.url);
const path = url.pathname;
if (
// ignore non-http protocols (for exmaple webpack://)
url.protocol.startsWith('http') &&
// ignore external urls
url.hostname === config.hostname &&
url.port === `${config.port}` &&
// ignore non-files
!!extname(path) &&
// ignore virtual files
!path.startsWith('/__web-test-runner') &&
!path.startsWith('/__web-dev-server')
) {
try {
let url;
try {
url = new URL(entry.url);
} catch (_) {
// ignore invalid URLs
continue;
}
try {
const path = url.pathname;
if (
// ignore non-http protocols (for example webpack://)
url.protocol.startsWith('http') &&
// ignore external urls
url.hostname === config.hostname &&
url.port === `${config.port}` &&
// ignore non-files
!!extname(path) &&
// ignore virtual files
!path.startsWith('/__web-test-runner') &&
!path.startsWith('/__web-dev-server')
) {
const filePath = join(config.rootDir, toFilePath(path));

if (!testFiles.includes(filePath) && included(filePath) && !excluded(filePath)) {
Expand Down Expand Up @@ -110,10 +116,10 @@ export async function v8ToIstanbul(
converter.applyCoverage(entry.functions);
Object.assign(istanbulCoverage, converter.toIstanbul());
}
} catch (error) {
console.error(`Error while generating code coverage for ${entry.url}.`);
console.error(error);
}
} catch (error) {
console.error(`Error while generating code coverage for ${entry.url}.`);
console.error(error);
}
}

Expand Down

0 comments on commit dcce65d

Please sign in to comment.