Skip to content

Commit 8dabef8

Browse files
authoredDec 18, 2023
fix(vitest): pass down CLI options to override workspace configs (#4774)
1 parent 184f4cc commit 8dabef8

File tree

6 files changed

+50
-2
lines changed

6 files changed

+50
-2
lines changed
 

‎packages/vitest/src/node/core.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -264,8 +264,11 @@ export class Vitest {
264264
'testTimeout',
265265
'pool',
266266
'globals',
267-
'mode',
268267
'expandSnapshotDiff',
268+
'retry',
269+
'testNamePattern',
270+
'passWithNoTests',
271+
'bail',
269272
] as const
270273

271274
const cliOverrides = overridesOptions.reduce((acc, name) => {

‎packages/vitest/src/node/workspace.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export async function initializeProject(workspacePath: string | number, ctx: Vit
4141
logLevel: 'error',
4242
configFile,
4343
// this will make "mode": "test" | "benchmark" inside defineConfig
44-
mode: options.mode || ctx.config.mode,
44+
mode: options.test?.mode || options.mode || ctx.config.mode,
4545
plugins: [
4646
...options.plugins || [],
4747
WorkspaceVitestPlugin(project, { ...options, root, workspacePath }),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { it, expect } from 'vitest';
2+
3+
it('math', () => {
4+
expect(1).toBe(1)
5+
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default ['projects']

‎test/config/test/flags.test.ts

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { expect, it } from 'vitest'
2+
import { runVitest } from '../../test-utils'
3+
4+
it('correctly inherit from the cli', async () => {
5+
const { vitest } = await runVitest({
6+
root: 'fixtures/workspace-flags',
7+
logHeapUsage: true,
8+
allowOnly: true,
9+
sequence: {
10+
seed: 123,
11+
},
12+
testTimeout: 5321,
13+
pool: 'forks',
14+
globals: true,
15+
expandSnapshotDiff: true,
16+
retry: 6,
17+
testNamePattern: 'math',
18+
passWithNoTests: true,
19+
bail: 100,
20+
})
21+
const project = vitest!.projects[0]
22+
const config = project.getSerializableConfig()
23+
expect(config).toMatchObject({
24+
logHeapUsage: true,
25+
allowOnly: true,
26+
sequence: expect.objectContaining({
27+
seed: 123,
28+
}),
29+
testTimeout: 5321,
30+
pool: 'forks',
31+
globals: true,
32+
expandSnapshotDiff: true,
33+
retry: 6,
34+
passWithNoTests: true,
35+
bail: 100,
36+
})
37+
expect(config.testNamePattern?.test('math')).toBe(true)
38+
})

0 commit comments

Comments
 (0)
Please sign in to comment.