Skip to content

Commit

Permalink
fix(vitest): pass down CLI options to override workspace configs (#4774)
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va committed Dec 18, 2023
1 parent 184f4cc commit 8dabef8
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 2 deletions.
5 changes: 4 additions & 1 deletion packages/vitest/src/node/core.ts
Expand Up @@ -264,8 +264,11 @@ export class Vitest {
'testTimeout',
'pool',
'globals',
'mode',
'expandSnapshotDiff',
'retry',
'testNamePattern',
'passWithNoTests',
'bail',
] as const

const cliOverrides = overridesOptions.reduce((acc, name) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/vitest/src/node/workspace.ts
Expand Up @@ -41,7 +41,7 @@ export async function initializeProject(workspacePath: string | number, ctx: Vit
logLevel: 'error',
configFile,
// this will make "mode": "test" | "benchmark" inside defineConfig
mode: options.mode || ctx.config.mode,
mode: options.test?.mode || options.mode || ctx.config.mode,
plugins: [
...options.plugins || [],
WorkspaceVitestPlugin(project, { ...options, root, workspacePath }),
Expand Down
@@ -0,0 +1,5 @@
import { it, expect } from 'vitest';

it('math', () => {
expect(1).toBe(1)
})
@@ -0,0 +1 @@
export default {}
1 change: 1 addition & 0 deletions test/config/fixtures/workspace-flags/vitest.workspace.js
@@ -0,0 +1 @@
export default ['projects']
38 changes: 38 additions & 0 deletions test/config/test/flags.test.ts
@@ -0,0 +1,38 @@
import { expect, it } from 'vitest'
import { runVitest } from '../../test-utils'

it('correctly inherit from the cli', async () => {
const { vitest } = await runVitest({
root: 'fixtures/workspace-flags',
logHeapUsage: true,
allowOnly: true,
sequence: {
seed: 123,
},
testTimeout: 5321,
pool: 'forks',
globals: true,
expandSnapshotDiff: true,
retry: 6,
testNamePattern: 'math',
passWithNoTests: true,
bail: 100,
})
const project = vitest!.projects[0]
const config = project.getSerializableConfig()
expect(config).toMatchObject({
logHeapUsage: true,
allowOnly: true,
sequence: expect.objectContaining({
seed: 123,
}),
testTimeout: 5321,
pool: 'forks',
globals: true,
expandSnapshotDiff: true,
retry: 6,
passWithNoTests: true,
bail: 100,
})
expect(config.testNamePattern?.test('math')).toBe(true)
})

0 comments on commit 8dabef8

Please sign in to comment.