Skip to content

Commit

Permalink
fix(forks): resolve poolOptions.<name>.isolate from forks options (
Browse files Browse the repository at this point in the history
  • Loading branch information
AriPerkkio authored Jun 11, 2024
1 parent fc4514c commit a60a140
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/vitest/src/node/plugins/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export async function VitestPlugin(options: UserConfig = {}, ctx = new Vitest('t
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,
isolate: options.poolOptions?.forks?.isolate ?? options.isolate ?? testConfig.poolOptions?.forks?.isolate ?? viteConfig.test?.isolate,
},
},
},
Expand Down
17 changes: 17 additions & 0 deletions test/config/fixtures/pool-isolation/isolated.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { expect, test } from 'vitest'
import type { UserConfig } from 'vitest/config'

const pool = process.env.TESTED_POOL as "forks" | "threads";

test('is isolated', () => {
// @ts-expect-error -- internal
const config: NonNullable<UserConfig['test']> = globalThis.__vitest_worker__.config

if (pool === 'forks') {
expect(config.poolOptions?.forks?.isolate).toBe(true)
}
else {
expect(pool).toBe('threads')
expect(config.poolOptions?.threads?.isolate).toBe(true)
}
})
17 changes: 17 additions & 0 deletions test/config/fixtures/pool-isolation/non-isolated.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { expect, test } from 'vitest'
import type { UserConfig } from 'vitest/config'

const pool = process.env.TESTED_POOL as "forks" | "threads";

test('is isolated', () => {
// @ts-expect-error -- internal
const config: NonNullable<UserConfig['test']> = globalThis.__vitest_worker__.config

if (pool === 'forks') {
expect(config.poolOptions?.forks?.isolate).toBe(false)
}
else {
expect(pool).toBe('threads')
expect(config.poolOptions?.threads?.isolate).toBe(false)
}
})
72 changes: 72 additions & 0 deletions test/config/test/pool-isolation.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { describe, expect, test } from 'vitest'
import { runVitest } from '../../test-utils'

describe.each(['forks', 'threads'] as const)('%s', async (pool) => {
test('is isolated', async () => {
const { stderr, exitCode } = await runVitest({
root: './fixtures/pool-isolation',
include: ['isolated.test.ts'],
pool,
poolOptions: {
// Use default value on the tested pool and disable on the other one
[invertPool(pool)]: { isolate: false },
},
env: { TESTED_POOL: pool },
})

expect(stderr).toBe('')
expect(exitCode).toBe(0)
})

test('is isolated + poolMatchGlobs', async () => {
const { stderr, exitCode } = await runVitest({
root: './fixtures/pool-isolation',
include: ['isolated.test.ts'],
pool,
poolMatchGlobs: [['**', pool]],
poolOptions: {
// Use default value on the tested pool and disable on the other one
[invertPool(pool)]: { isolate: false },
},
env: { TESTED_POOL: pool },
})

expect(stderr).toBe('')
expect(exitCode).toBe(0)
})

test('is not isolated', async () => {
const { stderr, exitCode } = await runVitest({
root: './fixtures/pool-isolation',
include: ['non-isolated.test.ts'],
pool,
poolOptions: {
[pool]: { isolate: false },
},
env: { TESTED_POOL: pool },
})

expect(stderr).toBe('')
expect(exitCode).toBe(0)
})

test('is not isolated + poolMatchGlobs', async () => {
const { stderr, exitCode } = await runVitest({
root: './fixtures/pool-isolation',
include: ['non-isolated.test.ts'],
pool: invertPool(pool),
poolMatchGlobs: [['**/**.test.ts', pool]],
poolOptions: {
[pool]: { isolate: false },
},
env: { TESTED_POOL: pool },
})

expect(stderr).toBe('')
expect(exitCode).toBe(0)
})
})

function invertPool(pool: 'threads' | 'forks') {
return pool === 'threads' ? 'forks' : 'threads'
}

0 comments on commit a60a140

Please sign in to comment.