[READ-ONLY] Mirror of https://github.com/vitest-dev/vitest. Next generation testing framework powered by Vite. vitest.dev
test testing-tools vite
12

Configure Feed

Select the types of activity you want to include in your feed.

fix(forks): resolve `poolOptions.<name>.isolate` from `forks` options (#5840)

authored by

Ari Perkkiö and committed by
GitHub
(Jun 11, 2024, 5:55 PM +0200) a60a140e fc4514c8

+107 -1
+72
test/config/test/pool-isolation.test.ts
··· 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 + }
+17
test/config/fixtures/pool-isolation/isolated.test.ts
··· 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 + })
+17
test/config/fixtures/pool-isolation/non-isolated.test.ts
··· 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 + })
+1 -1
packages/vitest/src/node/plugins/index.ts
··· 103 103 isolate: options.poolOptions?.threads?.isolate ?? options.isolate ?? testConfig.poolOptions?.threads?.isolate ?? viteConfig.test?.isolate, 104 104 }, 105 105 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, 107 107 }, 108 108 }, 109 109 },