Skip to content

fix(@angular/build): validate V8 coverage support for browsers in Vitest#32987

Open
clydin wants to merge 1 commit intoangular:mainfrom
clydin:vitest/browser-coverage-val
Open

fix(@angular/build): validate V8 coverage support for browsers in Vitest#32987
clydin wants to merge 1 commit intoangular:mainfrom
clydin:vitest/browser-coverage-val

Conversation

@clydin
Copy link
Copy Markdown
Member

@clydin clydin commented Apr 10, 2026

This change introduces a validation check in the Vitest runner to ensure that code coverage is only enabled when using supported Chromium-based browsers. Since the Angular CLI integration currently relies exclusively on the V8 coverage provider, running tests in non-Chromium browsers like Firefox or Safari with coverage enabled would result in incomplete data or missing reports. By adding this check, developers will receive a clear, actionable error message early in the process, preventing confusion and ensuring reliable coverage reports.

@clydin clydin added the target: patch This PR is targeted for the next patch release label Apr 10, 2026
This change introduces a validation check in the Vitest runner to ensure that code coverage is only enabled when using supported Chromium-based browsers. Since the Angular CLI integration currently relies exclusively on the V8 coverage provider, running tests in non-Chromium browsers like Firefox or Safari with coverage enabled would result in incomplete data or missing reports. By adding this check, developers will receive a clear, actionable error message early in the process, preventing confusion and ensuring reliable coverage reports.
@clydin clydin force-pushed the vitest/browser-coverage-val branch from 1574491 to f28dabb Compare April 11, 2026 01:17
@clydin clydin marked this pull request as ready for review April 11, 2026 04:11
@clydin clydin added the action: review The PR is still awaiting reviews from at least one requested reviewer label Apr 11, 2026
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces validation to ensure that V8 code coverage is only enabled for supported Chromium-based browsers when using the Vitest runner, and adds an E2E test to verify this behavior. A review comment identifies that the current implementation only checks the instances property from CLI options, potentially bypassing validation for browsers configured via the name property or within vitest.config.ts. A code suggestion is provided to make the validation more robust by checking these additional configuration sources.

Comment on lines +158 to +171
if (browser?.instances) {
const unsupportedBrowsers = browser.instances.filter(
(instance) => !['chrome', 'chromium', 'edge'].includes(instance.browser),
);

if (unsupportedBrowsers.length > 0) {
throw new Error(
`Code coverage is enabled, but the following configured browsers do not support the V8 coverage provider: ` +
`${unsupportedBrowsers.map((i) => i.browser).join(', ')}. ` +
`V8 coverage is only supported on Chromium-based browsers (e.g., Chrome, Chromium, Edge). ` +
`Please disable coverage or remove the unsupported browsers.`,
);
}
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The current validation only checks the instances property of the CLI-provided browser options. It should also validate the name property (which Vitest uses if instances is not defined) and consider the browser configuration defined in the Vitest configuration file (testConfig.browser). Without this, users configuring browsers via vitest.config.ts or using the name property will bypass this validation, leading to the incomplete coverage data this PR aims to prevent.

Suggested change
if (browser?.instances) {
const unsupportedBrowsers = browser.instances.filter(
(instance) => !['chrome', 'chromium', 'edge'].includes(instance.browser),
);
if (unsupportedBrowsers.length > 0) {
throw new Error(
`Code coverage is enabled, but the following configured browsers do not support the V8 coverage provider: ` +
`${unsupportedBrowsers.map((i) => i.browser).join(', ')}. ` +
`V8 coverage is only supported on Chromium-based browsers (e.g., Chrome, Chromium, Edge). ` +
`Please disable coverage or remove the unsupported browsers.`,
);
}
}
const activeBrowser = browser ?? testConfig?.browser;
const unsupportedBrowsers = activeBrowser?.instances
? activeBrowser.instances
.filter((i) => !['chrome', 'chromium', 'edge'].includes(i.browser))
.map((i) => i.browser)
: activeBrowser?.name && !['chrome', 'chromium', 'edge'].includes(activeBrowser.name)
? [activeBrowser.name]
: [];
if (unsupportedBrowsers.length > 0) {
throw new Error(
'Code coverage is enabled, but the following configured browsers do not support the V8 coverage provider: ' +
unsupportedBrowsers.join(', ') + '. ' +
'V8 coverage is only supported on Chromium-based browsers (e.g., Chrome, Chromium, Edge). ' +
'Please disable coverage or remove the unsupported browsers.',
);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

action: review The PR is still awaiting reviews from at least one requested reviewer area: @angular/build target: patch This PR is targeted for the next patch release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant