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/guide/common-errors.md
+29-9
Original file line number
Diff line number
Diff line change
@@ -65,9 +65,8 @@ This error can happen when NodeJS's `fetch` is used with default [`pool: 'thread
65
65
66
66
As work-around you can switch to [`pool: 'forks'`](/config/#forks) or [`pool: 'vmForks'`](/config/#vmforks).
67
67
68
-
Specify `pool` in your configuration file:
69
-
70
-
```ts
68
+
::: code-group
69
+
```ts [vitest.config.js]
71
70
import { defineConfig } from'vitest/config'
72
71
73
72
exportdefaultdefineConfig({
@@ -76,12 +75,33 @@ export default defineConfig({
76
75
},
77
76
})
78
77
```
78
+
```bash [CLI]
79
+
vitest --pool=forks
80
+
```
81
+
:::
79
82
80
-
Or in your `package.json` scripts:
83
+
## Segfaults and native code errors
81
84
82
-
```diff
83
-
scripts: {
84
-
- "test": "vitest"
85
-
+ "test": "vitest --pool=forks"
86
-
}
85
+
Running [native NodeJS modules](https://nodejs.org/api/addons.html) in `pool: 'threads'` can run into cryptic errors coming from the native code.
86
+
87
+
-`Segmentation fault (core dumped)`
88
+
-`thread '<unnamed>' panicked at 'assertion failed`
89
+
-`Abort trap: 6`
90
+
-`internal error: entered unreachable code`
91
+
92
+
In these cases the native module is likely not built to be multi-thread safe. As work-around, you can switch to `pool: 'forks'` which runs the test cases in multiple `node:child_process` instead of multiple `node:worker_threads`.
Copy file name to clipboardExpand all lines: docs/guide/improving-performance.md
+23
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,7 @@
1
1
# Improving Performance
2
2
3
+
## Test isolation
4
+
3
5
By default Vitest runs every test file in an isolated environment based on the [pool](/config/#pool):
4
6
5
7
-`threads` pool runs every test file in a separate [`Worker`](https://nodejs.org/api/worker_threads.html#class-worker)
@@ -49,3 +51,24 @@ export default defineConfig({
49
51
})
50
52
```
51
53
:::
54
+
55
+
## Pool
56
+
57
+
By default Vitest runs tests in `pool: 'forks'`. While `'forks'` pool is better for compatibility issues ([hanging process](/guide/common-errors.html#failed-to-terminate-worker) and [segfaults](/guide/common-errors.html#segfaults-and-native-code-errors)), it may be slightly slower than `pool: 'threads'` in larger projects.
58
+
59
+
You can try to improve test run time by switching `pool` option in configuration:
0 commit comments