Repository navigation
test: reuse jsdom per worker to halve the suite runtime - #388
Open
sunxiaobin89 wants to merge 1 commit into
Open
sunxiaobin89 wants to merge 1 commit into
sunxiaobin89 wants to merge 1 commit into
Conversation
Vitest rebuilt jsdom 181 times (79 s of the 27 s wall clock across workers). pool: 'vmThreads' keeps per-file isolation but reuses the environment per worker: 27.1 s -> 11.6-13.0 s with all 2181 tests green. The shared window exposed a latent stub bug: i18n-setup defined window.matchMedia without configurable: true, so a later file in the same worker failed with "Cannot redefine property: matchMedia". Mark both matchMedia stubs configurable.
sunxiaobin89
force-pushed
the
perf/vitest-pool
branch
from
December 3, 2026 05:41
fd22df9 to
4495be3
Compare
Contributor
Author
评估结论:保留
|
This branch has not been deployed
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.
概要
Vitest 会为 181 个测试文件各重建一次 jsdom(79 秒环境创建时间,占 27 秒墙钟时间的 36%)。改用
pool: 'vmThreads'后每个 worker 复用同一个环境,同时保留 per-file 隔离。结果:27.1 s → 11.6–13.0 s(约 55% 提速),2181 个测试全部通过(连续两次运行)。
附带修复
共享 jsdom 暴露了一个潜在的 stub 缺陷:
i18n-setup.ts定义window.matchMedia时没有configurable: true,同一 worker 中后续文件再定义就会报Cannot redefine property: matchMedia。两处 matchMedia stub 都改为 configurable。测试计划
pnpm test→ 27.08 s,jsdom 创建 181 次 / 79.09 spnpm test→ 11.64 s,随后 12.99 s,两次均 178 files / 2181 tests passed