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(browser): don't throw a validation error if v8 coverage is used with filtered instances #7306

Merged
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
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',
])
})
Loading