fix(@angular/build): validate V8 coverage support for browsers in Vitest#32987
fix(@angular/build): validate V8 coverage support for browsers in Vitest#32987clydin wants to merge 1 commit intoangular:mainfrom
Conversation
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.
1574491 to
f28dabb
Compare
There was a problem hiding this comment.
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.
| 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.`, | ||
| ); | ||
| } | ||
| } |
There was a problem hiding this comment.
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.
| 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.', | |
| ); | |
| } |
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.