diff --git a/packages/vitest/src/node/core.ts b/packages/vitest/src/node/core.ts index 7476fedf667b..480ca1600b68 100644 --- a/packages/vitest/src/node/core.ts +++ b/packages/vitest/src/node/core.ts @@ -264,8 +264,11 @@ export class Vitest { 'testTimeout', 'pool', 'globals', - 'mode', 'expandSnapshotDiff', + 'retry', + 'testNamePattern', + 'passWithNoTests', + 'bail', ] as const const cliOverrides = overridesOptions.reduce((acc, name) => { diff --git a/packages/vitest/src/node/workspace.ts b/packages/vitest/src/node/workspace.ts index ac03903b9c74..4357638787c3 100644 --- a/packages/vitest/src/node/workspace.ts +++ b/packages/vitest/src/node/workspace.ts @@ -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 }), diff --git a/test/config/fixtures/workspace-flags/projects/cli-config.test.ts b/test/config/fixtures/workspace-flags/projects/cli-config.test.ts new file mode 100644 index 000000000000..c069dce322ae --- /dev/null +++ b/test/config/fixtures/workspace-flags/projects/cli-config.test.ts @@ -0,0 +1,5 @@ +import { it, expect } from 'vitest'; + +it('math', () => { + expect(1).toBe(1) +}) diff --git a/test/config/fixtures/workspace-flags/projects/vitest.config.js b/test/config/fixtures/workspace-flags/projects/vitest.config.js new file mode 100644 index 000000000000..56004c9f9e06 --- /dev/null +++ b/test/config/fixtures/workspace-flags/projects/vitest.config.js @@ -0,0 +1 @@ +export default {} \ No newline at end of file diff --git a/test/config/fixtures/workspace-flags/vitest.workspace.js b/test/config/fixtures/workspace-flags/vitest.workspace.js new file mode 100644 index 000000000000..47d013c1f23e --- /dev/null +++ b/test/config/fixtures/workspace-flags/vitest.workspace.js @@ -0,0 +1 @@ +export default ['projects'] \ No newline at end of file diff --git a/test/config/test/flags.test.ts b/test/config/test/flags.test.ts new file mode 100644 index 000000000000..ab7230acc25e --- /dev/null +++ b/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) +})