From 3b87d852ca3d40f219066341acb873808956b8ed Mon Sep 17 00:00:00 2001 From: Vladimir Sheremet Date: Mon, 18 Dec 2023 14:48:27 +0100 Subject: [PATCH 1/2] fix(vitest): pass down CLI options to override workspace configs --- packages/vitest/src/node/core.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/vitest/src/node/core.ts b/packages/vitest/src/node/core.ts index 7476fedf667b..cb1f11df47af 100644 --- a/packages/vitest/src/node/core.ts +++ b/packages/vitest/src/node/core.ts @@ -266,6 +266,10 @@ export class Vitest { 'globals', 'mode', 'expandSnapshotDiff', + 'retry', + 'testNamePattern', + 'passWithNoTests', + 'bail', ] as const const cliOverrides = overridesOptions.reduce((acc, name) => { From 3d7b734f3a4e231b505a3af64becf6551f68a472 Mon Sep 17 00:00:00 2001 From: Vladimir Sheremet Date: Mon, 18 Dec 2023 17:50:39 +0100 Subject: [PATCH 2/2] test: add test for workspace flags --- packages/vitest/src/node/core.ts | 1 - packages/vitest/src/node/workspace.ts | 2 +- .../projects/cli-config.test.ts | 5 +++ .../workspace-flags/projects/vitest.config.js | 1 + .../workspace-flags/vitest.workspace.js | 1 + test/config/test/flags.test.ts | 38 +++++++++++++++++++ 6 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 test/config/fixtures/workspace-flags/projects/cli-config.test.ts create mode 100644 test/config/fixtures/workspace-flags/projects/vitest.config.js create mode 100644 test/config/fixtures/workspace-flags/vitest.workspace.js create mode 100644 test/config/test/flags.test.ts 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) +})