Skip to content

Commit b675287

Browse files
authored
Merge branch 'main' into fix-9642-merge-reports-reporter-errors
2 parents 67b744e + accf5d4 commit b675287

69 files changed

Lines changed: 750 additions & 157 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

docs/.vitepress/sponsors.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ export const sponsors: SponsorTier[] = [
66
size: 'big',
77
items: [
88
{
9-
name: 'NuxtLabs',
10-
url: 'https://nuxtlabs.com',
11-
img: '/nuxtlabs.svg',
9+
name: 'Vercel',
10+
url: 'https://vercel.com',
11+
img: '/vercel.svg',
1212
},
1313
{
14-
name: 'Bolt',
15-
url: 'https://bolt.new',
16-
img: '/bolt.svg',
14+
name: 'Chromatic',
15+
url: 'https://www.chromatic.com/?utm_source=vitest&utm_medium=sponsorship&utm_campaign=vitestSponsorship',
16+
img: '/chromatic.svg',
1717
},
1818
{
1919
name: 'Zammad',
@@ -26,10 +26,11 @@ export const sponsors: SponsorTier[] = [
2626
tier: 'Platinum Sponsors',
2727
size: 'big',
2828
items: [
29+
2930
{
30-
name: 'Chromatic',
31-
url: 'https://www.chromatic.com/?utm_source=vitest&utm_medium=sponsorship&utm_campaign=vitestSponsorship',
32-
img: '/chromatic.svg',
31+
name: 'Bolt',
32+
url: 'https://bolt.new',
33+
img: '/bolt.svg',
3334
},
3435
],
3536
},

docs/api/advanced/vitest.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ This makes this method very slow, unless you disable isolation before collecting
349349
function cancelCurrentRun(reason: CancelReason): Promise<void>
350350
```
351351

352-
This method will gracefully cancel all ongoing tests. It will wait for started tests to finish running and will not run tests that were scheduled to run but haven't started yet.
352+
This method will gracefully cancel all ongoing tests. It will stop the on-going tests and will not run tests that were scheduled to run but haven't started yet.
353353

354354
## setGlobalTestNamePattern
355355

docs/api/vi.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,21 +1085,21 @@ import { vi } from 'vitest'
10851085
vi.useFakeTimers()
10861086
10871087
// Manual mode (default)
1088-
vi.setTimerTickMode({ mode: 'manual' })
1088+
vi.setTimerTickMode('manual')
10891089
10901090
let i = 0
10911091
setInterval(() => console.log(++i), 50)
10921092
10931093
vi.advanceTimersByTime(150) // logs 1, 2, 3
10941094
10951095
// nextTimerAsync mode
1096-
vi.setTimerTickMode({ mode: 'nextTimerAsync' })
1096+
vi.setTimerTickMode('nextTimerAsync')
10971097
10981098
// Timers will advance automatically after each macrotask
10991099
await new Promise(resolve => setTimeout(resolve, 150)) // logs 4, 5, 6
11001100
11011101
// interval mode (default when 'fakeTimers.shouldAdvanceTime' is `true`)
1102-
vi.setTimerTickMode({ mode: 'interval', interval: 50 })
1102+
vi.setTimerTickMode('interval', 50)
11031103
11041104
// Timers will advance automatically every 50ms
11051105
await new Promise(resolve => setTimeout(resolve, 150)) // logs 7, 8, 9

docs/guide/improving-performance.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,20 @@ export default defineConfig({
7777

7878
You can limit the working directory when Vitest searches for files using [`test.dir`](/config/dir) option. This should make the search faster if you have unrelated folders and files in the root directory.
7979

80+
## Caching Between Reruns
81+
82+
In watch mode, Vitest caches all transformed files in memory, which makes reruns fast. However, this cache is discarded once the test run finishes. By enabling [`experimental.fsModuleCache`](/config/experimental#experimental-fsmodulecache), Vitest persists this cache to the file system so it can be reused across reruns.
83+
84+
This improvement is most noticeable when rerunning a small number of tests that depend on a large module graph. For full test suites, parallelization already mitigates the cost because other tests populate the in-memory cache while earlier tests are still running. For example, running one test file with a huge module graph (>900 modules):
85+
86+
```shell
87+
# the first run
88+
Duration 8.75s (transform 4.02s, setup 629ms, import 5.52s, tests 2.52s, environment 0ms, prepare 3ms)
89+
90+
# the second run
91+
Duration 5.90s (transform 842ms, setup 543ms, import 2.35s, tests 2.94s, environment 0ms, prepare 3ms)
92+
```
93+
8094
## Pool
8195

8296
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.

docs/guide/profiling-test-performance.md

Lines changed: 89 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -112,20 +112,101 @@ test('formatter works', () => {
112112
113113
<img src="/module-graph-barrel-file.png" alt="Vitest UI demonstrating barrel file issues" />
114114
115-
To see how files are transformed, you can use `VITEST_DEBUG_DUMP` environment variable to write transformed files in the file system:
115+
To see how files are transformed, you can open the "Module Info" view in the UI:
116+
117+
<img alt="The module info view for an inlined module" img-light src="/ui/light-module-info.png">
118+
<img alt="The module info view for an inlined module" img-dark src="/ui/dark-module-info.png">
119+
120+
## File Import
121+
122+
Some modules just take a long time to load. To identify which modules are the slowest, enable [`experimental.importDurations`](/config/experimental#experimental-importdurations) in your configuration:
123+
124+
```ts [vitest.config.ts]
125+
import { defineConfig } from 'vitest/config'
126+
127+
export default defineConfig({
128+
test: {
129+
experimental: {
130+
importDurations: {
131+
print: true,
132+
},
133+
},
134+
},
135+
})
136+
```
137+
138+
This will print a breakdown of the slowest imports after your tests finish:
139+
140+
```bash
141+
Import Duration Breakdown (Top 10)
142+
143+
Module Self Total
144+
my-test.test.ts 5ms 620ms [████████████████████]
145+
date-fns/index.js 500ms 500ms [████████████████░░░░] # [!code error]
146+
src/utils/helpers.ts 10ms 120ms [████████░░░░░░░░░░░░]
147+
```
148+
149+
You can also use `--experimental.importDurations.print` from the CLI without changing your configuration:
116150
117151
```bash
118-
$ VITEST_DEBUG_DUMP=true vitest --run
152+
vitest --experimental.importDurations.print
153+
```
154+
155+
Once you've identified the slow modules, there are several strategies to speed up imports:
156+
157+
### Use Specific Entry Points
158+
159+
Many libraries ship multiple entry points. Importing the main entry point (which is often a [barrel file](https://vitejs.dev/guide/performance.html#avoid-barrel-files)) can pull in far more code than you need.
119160
120-
RUN v2.1.1 /x/vitest/examples/profiling
121-
...
161+
For example, `date-fns` re-exports hundreds of functions from its main entry point. Instead of importing from the top-level module, import directly from the specific function:
122162
123-
$ ls .vitest-dump/
124-
_x_examples_profiling_global-setup_ts-1292904907.js
125-
_x_examples_profiling_test_prime-number_test_ts-1413378098.js
126-
_src_prime-number_ts-525172412.js
163+
```ts
164+
import { format } from 'date-fns' // [!code --]
165+
import { format } from 'date-fns/format' // [!code ++]
127166
```
128167
168+
### Use `resolve.alias` to Redirect Imports
169+
170+
If a dependency doesn't provide granular entry points, or if third-party code imports the heavy entry point, you can use [`resolve.alias`](https://vite.dev/config/shared-options#resolve-alias) to redirect imports to a lighter alternative:
171+
172+
```ts [vitest.config.ts]
173+
import { defineConfig } from 'vitest/config'
174+
175+
export default defineConfig({
176+
resolve: {
177+
alias: [
178+
{
179+
find: /^date-fns$/,
180+
replacement: join(dirname(require.resolve('date-fns/package.json')), 'index.cjs'),
181+
},
182+
]
183+
},
184+
})
185+
```
186+
187+
### Use the Dependency Optimizer
188+
189+
Vitest can bundle external libraries into a single file using [`deps.optimizer`](/config/deps#deps-optimizer), which reduces the overhead of importing packages with many internal modules:
190+
191+
```ts [vitest.config.ts]
192+
import { defineConfig } from 'vitest/config'
193+
194+
export default defineConfig({
195+
test: {
196+
deps: {
197+
optimizer: {
198+
ssr: {
199+
enabled: true,
200+
include: ['date-fns'],
201+
},
202+
},
203+
},
204+
},
205+
})
206+
```
207+
208+
This is especially effective for UI libraries and packages with deep import trees. Use `optimizer.ssr` for `node`/`edge` environments and `optimizer.client` for `jsdom`/`happy-dom` environments.
209+
129210
## Code Coverage
130211
131212
If code coverage generation is slow on your project you can use `DEBUG=vitest:coverage` environment variable to enable performance logging.

docs/public/nuxtlabs.svg

Lines changed: 0 additions & 1 deletion
This file was deleted.

docs/public/vercel.svg

Lines changed: 1 addition & 0 deletions
Loading

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@vitest/monorepo",
33
"type": "module",
4-
"version": "4.1.0-beta.4",
4+
"version": "4.1.0-beta.5",
55
"private": true,
66
"packageManager": "pnpm@10.30.2",
77
"description": "Next generation testing framework powered by Vite",
@@ -35,6 +35,7 @@
3535
"ui:build": "vite build packages/ui",
3636
"ui:dev": "npm -C packages/ui run dev:client",
3737
"ui:test": "npm -C packages/ui run test:run",
38+
"override-rolldown": "yq -i '.overrides.vite = \"npm:vite@beta\"' pnpm-workspace.yaml",
3839
"test:browser:webdriverio": "pnpm -C test/browser run test:webdriverio",
3940
"test:browser:playwright": "pnpm -C test/browser run test:playwright"
4041
},

packages/browser-playwright/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@vitest/browser-playwright",
33
"type": "module",
4-
"version": "4.1.0-beta.4",
4+
"version": "4.1.0-beta.5",
55
"description": "Browser running for Vitest using playwright",
66
"license": "MIT",
77
"funding": "https://opencollective.com/vitest",

packages/browser-preview/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@vitest/browser-preview",
33
"type": "module",
4-
"version": "4.1.0-beta.4",
4+
"version": "4.1.0-beta.5",
55
"description": "Browser running for Vitest using your browser of choice",
66
"license": "MIT",
77
"funding": "https://opencollective.com/vitest",

0 commit comments

Comments
 (0)