Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(test-runner-coverage-v8): #2825 ignore invalid URLs #2827

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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