From 73ecf55faf84af8f7b9f21a45f173f787f0e59f0 Mon Sep 17 00:00:00 2001 From: Vladimir Sheremet Date: Mon, 20 Jan 2025 15:13:48 +0100 Subject: [PATCH] fix(browser): don't throw a validation error if v8 coverage is used with filtered instances --- .../vitest/src/node/config/resolveConfig.ts | 28 ++++++++++++++++++- test/config/test/browser-configs.test.ts | 22 +++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/packages/vitest/src/node/config/resolveConfig.ts b/packages/vitest/src/node/config/resolveConfig.ts index 4255f9a12c35..693dbab7e04a 100644 --- a/packages/vitest/src/node/config/resolveConfig.ts +++ b/packages/vitest/src/node/config/resolveConfig.ts @@ -20,6 +20,7 @@ import { extraInlineDeps, } from '../../constants' import { benchmarkConfigDefaults, configDefaults } from '../../defaults' +import { wildcardPatternToRegExp } from '../../utils/base' import { isCI, stdProvider } from '../../utils/env' import { getWorkersCountByPercentage } from '../../utils/workers' import { VitestCache } from '../cache' @@ -251,7 +252,7 @@ export function resolveConfig( } } - const playwrightChromiumOnly = browser.provider === 'playwright' && (browser.name === 'chromium' || browser.instances?.every(i => i.browser === 'chromium')) + const playwrightChromiumOnly = isPlaywrightChromiumOnly(resolved) // Browser-mode "Playwright + Chromium" only features: if (browser.enabled && !playwrightChromiumOnly) { @@ -891,3 +892,28 @@ export function resolveCoverageReporters(configReporters: NonNullable wildcardPatternToRegExp(p)) + for (const instance of browser.instances) { + const name = instance.name || (config.name ? `${config.name} (${instance.browser})` : instance.browser) + // browser config is filtered out + if (filteredProjects.length && !filteredProjects.every(p => p.test(name))) { + continue + } + if (instance.browser !== 'chromium') { + return false + } + } + return true +} diff --git a/test/config/test/browser-configs.test.ts b/test/config/test/browser-configs.test.ts index efdd91b47396..8cb122b40d48 100644 --- a/test/config/test/browser-configs.test.ts +++ b/test/config/test/browser-configs.test.ts @@ -175,3 +175,25 @@ test('inherits browser options', async () => { }, ]) }) + +test('coverage provider v8 works correctly in browser mode if instances are filtered', async () => { + const { projects } = await vitest({ + project: 'chromium', + coverage: { + enabled: true, + provider: 'v8', + }, + browser: { + enabled: true, + provider: 'playwright', + instances: [ + { browser: 'chromium' }, + { browser: 'firefox' }, + { browser: 'webkit' }, + ], + }, + }) + expect(projects.map(p => p.name)).toEqual([ + 'chromium', + ]) +})