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
Copy file name to clipboardExpand all lines: docs/config/index.md
+72-2
Original file line number
Diff line number
Diff line change
@@ -144,7 +144,11 @@ Handling for dependencies resolution.
144
144
-**Type:**`(string | RegExp)[]`
145
145
-**Default:**`[/\/node_modules\//]`
146
146
147
-
Externalize means that Vite will bypass the package to native Node. Externalized dependencies will not be applied Vite's transformers and resolvers, so they do not support HMR on reload. All packages under `node_modules` are externalized.
147
+
Externalize means that Vite will bypass the package to the native Node. Externalized dependencies will not be applied to Vite's transformers and resolvers, so they do not support HMR on reload. By default, all packages inside `node_modules` are externalized.
148
+
149
+
These options support package names as they are written in `node_modules` or specified inside [`deps.moduleDirectories`](#deps-moduledirectories). For example, package `@company/some-name` located inside `packages/some-name` should be specified as `some-name`, and `packages` should be included in `deps.moduleDirectories`. Basically, Vitest always checks the file path, not the actual package name.
150
+
151
+
If regexp is used, Vitest calls it on the _file path_, not the package name.
148
152
149
153
#### server.deps.inline
150
154
@@ -421,6 +425,7 @@ import type { Environment } from 'vitest'
Run tests using [VM context](https://nodejs.org/api/vm.html) (inside a sandboxed environment) in a worker pool.
557
+
558
+
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.
559
+
560
+
::: warning
561
+
Running code in a sandbox has some advantages (faster tests), but also comes with a number of disadvantages.
562
+
563
+
- The globals within native modules, such as (`fs`, `path`, etc), differ from the globals present in your test environment. As a result, any error thrown by these native modules will reference a different Error constructor compared to the one used in your code:
564
+
565
+
```ts
566
+
try {
567
+
fs.writeFileSync('/doesnt exist')
568
+
}
569
+
catch (err) {
570
+
console.log(errinstanceofError) // false
571
+
}
572
+
```
573
+
574
+
- Importing ES modules caches them indefinitely which introduces memory leaks if you have a lot of contexts (test files). There is no API in Node.js that clears that cache.
575
+
- Accessing globals [takes longer](https://github.com/nodejs/node/issues/31658) in a sandbox environment.
576
+
577
+
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.
588
+
589
+
This option only affects workers that run tests in [VM context](#experimentalvmthreads).
590
+
591
+
::: tip
592
+
The implementation is based on Jest's [`workerIdleMemoryLimit`](https://jestjs.io/docs/configuration#workeridlememorylimit-numberstring).
593
+
594
+
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:
595
+
596
+
-`<= 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
597
+
-`\> 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.
598
+
- With units
599
+
-`50%` - As above, a percentage of total system memory
600
+
-`100KB`, `65MB`, etc - With units to denote a fixed memory limit.
601
+
-`K` / `KB` - Kilobytes (x1000)
602
+
-`KiB` - Kibibytes (x1024)
603
+
-`M` / `MB` - Megabytes
604
+
-`MiB` - Mebibytes
605
+
-`G` / `GB` - Gigabytes
606
+
-`GiB` - Gibibytes
607
+
:::
608
+
609
+
::: warning
610
+
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.
611
+
:::
612
+
545
613
### threads
546
614
547
615
-**Type:**`boolean`
@@ -708,6 +776,8 @@ Make sure that your files are not excluded by `watchExclude`.
708
776
709
777
Isolate environment for each test file. Does not work if you disable [`--threads`](#threads).
710
778
779
+
This options has no effect on [`experimentalVmThreads`](#experimentalvmthreads).
780
+
711
781
### coverage<NonProjectOption />
712
782
713
783
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.
0 commit comments