Repository navigation
test: give each test run its own temporary root - #250
Merged
Merged
Conversation
A run of the unit suite left 64 entries in the system temp directory and the native suite one more; a working machine had accumulated about 5,700. A global setup now creates one root per run, points TMPDIR/TEMP/TMP at it before Vitest starts workers (os.tmpdir() reads them on every call, and workers and their child processes inherit them), and removes it when the run ends. The one remaining directory per run is Vitest's own fetcher root, fixed upstream in 5.0.3.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The unit and native test suites no longer leave scratch directories in the system temp directory.
Why
A single run of the unit suite left 64 entries in
os.tmpdir(), from about 17 test files and the CLIs they spawn. The native suite left one more. A working machine had accumulated about 5,700 of them.Changes
tests/support/temp-root.global.ts: a global setup that creates one root per run and pointsTMPDIR/TEMP/TMPat it, removing the root on teardown. Vitest runs global setup before starting workers, andos.tmpdir()reads those variables on every call, so workers and their child processes inherit the root without any per-test changes.vitest.config.tsandtests-native/vitest.config.mts.Notes for reviewers
tmpdir()/<nanoid>/ssr) is created before global setup and never removed in 5.0.0–5.0.2. It is fixed upstream in 5.0.3 (fix(vitest): remove root temp dir on close vitest-dev/vitest#11248), which clears the release cooldown on 2026-10-07.