From aced900c0c9e69bec460443f8e0441e191b90049 Mon Sep 17 00:00:00 2001 From: Vladimir Sheremet Date: Wed, 11 Feb 2026 09:50:26 +0100 Subject: [PATCH 1/3] docs: add `--static-parse` to docs --- guide/cli.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/guide/cli.md b/guide/cli.md index 61d82db3..730d1ced 100644 --- a/guide/cli.md +++ b/guide/cli.md @@ -121,6 +121,8 @@ tests/test1.test.ts tests/test2.test.ts ``` +Since Vitest 4.1, you may pass `--static-parse` to [parse test files](/api/advanced/vitest#parsespecifications) instead of running them to collect tests. Vitest parses test files with limited concurrency, defaulting to `os.availableParallelism()`. You can change it via the `--static-parse-concurrency` option. + ## Shell Autocompletions Vitest provides shell autocompletions for commands, options, and option values powered by [`@bomb.sh/tab`](https://github.com/bombshell-dev/tab). From 7a5ad4defc51a329d42ab280f76e1a5be69f6056 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ari=20Perkki=C3=B6?= Date: Wed, 11 Feb 2026 15:13:40 +0200 Subject: [PATCH 2/3] feat: add `--detect-async-leaks` (#9528) --- config/detectasyncleaks.md | 44 ++++++++++++++++++++++++++++++++++++++ guide/cli-generated.md | 7 ++++++ 2 files changed, 51 insertions(+) create mode 100644 config/detectasyncleaks.md diff --git a/config/detectasyncleaks.md b/config/detectasyncleaks.md new file mode 100644 index 00000000..26e873e0 --- /dev/null +++ b/config/detectasyncleaks.md @@ -0,0 +1,44 @@ +--- +title: detectAsyncLeaks | Config +outline: deep +--- + +# detectAsyncLeaks + +- **Type:** `boolean` +- **CLI:** `--detectAsyncLeaks`, `--detect-async-leaks` +- **Default:** `false` + +::: warning +Enabling this option will make your tests run much slower. Use only when debugging or developing tests. +::: + +Detect asynchronous resources leaking from the test file. +Uses [`node:async_hooks`](https://nodejs.org/api/async_hooks.html) to track creation of async resources. If a resource is not cleaned up, it will be logged after tests have finished. + +For example if your code has `setTimeout` calls that execute the callback after tests have finished, you will see following error: + +```sh +⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Async Leaks 1 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ + +Timeout leaking in test/checkout-screen.test.tsx + 26| + 27| useEffect(() => { + 28| setTimeout(() => setWindowWidth(window.innerWidth), 150) + | ^ + 29| }) + 30| +``` + +To fix this, you'll need to make sure your code cleans the timeout properly: + +```js +useEffect(() => { + setTimeout(() => setWindowWidth(window.innerWidth), 150) // [!code --] + const timeout = setTimeout(() => setWindowWidth(window.innerWidth), 150) // [!code ++] + + return function cleanup() { // [!code ++] + clearTimeout(timeout) // [!code ++] + } // [!code ++] +}) +``` diff --git a/guide/cli-generated.md b/guide/cli-generated.md index b449a9ad..118f687a 100644 --- a/guide/cli-generated.md +++ b/guide/cli-generated.md @@ -464,6 +464,13 @@ Pass when no tests are found Show the size of heap for each test when running in node +### detectAsyncLeaks + +- **CLI:** `--detectAsyncLeaks` +- **Config:** [detectAsyncLeaks](/config/detectasyncleaks) + +Detect asynchronous resources leaking from the test file (default: `false`) + ### allowOnly - **CLI:** `--allowOnly` From dfec6b5eb92af99196ebbb8e6d355f390c275d77 Mon Sep 17 00:00:00 2001 From: noise Date: Thu, 12 Feb 2026 22:38:34 +0800 Subject: [PATCH 3/3] docs(cn): dissolve the conflict --- config/detectasyncleaks.md | 2 +- guide/cli-generated.md | 2 +- guide/cli.md | 8 ++------ 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/config/detectasyncleaks.md b/config/detectasyncleaks.md index 26e873e0..88c326de 100644 --- a/config/detectasyncleaks.md +++ b/config/detectasyncleaks.md @@ -2,7 +2,7 @@ title: detectAsyncLeaks | Config outline: deep --- - + # detectAsyncLeaks - **Type:** `boolean` diff --git a/guide/cli-generated.md b/guide/cli-generated.md index a034fc6d..7e3bc809 100644 --- a/guide/cli-generated.md +++ b/guide/cli-generated.md @@ -463,7 +463,7 @@ Memory limit for VM pools. If you see memory leaks, try to tinker this value. - **配置:** [logHeapUsage](/config/logheapusage) 在节点中运行时,显示每个测试的堆大小 - + ### detectAsyncLeaks - **CLI:** `--detectAsyncLeaks` diff --git a/guide/cli.md b/guide/cli.md index e071048c..53607472 100644 --- a/guide/cli.md +++ b/guide/cli.md @@ -122,14 +122,10 @@ vitest list --filesOnly tests/test1.test.ts tests/test2.test.ts ``` - -<<<<<<< HEAD -## Shell 自动补全 {#shell-autocompletions} -======= + Since Vitest 4.1, you may pass `--static-parse` to [parse test files](/api/advanced/vitest#parsespecifications) instead of running them to collect tests. Vitest parses test files with limited concurrency, defaulting to `os.availableParallelism()`. You can change it via the `--static-parse-concurrency` option. -## Shell Autocompletions ->>>>>>> 7a5ad4defc51a329d42ab280f76e1a5be69f6056 +## Shell 自动补全 {#shell-autocompletions} Vitest 通过 [`@bomb.sh/tab`](https://github.com/bombshell-dev/tab) 提供命令、选项及选项值的 Shell 自动补全功能。