Skip to content

Commit d1c81ce

Browse files
authored
feat: fill out READMEs for 04-03 problem and solution (#4)
1 parent 5ff0d49 commit d1c81ce

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed
Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
11
# Test isolation
22

3-
...
3+
Vitest runs every test file in a separate worker, which enables parallel execution and speeds up tests by default.
4+
5+
Each worker has its own isolated environment, meaning that if one test file mutates a global variable, other test files won't be affected by this mutation. This test file-level isolation is a great feature for preventing test interference.
6+
7+
### The Problem
8+
While test isolation provides benefits, **it comes with a performance cost.**
9+
10+
When you have hundreds or thousands of test files, the overhead of spawning a worker for each file accumulates and can significantly degrade performance.
11+
12+
### Your Task
13+
14+
Follow the instructions to disable test isolation and observe the performance difference it makes in projects with a large number of test files.

exercises/04.performance/03.solution.test-isolation/README.mdx

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,24 @@ This also means that you can benefit from correctly written tests in more ways t
3232
3333
## Your task
3434

35-
👨‍💼 ...
35+
Opt out of the default test isolation and observe how this change affects how your tests are ran.
36+
37+
### Configuration Change
38+
39+
To disable test isolation and prevent Vitest from spawning a worker for each test file:
40+
41+
1. Open your `vitest.config.js` (or `vitest.config.ts`)
42+
2. Add or modify the test configuration:
43+
44+
```javascript
45+
export default defineConfig({
46+
test: {
47+
globals: true,
48+
isolate: false,
49+
},
50+
})
51+
```
52+
53+
Then run `npm test`.
54+
55+
What change did this make to your test run?

0 commit comments

Comments
 (0)