Skip to content

Commit bc5b2d0

Browse files
authoredFeb 16, 2024··
fix: Prevent merging of poolOptions (#5221)
1 parent df6182d commit bc5b2d0

File tree

5 files changed

+27
-8
lines changed

5 files changed

+27
-8
lines changed
 

‎packages/vitest/src/node/plugins/index.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,6 @@ export async function VitestPlugin(options: UserConfig = {}, ctx = new Vitest('t
5050
)
5151
testConfig.api = resolveApiServerConfig(testConfig)
5252

53-
testConfig.poolOptions ??= {}
54-
testConfig.poolOptions.threads ??= {}
55-
testConfig.poolOptions.forks ??= {}
56-
// prefer --poolOptions.{name}.isolate CLI arguments over --isolate, but still respect config value
57-
testConfig.poolOptions.threads.isolate = options.poolOptions?.threads?.isolate ?? options.isolate ?? testConfig.poolOptions.threads.isolate ?? viteConfig.test?.isolate
58-
testConfig.poolOptions.forks.isolate = options.poolOptions?.forks?.isolate ?? options.isolate ?? testConfig.poolOptions.forks.isolate ?? viteConfig.test?.isolate
59-
6053
// store defines for globalThis to make them
6154
// reassignable when running in worker in src/runtime/setup.ts
6255
const defines: Record<string, any> = deleteDefineConfig(viteConfig)
@@ -98,7 +91,14 @@ export async function VitestPlugin(options: UserConfig = {}, ctx = new Vitest('t
9891
},
9992
},
10093
test: {
101-
poolOptions: testConfig.poolOptions,
94+
poolOptions: {
95+
threads: {
96+
isolate: options.poolOptions?.threads?.isolate ?? options.isolate ?? testConfig.poolOptions?.threads?.isolate ?? viteConfig.test?.isolate,
97+
},
98+
forks: {
99+
isolate: options.poolOptions?.threads?.isolate ?? options.isolate ?? testConfig.poolOptions?.threads?.isolate ?? viteConfig.test?.isolate,
100+
},
101+
},
102102
},
103103
}
104104

‎test/config/test/resolution.test.ts

+16
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,22 @@ async function config(cliOptions: UserConfig, configValue: UserConfig = {}, vite
1515
}
1616

1717
describe('correctly defines isolated flags', async () => {
18+
it('does not merge user-defined poolOptions with itself', async () => {
19+
const c = await config({}, {
20+
poolOptions: {
21+
array: [1, 2, 3],
22+
},
23+
})
24+
// Ensure poolOptions.array has not been merged with itself
25+
// Previously, this would have been [1,2,3,1,2,3]
26+
expect(c.poolOptions?.array).toMatchInlineSnapshot(`
27+
[
28+
1,
29+
2,
30+
3,
31+
]
32+
`)
33+
})
1834
it('prefers CLI poolOptions flags over config', async () => {
1935
const c = await config({
2036
isolate: true,

‎test/run/pool-custom-fixtures/pool/custom-pool.ts

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export default (ctx: Vitest): ProcessPool => {
1010
name: 'custom',
1111
async runTests(specs) {
1212
console.warn('[pool] printing:', options.print)
13+
console.warn('[pool] array option', options.array)
1314
for await (const [project, file] of specs) {
1415
ctx.state.clearFiles(project)
1516
const methods = createMethodsRPC(project)

‎test/run/pool-custom-fixtures/vitest.config.ts

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export default defineConfig({
77
poolOptions: {
88
custom: {
99
print: 'options are respected',
10+
array: [1, 2, 3],
1011
},
1112
},
1213
poolMatchGlobs: [

‎test/run/test/custom-pool.test.ts

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ test('can run custom pools with Vitest', async () => {
66

77
expect(vitest.stderr).toMatchInlineSnapshot(`
88
"[pool] printing: options are respected
9+
[pool] array option [ 1, 2, 3 ]
910
[pool] running tests for custom-pool-test in /pool-custom-fixtures/tests/custom-not-run.spec.ts
1011
[pool] custom pool is closed!
1112
"

0 commit comments

Comments
 (0)
Please sign in to comment.