diff --git a/packages/vitest/src/node/plugins/index.ts b/packages/vitest/src/node/plugins/index.ts index d07e09bcd83c..09969d21f1bf 100644 --- a/packages/vitest/src/node/plugins/index.ts +++ b/packages/vitest/src/node/plugins/index.ts @@ -50,13 +50,6 @@ export async function VitestPlugin(options: UserConfig = {}, ctx = new Vitest('t ) testConfig.api = resolveApiServerConfig(testConfig) - testConfig.poolOptions ??= {} - testConfig.poolOptions.threads ??= {} - testConfig.poolOptions.forks ??= {} - // prefer --poolOptions.{name}.isolate CLI arguments over --isolate, but still respect config value - testConfig.poolOptions.threads.isolate = options.poolOptions?.threads?.isolate ?? options.isolate ?? testConfig.poolOptions.threads.isolate ?? viteConfig.test?.isolate - testConfig.poolOptions.forks.isolate = options.poolOptions?.forks?.isolate ?? options.isolate ?? testConfig.poolOptions.forks.isolate ?? viteConfig.test?.isolate - // store defines for globalThis to make them // reassignable when running in worker in src/runtime/setup.ts const defines: Record = deleteDefineConfig(viteConfig) @@ -98,7 +91,14 @@ export async function VitestPlugin(options: UserConfig = {}, ctx = new Vitest('t }, }, test: { - poolOptions: testConfig.poolOptions, + poolOptions: { + threads: { + isolate: options.poolOptions?.threads?.isolate ?? options.isolate ?? testConfig.poolOptions?.threads?.isolate ?? viteConfig.test?.isolate, + }, + forks: { + isolate: options.poolOptions?.threads?.isolate ?? options.isolate ?? testConfig.poolOptions?.threads?.isolate ?? viteConfig.test?.isolate, + }, + }, }, } diff --git a/test/config/test/resolution.test.ts b/test/config/test/resolution.test.ts index bf7f4e9007f3..63d6009dbfc3 100644 --- a/test/config/test/resolution.test.ts +++ b/test/config/test/resolution.test.ts @@ -15,6 +15,22 @@ async function config(cliOptions: UserConfig, configValue: UserConfig = {}, vite } describe('correctly defines isolated flags', async () => { + it('does not merge user-defined poolOptions with itself', async () => { + const c = await config({}, { + poolOptions: { + array: [1, 2, 3], + }, + }) + // Ensure poolOptions.array has not been merged with itself + // Previously, this would have been [1,2,3,1,2,3] + expect(c.poolOptions?.array).toMatchInlineSnapshot(` + [ + 1, + 2, + 3, + ] + `) + }) it('prefers CLI poolOptions flags over config', async () => { const c = await config({ isolate: true, diff --git a/test/run/pool-custom-fixtures/pool/custom-pool.ts b/test/run/pool-custom-fixtures/pool/custom-pool.ts index 31889be91456..84029bb82d61 100644 --- a/test/run/pool-custom-fixtures/pool/custom-pool.ts +++ b/test/run/pool-custom-fixtures/pool/custom-pool.ts @@ -10,6 +10,7 @@ export default (ctx: Vitest): ProcessPool => { name: 'custom', async runTests(specs) { console.warn('[pool] printing:', options.print) + console.warn('[pool] array option', options.array) for await (const [project, file] of specs) { ctx.state.clearFiles(project) const methods = createMethodsRPC(project) diff --git a/test/run/pool-custom-fixtures/vitest.config.ts b/test/run/pool-custom-fixtures/vitest.config.ts index f8af2635f787..180bfc6a3025 100644 --- a/test/run/pool-custom-fixtures/vitest.config.ts +++ b/test/run/pool-custom-fixtures/vitest.config.ts @@ -7,6 +7,7 @@ export default defineConfig({ poolOptions: { custom: { print: 'options are respected', + array: [1, 2, 3], }, }, poolMatchGlobs: [ diff --git a/test/run/test/custom-pool.test.ts b/test/run/test/custom-pool.test.ts index e62b12294008..5dc6f1fc9ea8 100644 --- a/test/run/test/custom-pool.test.ts +++ b/test/run/test/custom-pool.test.ts @@ -6,6 +6,7 @@ test('can run custom pools with Vitest', async () => { expect(vitest.stderr).toMatchInlineSnapshot(` "[pool] printing: options are respected + [pool] array option [ 1, 2, 3 ] [pool] running tests for custom-pool-test in /pool-custom-fixtures/tests/custom-not-run.spec.ts [pool] custom pool is closed! "