Skip to content

Commit

Permalink
fix(browser): don't throw a validation error if v8 coverage is used w…
Browse files Browse the repository at this point in the history
…ith filtered instances (#7306)
  • Loading branch information
sheremet-va authored Jan 20, 2025
1 parent 7f36b6f commit fa4634b
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
28 changes: 27 additions & 1 deletion packages/vitest/src/node/config/resolveConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -891,3 +892,28 @@ export function resolveCoverageReporters(configReporters: NonNullable<BaseCovera

return resolvedReporters
}

function isPlaywrightChromiumOnly(config: ResolvedConfig) {
const browser = config.browser
if (!browser || browser.provider !== 'playwright' || !browser.enabled) {
return false
}
if (browser.name) {
return browser.name === 'chromium'
}
if (!browser.instances) {
return false
}
const filteredProjects = toArray(config.project).map(p => 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
}
22 changes: 22 additions & 0 deletions test/config/test/browser-configs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
])
})

0 comments on commit fa4634b

Please sign in to comment.