diff --git a/packages/vitest/src/node/core.ts b/packages/vitest/src/node/core.ts index cb1f11df47af..480ca1600b68 100644 --- a/packages/vitest/src/node/core.ts +++ b/packages/vitest/src/node/core.ts @@ -264,7 +264,6 @@ export class Vitest { 'testTimeout', 'pool', 'globals', - 'mode', 'expandSnapshotDiff', 'retry', 'testNamePattern', diff --git a/packages/vitest/src/node/workspace.ts b/packages/vitest/src/node/workspace.ts index d816ac87cb9b..6f1e2c472367 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) +})