[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(workspace): support overring `pool` and `poolOptions` on project level (#4765)

authored by

Ari Perkkiö and committed by
GitHub
(Jan 9, 2024, 3:43 PM +0100) e9fe4181 508fced9

+212 -13
+7 -7
docs/config/index.md
··· 655 655 - **Type:** `Record<'threads' | 'forks' | 'vmThreads', {}>` 656 656 - **Default:** `{}` 657 657 658 - #### poolOptions.threads<NonProjectOption /> 658 + #### poolOptions.threads 659 659 660 660 Options for `threads` pool. 661 661 ··· 687 687 688 688 Minimum number of threads. You can also use `VITEST_MIN_THREADS` environment variable. 689 689 690 - ##### poolOptions.threads.singleThread<NonProjectOption /> 690 + ##### poolOptions.threads.singleThread 691 691 692 692 - **Type:** `boolean` 693 693 - **Default:** `false` ··· 710 710 711 711 This can improve performance in some cases, but might cause segfault in older Node versions. 712 712 713 - ##### poolOptions.threads.isolate<NonProjectOption /> 713 + ##### poolOptions.threads.isolate 714 714 715 715 - **Type:** `boolean` 716 716 - **Default:** `true` ··· 728 728 Be careful when using, it as some options may crash worker, e.g. --prof, --title. See https://github.com/nodejs/node/issues/41103. 729 729 ::: 730 730 731 - #### poolOptions.forks<NonProjectOption /> 731 + #### poolOptions.forks 732 732 733 733 Options for `forks` pool. 734 734 ··· 760 760 761 761 Minimum number of forks. 762 762 763 - ##### poolOptions.forks.isolate<NonProjectOption /> 763 + ##### poolOptions.forks.isolate 764 764 765 765 - **Type:** `boolean` 766 766 - **Default:** `true` 767 767 768 768 Isolate environment for each test file. 769 769 770 - ##### poolOptions.forks.singleFork<NonProjectOption /> 770 + ##### poolOptions.forks.singleFork 771 771 772 772 - **Type:** `boolean` 773 773 - **Default:** `false` ··· 792 792 Be careful when using, it as some options may crash worker, e.g. --prof, --title. See https://github.com/nodejs/node/issues/41103. 793 793 ::: 794 794 795 - #### poolOptions.vmThreads<NonProjectOption /> 795 + #### poolOptions.vmThreads 796 796 797 797 Options for `vmThreads` pool. 798 798
+90
test/workspaces/vitest.workspace.ts
··· 23 23 }, 24 24 }, 25 25 26 + // Projects testing pool and poolOptions 27 + { 28 + test: { 29 + name: 'Threads pool', 30 + include: [ 31 + './space-pools/threads.test.ts', 32 + './space-pools/multi-worker.test.ts', 33 + './space-pools/isolate.test.ts', 34 + ], 35 + pool: 'threads', 36 + }, 37 + }, 38 + { 39 + test: { 40 + name: 'Single thread pool', 41 + include: [ 42 + './space-pools/threads.test.ts', 43 + './space-pools/single-worker.test.ts', 44 + ], 45 + pool: 'threads', 46 + poolOptions: { threads: { singleThread: true } }, 47 + }, 48 + }, 49 + { 50 + test: { 51 + name: 'Non-isolated thread pool #1', 52 + include: [ 53 + './space-pools/threads.test.ts', 54 + './space-pools/no-isolate.test.ts', 55 + ], 56 + pool: 'threads', 57 + poolOptions: { threads: { isolate: false } }, 58 + }, 59 + }, 60 + { 61 + test: { 62 + name: 'Non-isolated thread pool #2', 63 + include: [ 64 + './space-pools/threads.test.ts', 65 + './space-pools/no-isolate.test.ts', 66 + ], 67 + pool: 'threads', 68 + isolate: false, 69 + }, 70 + }, 71 + { 72 + test: { 73 + name: 'Forks pool', 74 + include: [ 75 + './space-pools/forks.test.ts', 76 + './space-pools/multi-worker.test.ts', 77 + './space-pools/isolate.test.ts', 78 + ], 79 + pool: 'forks', 80 + }, 81 + }, 82 + { 83 + test: { 84 + name: 'Single fork pool', 85 + include: [ 86 + './space-pools/forks.test.ts', 87 + './space-pools/single-worker.test.ts', 88 + ], 89 + pool: 'forks', 90 + poolOptions: { forks: { singleFork: true } }, 91 + }, 92 + }, 93 + { 94 + test: { 95 + name: 'Non-isolated fork pool #1', 96 + include: [ 97 + './space-pools/forks.test.ts', 98 + './space-pools/no-isolate.test.ts', 99 + ], 100 + pool: 'forks', 101 + poolOptions: { forks: { isolate: false } }, 102 + }, 103 + }, 104 + { 105 + test: { 106 + name: 'Non-isolated fork pool #2', 107 + include: [ 108 + './space-pools/forks.test.ts', 109 + './space-pools/no-isolate.test.ts', 110 + ], 111 + pool: 'forks', 112 + isolate: false, 113 + }, 114 + }, 115 + 26 116 // These two projects run on same environment but still transform 27 117 // a single file differently due to Vite plugins 28 118 {
+8 -3
test/config/test/config-types.test-d.ts
··· 9 9 expectProjectTestConfig.toHaveProperty('name') 10 10 expectMainTestConfig.toHaveProperty('name') 11 11 12 - expectProjectTestConfig.not.toHaveProperty('pool') 13 - expectMainTestConfig.toHaveProperty('pool') 14 - 15 12 expectProjectTestConfig.not.toHaveProperty('coverage') 16 13 expectMainTestConfig.toHaveProperty('coverage') 14 + 15 + expectProjectTestConfig.not.toHaveProperty('reporters') 16 + expectMainTestConfig.toHaveProperty('reporters') 17 + }) 18 + 19 + test('allows expected project fields on a project config', () => { 20 + expectProjectTestConfig.toHaveProperty('pool') 21 + expectProjectTestConfig.toHaveProperty('poolOptions') 17 22 }) 18 23 }) 19 24
+12
test/workspaces/space-pools/forks.test.ts
··· 1 + import { isMainThread } from 'node:worker_threads' 2 + import { expect, test } from 'vitest' 3 + 4 + test('is run in "node:child_process"', () => { 5 + expect(isChildProcess()).toBe(true) 6 + expect(isMainThread).toBe(true) 7 + }) 8 + 9 + // TODO: Use from "src/utils/base.ts" after #4441 10 + function isChildProcess(): boolean { 11 + return !!process?.send 12 + }
+15
test/workspaces/space-pools/isolate.test.ts
··· 1 + import { expect, test } from 'vitest' 2 + import type { UserConfig } from 'vitest/config' 3 + 4 + test('is isolated', () => { 5 + // @ts-expect-error -- internal 6 + const config: NonNullable<UserConfig['test']> = globalThis.__vitest_worker__.config 7 + 8 + if (config.pool === 'forks') { 9 + expect(config.poolOptions?.forks?.isolate).toBe(true) 10 + } 11 + else { 12 + expect(config.pool).toBe('threads') 13 + expect(config.poolOptions?.threads?.isolate).toBe(true) 14 + } 15 + })
+15
test/workspaces/space-pools/multi-worker.test.ts
··· 1 + import { expect, test } from 'vitest' 2 + import type { UserConfig } from 'vitest/config' 3 + 4 + test('is multi worker', () => { 5 + // @ts-expect-error -- internal 6 + const config: NonNullable<UserConfig['test']> = globalThis.__vitest_worker__.config 7 + 8 + if (config.pool === 'forks') { 9 + expect(config.poolOptions?.forks?.singleFork).toBe(false) 10 + } 11 + else { 12 + expect(config.pool).toBe('threads') 13 + expect(config.poolOptions?.threads?.singleThread).toBe(false) 14 + } 15 + })
+15
test/workspaces/space-pools/no-isolate.test.ts
··· 1 + import { expect, test } from 'vitest' 2 + import type { UserConfig } from 'vitest/config' 3 + 4 + test('is not isolated', () => { 5 + // @ts-expect-error -- internal 6 + const config: NonNullable<UserConfig['test']> = globalThis.__vitest_worker__.config 7 + 8 + if (config.pool === 'forks') { 9 + expect(config.poolOptions?.forks?.isolate).toBe(false) 10 + } 11 + else { 12 + expect(config.pool).toBe('threads') 13 + expect(config.poolOptions?.threads?.isolate).toBe(false) 14 + } 15 + })
+15
test/workspaces/space-pools/single-worker.test.ts
··· 1 + import { expect, test } from 'vitest' 2 + import type { UserConfig } from 'vitest/config' 3 + 4 + test('is single worker', () => { 5 + // @ts-expect-error -- internal 6 + const config: NonNullable<UserConfig['test']> = globalThis.__vitest_worker__.config 7 + 8 + if (config.pool === 'forks') { 9 + expect(config.poolOptions?.forks?.singleFork).toBe(true) 10 + } 11 + else { 12 + expect(config.pool).toBe('threads') 13 + expect(config.poolOptions?.threads?.singleThread).toBe(true) 14 + } 15 + })
+12
test/workspaces/space-pools/threads.test.ts
··· 1 + import { isMainThread } from 'node:worker_threads' 2 + import { expect, test } from 'vitest' 3 + 4 + test('is run in "node:worker_threads"', () => { 5 + expect(isChildProcess()).toBe(false) 6 + expect(isMainThread).toBe(false) 7 + }) 8 + 9 + // TODO: Use from "src/utils/base.ts" after #4441 10 + function isChildProcess(): boolean { 11 + return !!process?.send 12 + }
+18 -2
packages/vitest/src/node/workspace.ts
··· 319 319 320 320 getSerializableConfig() { 321 321 const optimizer = this.config.deps?.optimizer 322 + const poolOptions = this.config.poolOptions 323 + 324 + // Resolve from server.config to avoid comparing against default value 325 + const isolate = this.server?.config?.test?.isolate 326 + 322 327 return deepMerge({ 323 328 ...this.config, 324 329 coverage: this.ctx.config.coverage, 325 330 326 - pool: this.ctx.config.pool, 327 - poolOptions: this.ctx.config.poolOptions, 331 + poolOptions: { 332 + forks: { 333 + singleFork: poolOptions?.forks?.singleFork ?? this.ctx.config.poolOptions?.forks?.singleFork ?? false, 334 + isolate: poolOptions?.forks?.isolate ?? isolate ?? this.ctx.config.poolOptions?.forks?.isolate ?? true, 335 + }, 336 + threads: { 337 + singleThread: poolOptions?.threads?.singleThread ?? this.ctx.config.poolOptions?.threads?.singleThread ?? false, 338 + isolate: poolOptions?.threads?.isolate ?? isolate ?? this.ctx.config.poolOptions?.threads?.isolate ?? true, 339 + }, 340 + vmThreads: { 341 + singleThread: poolOptions?.vmThreads?.singleThread ?? this.ctx.config.poolOptions?.vmThreads?.singleThread ?? false, 342 + }, 343 + }, 328 344 329 345 reporters: [], 330 346 deps: {
+5 -1
packages/vitest/src/types/config.ts
··· 817 817 | 'update' 818 818 | 'reporters' 819 819 | 'outputFile' 820 - | 'pool' 821 820 | 'poolOptions' 822 821 | 'teardownTimeout' 823 822 | 'silent' ··· 842 841 > & { 843 842 sequencer?: Omit<SequenceOptions, 'sequencer' | 'seed'> 844 843 deps?: Omit<DepsOptions, 'moduleDirectories'> 844 + poolOptions?: { 845 + threads?: Pick<NonNullable<PoolOptions['threads']>, 'singleThread' | 'isolate'> 846 + vmThreads?: Pick<NonNullable<PoolOptions['vmThreads']>, 'singleThread'> 847 + forks?: Pick<NonNullable<PoolOptions['forks']>, 'singleFork' | 'isolate'> 848 + } 845 849 } 846 850 847 851 export type RuntimeConfig = Pick<