Skip to content

Commit dcce65d

Browse files
author
Devin McIntyre
committed
fix(test-runner-coverage-v8): modernweb-dev#2825 ignore invalid URLs during code coverage conversion
1 parent aadcbea commit dcce65d

File tree

2 files changed

+29
-18
lines changed

2 files changed

+29
-18
lines changed

Diff for: .changeset/eleven-seahorses-wave.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@web/test-runner-coverage-v8': patch
3+
---
4+
5+
fix(test-runner-coverage-v8): #2825 ignore invalid URLs during code coverage conversion

Diff for: packages/test-runner-coverage-v8/src/index.ts

+24-18
Original file line numberDiff line numberDiff line change
@@ -66,21 +66,27 @@ export async function v8ToIstanbul(
6666
const istanbulCoverage: CoverageMapData = {};
6767

6868
for (const entry of coverage) {
69-
const url = new URL(entry.url);
70-
const path = url.pathname;
71-
if (
72-
// ignore non-http protocols (for exmaple webpack://)
73-
url.protocol.startsWith('http') &&
74-
// ignore external urls
75-
url.hostname === config.hostname &&
76-
url.port === `${config.port}` &&
77-
// ignore non-files
78-
!!extname(path) &&
79-
// ignore virtual files
80-
!path.startsWith('/__web-test-runner') &&
81-
!path.startsWith('/__web-dev-server')
82-
) {
83-
try {
69+
let url;
70+
try {
71+
url = new URL(entry.url);
72+
} catch (_) {
73+
// ignore invalid URLs
74+
continue;
75+
}
76+
try {
77+
const path = url.pathname;
78+
if (
79+
// ignore non-http protocols (for example webpack://)
80+
url.protocol.startsWith('http') &&
81+
// ignore external urls
82+
url.hostname === config.hostname &&
83+
url.port === `${config.port}` &&
84+
// ignore non-files
85+
!!extname(path) &&
86+
// ignore virtual files
87+
!path.startsWith('/__web-test-runner') &&
88+
!path.startsWith('/__web-dev-server')
89+
) {
8490
const filePath = join(config.rootDir, toFilePath(path));
8591

8692
if (!testFiles.includes(filePath) && included(filePath) && !excluded(filePath)) {
@@ -110,10 +116,10 @@ export async function v8ToIstanbul(
110116
converter.applyCoverage(entry.functions);
111117
Object.assign(istanbulCoverage, converter.toIstanbul());
112118
}
113-
} catch (error) {
114-
console.error(`Error while generating code coverage for ${entry.url}.`);
115-
console.error(error);
116119
}
120+
} catch (error) {
121+
console.error(`Error while generating code coverage for ${entry.url}.`);
122+
console.error(error);
117123
}
118124
}
119125

0 commit comments

Comments
 (0)