Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion exercises/04.performance/03.problem.test-isolation/README.mdx
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
# Test isolation

...
Vitest runs every test file in a separate worker, which enables parallel execution and speeds up tests by default.

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.

### The Problem
While test isolation provides benefits, **it comes with a performance cost.**

When you have hundreds or thousands of test files, the overhead of spawning a worker for each file accumulates and can significantly degrade performance.

### Your Task

Follow the instructions to disable test isolation and observe the performance difference it makes in projects with a large number of test files.
22 changes: 21 additions & 1 deletion exercises/04.performance/03.solution.test-isolation/README.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,24 @@ This also means that you can benefit from correctly written tests in more ways t

## Your task

👨‍💼 ...
Opt out of the default test isolation and observe how this change affects how your tests are ran.

### Configuration Change

To disable test isolation and prevent Vitest from spawning a worker for each test file:

1. Open your `vitest.config.js` (or `vitest.config.ts`)
2. Add or modify the test configuration:

```javascript
export default defineConfig({
test: {
globals: true,
isolate: false,
},
})
```

Then run `npm test`.

What change did this make to your test run?