Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 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
11 changes: 5 additions & 6 deletions docs/guide/debugging.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,11 @@ import { defineConfig } from 'vitest/config'

export default defineConfig({
test: {
inspectBrk: true,
fileParallelism: false,
browser: {
name: 'chromium',
provider: 'playwright',
},
provider: 'playwright',
enabled: true,
instances: [
{ browser: 'chromium' },
],
},
})
```
Expand Down
16 changes: 12 additions & 4 deletions packages/vitest/src/node/config/resolveConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,14 +251,22 @@ export function resolveConfig(
}
}

const playwrightChromiumOnly = browser.provider === 'playwright' && (browser.name === 'chromium' || browser.instances?.every(i => i.browser === 'chromium'))

// Browser-mode "Playwright + Chromium" only features:
if (browser.enabled && !(browser.provider === 'playwright' && browser.name === 'chromium')) {
const browserConfig = { browser: { provider: browser.provider, name: browser.name } }
if (browser.enabled && !playwrightChromiumOnly) {
const browserConfig = {
browser: {
provider: browser.provider,
name: browser.name,
instances: browser.instances,
},
}

if (resolved.coverage.enabled && resolved.coverage.provider === 'v8') {
throw new Error(
`@vitest/coverage-v8 does not work with\n${JSON.stringify(browserConfig, null, 2)}\n`
+ `\nUse either:\n${JSON.stringify({ browser: { provider: 'playwright', name: 'chromium' } }, null, 2)}`
+ `\nUse either:\n${JSON.stringify({ browser: { provider: 'playwright', instances: [{ browser: 'chromium' }] } }, null, 2)}`
+ `\n\n...or change your coverage provider to:\n${JSON.stringify({ coverage: { provider: 'istanbul' } }, null, 2)}\n`,
)
}
Expand All @@ -268,7 +276,7 @@ export function resolveConfig(

throw new Error(
`${inspectOption} does not work with\n${JSON.stringify(browserConfig, null, 2)}\n`
+ `\nUse either:\n${JSON.stringify({ browser: { provider: 'playwright', name: 'chromium' } }, null, 2)}`
+ `\nUse either:\n${JSON.stringify({ browser: { provider: 'playwright', instances: [{ browser: 'chromium' }] } }, null, 2)}`
+ `\n\n...or disable ${inspectOption}\n`,
)
}
Expand Down
4 changes: 2 additions & 2 deletions packages/vitest/src/node/types/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export interface BrowserConfigOptions {

/**
* Name of the browser
* @deprecated use `configs` instead. if both are defined, this will filter `configs` by name.
* @deprecated use `instances` instead. if both are defined, this will filter `instances` by name.
*/
name?: string

Expand All @@ -118,7 +118,7 @@ export interface BrowserConfigOptions {
*
* @example
* { playwright: { launch: { devtools: true } }
* @deprecated use `configs` instead
* @deprecated use `instances` instead
*/
providerOptions?: BrowserProviderOptions

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default defineWorkspace([
browser: {
enabled: true,
provider: 'webdriverio',
name: 'chrome',
instances: [{ browser: 'chrome' }]
},
}
}
Expand Down
130 changes: 126 additions & 4 deletions test/config/test/failures.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,11 @@ Use either:
{
"browser": {
"provider": "playwright",
"name": "chromium"
"instances": [
{
"browser": "chromium"
}
]
}
}

Expand All @@ -122,7 +126,7 @@ Use either:
}
})

test('v8 coverage provider throws when not playwright + chromium', async () => {
test('v8 coverage provider throws when not playwright + chromium (browser.name)', async () => {
for (const { provider, name } of browsers) {
if (provider === 'playwright' && name === 'chromium') {
continue
Expand Down Expand Up @@ -152,7 +156,64 @@ Use either:
{
"browser": {
"provider": "playwright",
"name": "chromium"
"instances": [
{
"browser": "chromium"
}
]
}
}

...or change your coverage provider to:
{
"coverage": {
"provider": "istanbul"
}
}
`,
)
}
})

test('v8 coverage provider throws when not playwright + chromium (browser.instances)', async () => {
for (const { provider, name } of browsers) {
if (provider === 'playwright' && name === 'chromium') {
continue
}

const { stderr } = await runVitest({
coverage: {
enabled: true,
},
browser: {
enabled: true,
provider,
instances: [{ browser: name }],
},
})

expect(stderr).toMatch(
`Error: @vitest/coverage-v8 does not work with
{
"browser": {
"provider": "${provider}",
"instances": [
{
"browser": "${name}"
}
]
}
}

Use either:
{
"browser": {
"provider": "playwright",
"instances": [
{
"browser": "chromium"
}
]
}
}

Expand All @@ -167,14 +228,75 @@ Use either:
}
})

test('v8 coverage provider throws when using chromium and other non-chromium browser', async () => {
const { stderr } = await runVitest({
coverage: {
enabled: true,
},
browser: {
enabled: true,
headless: true,
provider: 'playwright',
instances: [
{ browser: 'chromium' },
{ browser: 'firefox' },
{ browser: 'webkit' },
],
},
})

expect(stderr).toMatch(
`Error: @vitest/coverage-v8 does not work with
{
"browser": {
"provider": "playwright",
"instances": [
{
"browser": "chromium"
},
{
"browser": "firefox"
},
{
"browser": "webkit"
}
]
}
}

Use either:
{
"browser": {
"provider": "playwright",
"instances": [
{
"browser": "chromium"
}
]
}
}

...or change your coverage provider to:
{
"coverage": {
"provider": "istanbul"
}
}`,
)
})

test('v8 coverage provider cannot be used in workspace without playwright + chromium', async () => {
const { stderr } = await runVitest({ coverage: { enabled: true }, workspace: './fixtures/workspace/browser/workspace-with-browser.ts' })
expect(stderr).toMatch(
`Error: @vitest/coverage-v8 does not work with
{
"browser": {
"provider": "webdriverio",
"name": "chrome"
"instances": [
{
"browser": "chrome"
}
]
}
}`,
)
Expand Down
Loading