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

docs: add "improving performance" to guide list (#4779)

authored by

Vladimir and committed by
GitHub
(Dec 28, 2023, 4:53 PM +0100) 578db5e3 06c14f7d

+56 -52
+4
docs/.vitepress/config.ts
··· 233 233 text: 'Common Errors', 234 234 link: '/guide/common-errors', 235 235 }, 236 + { 237 + text: 'Improving Performance', 238 + link: '/guide/improving-performance', 239 + }, 236 240 ], 237 241 }, 238 242 {
+1 -1
docs/config/index.md
··· 2076 2076 2077 2077 Run tests in an isolated environment. This option has no effect on `vmThreads` pool. 2078 2078 2079 - Disabling this option might improve [performance](/guide/performance) if your code doesn't rely on side effects (which is usually true for projects with `node` environment). 2079 + Disabling this option might [improve performance](/guide/improving-performance) if your code doesn't rely on side effects (which is usually true for projects with `node` environment). 2080 2080 2081 2081 ::: note 2082 2082 You can disable isolation for specific pools by using [`poolOptions`](#pooloptions) property.
+51
docs/guide/improving-performance.md
··· 1 + # Improving Performance 2 + 3 + By default Vitest runs every test file in an isolated environment based on the [pool](/config/#pool): 4 + 5 + - `threads` pool runs every test file in a separate [`Worker`](https://nodejs.org/api/worker_threads.html#class-worker) 6 + - `forks` pool runs every test file in a separate [forked child process](https://nodejs.org/api/child_process.html#child_processforkmodulepath-args-options) 7 + - `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 8 + 9 + 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. 10 + 11 + ::: code-group 12 + ```bash [CLI] 13 + vitest --no-isolate 14 + ``` 15 + ```ts [vitest.config.js] 16 + import { defineConfig } from 'vitest/config' 17 + 18 + export default defineConfig({ 19 + test: { 20 + isolate: false, 21 + // you can also disable isolation only for specific pools 22 + poolOptions: { 23 + forks: { 24 + isolate: false, 25 + }, 26 + }, 27 + }, 28 + }) 29 + ``` 30 + ::: 31 + 32 + ::: note 33 + If you are using `vmThreads` pool, you cannot disable isolation. Use `threads` pool instead to improve your tests performance. 34 + ::: 35 + 36 + For some projects, it might also be desirable to disable parallelism to improve startup time. To do that, provide `--no-file-parallelism` flag to the CLI or set [`test.fileParallelism`](/config/#fileParallelism) property in the config to `false`. 37 + 38 + ::: code-group 39 + ```bash [CLI] 40 + vitest --no-file-parallelism 41 + ``` 42 + ```ts [vitest.config.js] 43 + import { defineConfig } from 'vitest/config' 44 + 45 + export default defineConfig({ 46 + test: { 47 + fileParallelism: false, 48 + }, 49 + }) 50 + ``` 51 + :::
-51
docs/guide/performance.md
··· 1 - # Performance 2 - 3 - By default Vitest runs every test file in an isolated environment based on the [pool](/config/#pool): 4 - 5 - - `threads` pool runs every test file in a separate [`Worker`](https://nodejs.org/api/worker_threads.html#class-worker) 6 - - `forks` pool runs every test file in a separate [forked child process](https://nodejs.org/api/child_process.html#child_processforkmodulepath-args-options) 7 - - `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 8 - 9 - 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. 10 - 11 - ::: code-group 12 - ```bash [CLI] 13 - vitest --no-isolate 14 - ``` 15 - ```ts [vitest.config.js] 16 - import { defineConfig } from 'vitest/config' 17 - 18 - export default defineConfig({ 19 - test: { 20 - isolate: false, 21 - // you can also disable isolation only for specific pools 22 - poolOptions: { 23 - forks: { 24 - isolate: false, 25 - }, 26 - }, 27 - }, 28 - }) 29 - ``` 30 - ::: 31 - 32 - ::: note 33 - If you are using `vmThreads` pool, you cannot disable isolation. Use `threads` pool instead to improve your tests performance. 34 - ::: 35 - 36 - For some projects, it might also be desirable to disable parallelism to improve startup time. To do that, provide `--no-file-parallelism` flag to the CLI or set [`test.fileParallelism`](/config/#fileParallelism) property in the config to `false`. 37 - 38 - ::: code-group 39 - ```bash [CLI] 40 - vitest --no-file-parallelism 41 - ``` 42 - ```ts [vitest.config.js] 43 - import { defineConfig } from 'vitest/config' 44 - 45 - export default defineConfig({ 46 - test: { 47 - fileParallelism: false, 48 - }, 49 - }) 50 - ``` 51 - :::