Skip to content

Commit a60a140

Browse files
authored
fix(forks): resolve poolOptions.<name>.isolate from forks options (#5840)
1 parent fc4514c commit a60a140

File tree

4 files changed

+107
-1
lines changed

4 files changed

+107
-1
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ export async function VitestPlugin(options: UserConfig = {}, ctx = new Vitest('t
103103
isolate: options.poolOptions?.threads?.isolate ?? options.isolate ?? testConfig.poolOptions?.threads?.isolate ?? viteConfig.test?.isolate,
104104
},
105105
forks: {
106-
isolate: options.poolOptions?.threads?.isolate ?? options.isolate ?? testConfig.poolOptions?.threads?.isolate ?? viteConfig.test?.isolate,
106+
isolate: options.poolOptions?.forks?.isolate ?? options.isolate ?? testConfig.poolOptions?.forks?.isolate ?? viteConfig.test?.isolate,
107107
},
108108
},
109109
},
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { expect, test } from 'vitest'
2+
import type { UserConfig } from 'vitest/config'
3+
4+
const pool = process.env.TESTED_POOL as "forks" | "threads";
5+
6+
test('is isolated', () => {
7+
// @ts-expect-error -- internal
8+
const config: NonNullable<UserConfig['test']> = globalThis.__vitest_worker__.config
9+
10+
if (pool === 'forks') {
11+
expect(config.poolOptions?.forks?.isolate).toBe(true)
12+
}
13+
else {
14+
expect(pool).toBe('threads')
15+
expect(config.poolOptions?.threads?.isolate).toBe(true)
16+
}
17+
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { expect, test } from 'vitest'
2+
import type { UserConfig } from 'vitest/config'
3+
4+
const pool = process.env.TESTED_POOL as "forks" | "threads";
5+
6+
test('is isolated', () => {
7+
// @ts-expect-error -- internal
8+
const config: NonNullable<UserConfig['test']> = globalThis.__vitest_worker__.config
9+
10+
if (pool === 'forks') {
11+
expect(config.poolOptions?.forks?.isolate).toBe(false)
12+
}
13+
else {
14+
expect(pool).toBe('threads')
15+
expect(config.poolOptions?.threads?.isolate).toBe(false)
16+
}
17+
})
+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import { describe, expect, test } from 'vitest'
2+
import { runVitest } from '../../test-utils'
3+
4+
describe.each(['forks', 'threads'] as const)('%s', async (pool) => {
5+
test('is isolated', async () => {
6+
const { stderr, exitCode } = await runVitest({
7+
root: './fixtures/pool-isolation',
8+
include: ['isolated.test.ts'],
9+
pool,
10+
poolOptions: {
11+
// Use default value on the tested pool and disable on the other one
12+
[invertPool(pool)]: { isolate: false },
13+
},
14+
env: { TESTED_POOL: pool },
15+
})
16+
17+
expect(stderr).toBe('')
18+
expect(exitCode).toBe(0)
19+
})
20+
21+
test('is isolated + poolMatchGlobs', async () => {
22+
const { stderr, exitCode } = await runVitest({
23+
root: './fixtures/pool-isolation',
24+
include: ['isolated.test.ts'],
25+
pool,
26+
poolMatchGlobs: [['**', pool]],
27+
poolOptions: {
28+
// Use default value on the tested pool and disable on the other one
29+
[invertPool(pool)]: { isolate: false },
30+
},
31+
env: { TESTED_POOL: pool },
32+
})
33+
34+
expect(stderr).toBe('')
35+
expect(exitCode).toBe(0)
36+
})
37+
38+
test('is not isolated', async () => {
39+
const { stderr, exitCode } = await runVitest({
40+
root: './fixtures/pool-isolation',
41+
include: ['non-isolated.test.ts'],
42+
pool,
43+
poolOptions: {
44+
[pool]: { isolate: false },
45+
},
46+
env: { TESTED_POOL: pool },
47+
})
48+
49+
expect(stderr).toBe('')
50+
expect(exitCode).toBe(0)
51+
})
52+
53+
test('is not isolated + poolMatchGlobs', async () => {
54+
const { stderr, exitCode } = await runVitest({
55+
root: './fixtures/pool-isolation',
56+
include: ['non-isolated.test.ts'],
57+
pool: invertPool(pool),
58+
poolMatchGlobs: [['**/**.test.ts', pool]],
59+
poolOptions: {
60+
[pool]: { isolate: false },
61+
},
62+
env: { TESTED_POOL: pool },
63+
})
64+
65+
expect(stderr).toBe('')
66+
expect(exitCode).toBe(0)
67+
})
68+
})
69+
70+
function invertPool(pool: 'threads' | 'forks') {
71+
return pool === 'threads' ? 'forks' : 'threads'
72+
}

0 commit comments

Comments
 (0)