You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Enable multi-threading using [tinypool](https://github.com/tinylibs/tinypool) (a lightweight fork of [Piscina](https://github.com/piscinajs/piscina)). When using threads you are unable to use process related APIs such as `process.chdir()`. Some libraries written in native languages, such as Prisma, `bcrypt` and `canvas`, have problems when running in multiple threads and run into segfaults. In these cases it is adviced to use `forks` pool instead.
629
636
630
-
Run tests using [VM context](https://nodejs.org/api/vm.html) (inside a sandboxed environment) in a worker pool.
637
+
#### forks<NonProjectOption />
631
638
632
-
This makes tests run faster, but the VM module is unstable when running [ESM code](https://github.com/nodejs/node/issues/37648). Your tests will [leak memory](https://github.com/nodejs/node/issues/33439) - to battle that, consider manually editing [`experimentalVmWorkerMemoryLimit`](#experimentalvmworkermemorylimit) value.
639
+
Similar as `threads` pool but uses `child_process` instead of `worker_threads` via [tinypool](https://github.com/tinylibs/tinypool). Communication between tests and main process is not as fast as with `threads` pool. Process related APIs such as `process.chdir()` are available in `forks` pool.
640
+
641
+
#### vmThreads<NonProjectOption />
642
+
643
+
Run tests using [VM context](https://nodejs.org/api/vm.html) (inside a sandboxed environment) in a `threads` pool.
644
+
645
+
This makes tests run faster, but the VM module is unstable when running [ESM code](https://github.com/nodejs/node/issues/37648). Your tests will [leak memory](https://github.com/nodejs/node/issues/33439) - to battle that, consider manually editing [`poolOptions.vmThreads.memoryLimit`](#pooloptions-vmthreads-memorylimit) value.
633
646
634
647
::: warning
635
648
Running code in a sandbox has some advantages (faster tests), but also comes with a number of disadvantages.
@@ -651,83 +664,192 @@ catch (err) {
651
664
Please, be aware of these issues when using this option. Vitest team cannot fix any of the issues on our side.
Specifies the memory limit for workers before they are recycled. This value heavily depends on your environment, so it's better to specify it manually instead of relying on the default.
673
+
#### poolOptions.threads<NonProjectOption />
662
674
663
-
This option only affects workers that run tests in [VM context](#experimentalvmthreads).
675
+
Options for `threads` pool.
664
676
665
-
::: tip
666
-
The implementation is based on Jest's [`workerIdleMemoryLimit`](https://jestjs.io/docs/configuration#workeridlememorylimit-numberstring).
677
+
```ts
678
+
import { defineConfig } from'vitest/config'
667
679
668
-
The limit can be specified in a number of different ways and whatever the result is `Math.floor` is used to turn it into an integer value:
680
+
exportdefaultdefineConfig({
681
+
test: {
682
+
poolOptions: {
683
+
threads: {
684
+
// Threads related options here
685
+
}
686
+
}
687
+
}
688
+
})
689
+
```
669
690
670
-
-`<= 1` - The value is assumed to be a percentage of system memory. So 0.5 sets the memory limit of the worker to half of the total system memory
671
-
-`\> 1` - Assumed to be a fixed byte value. Because of the previous rule if you wanted a value of 1 byte (I don't know why) you could use 1.1.
672
-
- With units
673
-
-`50%` - As above, a percentage of total system memory
674
-
-`100KB`, `65MB`, etc - With units to denote a fixed memory limit.
Percentage based memory limit [does not work on Linux CircleCI](https://github.com/jestjs/jest/issues/11956#issuecomment-1212925677) workers due to incorrect system memory being reported.
693
+
-**Type:**`number`
694
+
-**Default:**_available CPUs_
695
+
696
+
Maximum number of threads. You can also use `VITEST_MAX_THREADS` environment variable.
Run all tests with the same environment inside a single worker thread. This will disable built-in module isolation (your source code or [inlined](#deps-inline) code will still be reevaluated for each test), but can improve test performance.
711
+
712
+
713
+
:::warning
714
+
Even though this option will force tests to run one after another, this option is different from Jest's `--runInBand`. Vitest uses workers not only for running tests in parallel, but also to provide isolation. By disabling this option, your tests will run sequentially, but in the same global context, so you must provide isolation yourself.
715
+
716
+
This might cause all sorts of issues, if you are relying on global state (frontend frameworks usually do) or your code relies on environment to be defined separately for each test. But can be a speed boost for your tests (up to 3 times faster), that don't necessarily rely on global state or can easily bypass that.
Enable multi-threading using [tinypool](https://github.com/tinylibs/tinypool) (a lightweight fork of [Piscina](https://github.com/piscinajs/piscina)). Prior to Vitest 0.29.0, Vitest was still running tests inside worker thread, even if this option was disabled. Since 0.29.0, if this option is disabled, Vitest uses `child_process` to spawn a process to run tests inside, meaning you can use `process.chdir` and other API that was not available inside workers. If you want to revert to the previous behaviour, use `--single-thread` option instead.
Run all tests with the same environment inside a single worker thread. This will disable built-in module isolation (your source code or [inlined](#deps-inline) code will still be reevaluated for each test), but can improve test performance. Before Vitest 0.29.0 this was equivalent to using `--no-threads`.
779
+
Run all tests with the same environment inside a single child process. This will disable built-in module isolation (your source code or [inlined](#deps-inline) code will still be reevaluated for each test), but can improve test performance.
704
780
705
781
706
782
:::warning
707
-
Even though this option will force tests to run one after another, this option is different from Jest's `--runInBand`. Vitest uses workers not only for running tests in parallel, but also to provide isolation. By disabling this option, your tests will run sequentially, but in the same global context, so you must provide isolation yourself.
783
+
Even though this option will force tests to run one after another, this option is different from Jest's `--runInBand`. Vitest uses child processes not only for running tests in parallel, but also to provide isolation. By disabling this option, your tests will run sequentially, but in the same global context, so you must provide isolation yourself.
708
784
709
785
This might cause all sorts of issues, if you are relying on global state (frontend frameworks usually do) or your code relies on environment to be defined separately for each test. But can be a speed boost for your tests (up to 3 times faster), that don't necessarily rely on global state or can easily bypass that.
Specifies the memory limit for workers before they are recycled. This value heavily depends on your environment, so it's better to specify it manually instead of relying on the default.
826
+
827
+
::: tip
828
+
The implementation is based on Jest's [`workerIdleMemoryLimit`](https://jestjs.io/docs/configuration#workeridlememorylimit-numberstring).
829
+
830
+
The limit can be specified in a number of different ways and whatever the result is `Math.floor` is used to turn it into an integer value:
831
+
832
+
-`<= 1` - The value is assumed to be a percentage of system memory. So 0.5 sets the memory limit of the worker to half of the total system memory
833
+
-`\> 1` - Assumed to be a fixed byte value. Because of the previous rule if you wanted a value of 1 byte (I don't know why) you could use 1.1.
834
+
- With units
835
+
-`50%` - As above, a percentage of total system memory
836
+
-`100KB`, `65MB`, etc - With units to denote a fixed memory limit.
837
+
-`K` / `KB` - Kilobytes (x1000)
838
+
-`KiB` - Kibibytes (x1024)
839
+
-`M` / `MB` - Megabytes
840
+
-`MiB` - Mebibytes
841
+
-`G` / `GB` - Gigabytes
842
+
-`GiB` - Gibibytes
843
+
:::
844
+
845
+
::: warning
846
+
Percentage based memory limit [does not work on Linux CircleCI](https://github.com/jestjs/jest/issues/11956#issuecomment-1212925677) workers due to incorrect system memory being reported.
@@ -773,7 +895,7 @@ Path to setup files. They will be run before each test file.
773
895
Changing setup files will trigger rerun of all tests.
774
896
:::
775
897
776
-
You can use `process.env.VITEST_POOL_ID` (integer-like string) inside to distinguish between threads (will always be `'1'`, if run with `threads: false`).
898
+
You can use `process.env.VITEST_POOL_ID` (integer-like string) inside to distinguish between threads.
777
899
778
900
:::tip
779
901
Note, that if you are running [`--threads=false`](#threads), this setup file will be run in the same global scope multiple times. Meaning, that you are accessing the same global object before each test, so make sure you are not doing the same thing more than you need.
Make sure that your files are not excluded by `watchExclude`.
843
965
:::
844
966
845
-
### isolate
846
-
847
-
-**Type:**`boolean`
848
-
-**Default:**`true`
849
-
-**CLI:**`--isolate`, `--isolate=false`
850
-
851
-
Isolate environment for each test file. Does not work if you disable [`--threads`](#threads).
852
-
853
-
This options has no effect on [`experimentalVmThreads`](#experimentalvmthreads).
854
-
855
967
### coverage<NonProjectOption />
856
968
857
969
You can use [`v8`](https://v8.dev/blog/javascript-code-coverage), [`istanbul`](https://istanbul.js.org/) or [a custom coverage solution](/guide/coverage#custom-coverage-provider) for coverage collection.
@@ -1211,6 +1323,14 @@ Run all tests in a specific browser. Possible options in different providers:
1211
1323
1212
1324
Run the browser in a `headless` mode. If you are running Vitest in CI, it will be enabled by default.
Once Vitest starts it will stop execution and waits for you to open developer tools that can connect to [NodeJS inspector](https://nodejs.org/en/docs/guides/debugging-getting-started/). You can use Chrome DevTools for this by opening `chrome://inspect` on browser.
66
66
67
-
In watch mode you can keep the debugger open during test re-runs by using the `--single-thread --isolate false` options.
67
+
In watch mode you can keep the debugger open during test re-runs by using the `--poolOptions.threads.isolate false` options.
0 commit comments