[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.

refactor: deprecate `environmentMatchGlobs` and `poolMatchGlobs` in favor of workspace (#6922)

authored by

Vladimir and committed by
GitHub
(Dec 1, 2024, 11:17 PM +0100) 98c7e519 fe2a187f

+112 -14
+21 -4
docs/advanced/pool.md
··· 14 14 15 15 You can provide your own pool by specifying a file path: 16 16 17 - ```ts 17 + ```ts [vitest.config.ts] 18 18 import { defineConfig } from 'vitest/config' 19 19 20 20 export default defineConfig({ ··· 27 27 customProperty: true, 28 28 }, 29 29 }, 30 - // you can also specify pool for a subset of files 31 - poolMatchGlobs: [ 32 - ['**/*.custom.test.ts', './my-custom-pool.ts'], 30 + }, 31 + }) 32 + ``` 33 + 34 + If you need to run tests in different pools, use the [workspace](/guide/workspace) feature: 35 + 36 + ```ts [vitest.config.ts] 37 + export default defineConfig({ 38 + test: { 39 + workspace: [ 40 + { 41 + extends: true, 42 + test: { 43 + pool: 'threads', 44 + }, 45 + }, 33 46 ], 34 47 }, 35 48 }) 36 49 ``` 50 + 51 + ::: info 52 + The `workspace` field was introduced in Vitest 2.2. To define a workspace in Vitest <2.2, create a separate `vitest.workspace.ts` file. 53 + ::: 37 54 38 55 ## API 39 56
+45 -1
docs/config/index.md
··· 581 581 - **Type:** `[string, EnvironmentName][]` 582 582 - **Default:** `[]` 583 583 584 + ::: warning 585 + This API was deprecated in Vitest 2.2. Use [workspace](/guide/workspace) to define different configurations instead. 586 + 587 + ```ts 588 + export default defineConfig({ 589 + test: { 590 + environmentMatchGlobs: [ // [!code --] 591 + ['./*.jsdom.test.ts', 'jsdom'], // [!code --] 592 + ], // [!code --] 593 + workspace: [ // [!code ++] 594 + { // [!code ++] 595 + extends: true, // [!code ++] 596 + test: { // [!code ++] 597 + environment: 'jsdom', // [!code ++] 598 + }, // [!code ++] 599 + }, // [!code ++] 600 + ], // [!code ++] 601 + }, 602 + }) 603 + ``` 604 + ::: 605 + 584 606 Automatically assign environment based on globs. The first match will be used. 585 607 586 608 For example: ··· 605 627 606 628 - **Type:** `[string, 'threads' | 'forks' | 'vmThreads' | 'vmForks' | 'typescript'][]` 607 629 - **Default:** `[]` 630 + 631 + ::: warning 632 + This API was deprecated in Vitest 2.2. Use [workspace](/guide/workspace) to define different configurations instead: 633 + 634 + ```ts 635 + export default defineConfig({ 636 + test: { 637 + poolMatchGlobs: [ // [!code --] 638 + ['./*.threads.test.ts', 'threads'], // [!code --] 639 + ], // [!code --] 640 + workspace: [ // [!code ++] 641 + { // [!code ++] 642 + test: { // [!code ++] 643 + extends: true, // [!code ++] 644 + pool: 'threads', // [!code ++] 645 + }, // [!code ++] 646 + }, // [!code ++] 647 + ], // [!code ++] 648 + }, 649 + }) 650 + ``` 651 + ::: 608 652 609 653 Automatically assign pool in which tests will run based on globs. The first match will be used. 610 654 ··· 1713 1757 - **Default:** `false` 1714 1758 - **CLI:** `--browser`, `--browser.enabled=false` 1715 1759 1716 - Run all tests inside a browser by default. Can be overridden with [`poolMatchGlobs`](#poolmatchglobs) option. 1760 + Run all tests inside a browser by default. 1717 1761 1718 1762 #### browser&#46;name 1719 1763
+1 -1
docs/guide/improving-performance.md
··· 8 8 - `forks` pool runs every test file in a separate [forked child process](https://nodejs.org/api/child_process.html#child_processforkmodulepath-args-options) 9 9 - `vmThreads` pool runs every test file in a separate [VM context](https://nodejs.org/api/vm.html#vmcreatecontextcontextobject-options), but it uses workers for parallelism 10 10 11 - This greatly increases test times, which might not be desirable for projects that don't rely on side effects and properly cleanup their state (which is usually true for projects with `node` environment). In this case disabling isolation will improve the speed of your tests. To do that, you can provide `--no-isolate` flag to the CLI or set [`test.isolate`](/config/#isolate) property in the config to `false`. If you are using several pools at once with `poolMatchGlobs`, you can also disable isolation for a specific pool you are using. 11 + This greatly increases test times, which might not be desirable for projects that don't rely on side effects and properly cleanup their state (which is usually true for projects with `node` environment). In this case disabling isolation will improve the speed of your tests. To do that, you can provide `--no-isolate` flag to the CLI or set [`test.isolate`](/config/#isolate) property in the config to `false`. 12 12 13 13 ::: code-group 14 14 ```bash [CLI]
+1 -1
test/cli/test/custom-pool.test.ts
··· 16 16 `) 17 17 18 18 expect(vitest.stdout).toContain('✓ |custom-pool-test| tests/custom-not-run.spec.ts') 19 - expect(vitest.stdout).toContain('✓ |custom-pool-test| tests/custom-run.threads.spec.ts') 19 + expect(vitest.stdout).toContain('✓ |threads-pool-test| tests/custom-run.threads.spec.ts') 20 20 expect(vitest.stdout).toContain('Test Files 2 passed') 21 21 expect(vitest.stdout).toContain('Tests 2 passed') 22 22 })
+6 -2
test/config/test/pool-isolation.test.ts
··· 31 31 env: { TESTED_POOL: pool }, 32 32 }) 33 33 34 - expect(stderr).toBe('') 34 + expect(stderr).toBe(deprecatedPoolMatchGlob()) 35 35 expect(exitCode).toBe(0) 36 36 }) 37 37 ··· 62 62 env: { TESTED_POOL: pool }, 63 63 }) 64 64 65 - expect(stderr).toBe('') 65 + expect(stderr).toBe(deprecatedPoolMatchGlob()) 66 66 expect(exitCode).toBe(0) 67 67 }) 68 68 }) 69 69 70 70 function invertPool(pool: 'threads' | 'forks') { 71 71 return pool === 'threads' ? 'forks' : 'threads' 72 + } 73 + 74 + function deprecatedPoolMatchGlob() { 75 + return ' Vitest "poolMatchGlobs" is deprecated. Use "workspace" to define different configurations instead.\n' 72 76 }
+18 -5
test/cli/fixtures/custom-pool/vitest.config.ts
··· 2 2 3 3 export default defineConfig({ 4 4 test: { 5 - name: 'custom-pool-test', 6 - pool: './pool/custom-pool.ts', 7 5 poolOptions: { 8 6 custom: { 9 7 print: 'options are respected', 10 8 array: [1, 2, 3], 11 9 }, 12 10 }, 13 - poolMatchGlobs: [ 14 - ['**/*.threads.spec.ts', 'threads'], 15 - ], 11 + workspace: [ 12 + { 13 + extends: true, 14 + test: { 15 + name: 'custom-pool-test', 16 + pool: './pool/custom-pool.ts', 17 + exclude: ['**/*.threads.spec.ts'], 18 + }, 19 + }, 20 + { 21 + extends: true, 22 + test: { 23 + name: 'threads-pool-test', 24 + include: ['**/*.threads.spec.ts'], 25 + pool: 'threads', 26 + }, 27 + }, 28 + ] 16 29 }, 17 30 })
+18
packages/vitest/src/node/config/resolveConfig.ts
··· 532 532 if (!builtinPools.includes(resolved.pool as BuiltinPool)) { 533 533 resolved.pool = resolvePath(resolved.pool, resolved.root) 534 534 } 535 + if (resolved.poolMatchGlobs) { 536 + logger.warn( 537 + c.yellow( 538 + `${c.inverse( 539 + c.yellow(' Vitest '), 540 + )} "poolMatchGlobs" is deprecated. Use "workspace" to define different configurations instead.`, 541 + ), 542 + ) 543 + } 535 544 resolved.poolMatchGlobs = (resolved.poolMatchGlobs || []).map( 536 545 ([glob, pool]) => { 537 546 if (!builtinPools.includes(pool as BuiltinPool)) { ··· 725 734 ...resolved.typecheck, 726 735 } 727 736 737 + if (resolved.environmentMatchGlobs) { 738 + logger.warn( 739 + c.yellow( 740 + `${c.inverse( 741 + c.yellow(' Vitest '), 742 + )} "environmentMatchGlobs" is deprecated. Use "workspace" to define different configurations instead.`, 743 + ), 744 + ) 745 + } 728 746 resolved.environmentMatchGlobs = (resolved.environmentMatchGlobs || []).map( 729 747 i => [resolve(resolved.root, i[0]), i[1]], 730 748 )
+2
packages/vitest/src/node/types/config.ts
··· 314 314 * 315 315 * Format: [glob, environment-name] 316 316 * 317 + * @deprecated use [`workspace`](https://vitest.dev/config/#environmentmatchglobs) instead 317 318 * @default [] 318 319 * @example [ 319 320 * // all tests in tests/dom will run in jsdom ··· 370 371 * 371 372 * Format: [glob, pool-name] 372 373 * 374 + * @deprecated use [`workspace`](https://vitest.dev/config/#poolmatchglobs) instead 373 375 * @default [] 374 376 * @example [ 375 377 * // all tests in "forks" directory will run using "poolOptions.forks" API