Skip to content

[vitest-plugin] Fix cached cloudflare:test imports across runs - #16249

Merged
edmundhung merged 2 commits into
edmundhung/fix-vitest-fs-module-cachefrom
mjp/fix-vitest-fs-module-cache
Oct 14, 2026
Merged

edmundhung merged 2 commits into
edmundhung/fix-vitest-fs-module-cachefrom
mjp/fix-vitest-fs-module-cache

Conversation

@mattjohnsonpint

@mattjohnsonpint mattjohnsonpint commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Follow-up to #16163, targeting its branch. (Thus, no changeset required, since it's in the base PR.)

The filesystem-cache adapter fixes loading transformed modules into workerd, but subsequent runs can still fail when cached tests import cloudflare:test.

The plugin generates a random virtual module ID each session. Cached imports retain the previous ID, which the next session no longer recognizes, causing the virtual module to fall through to filesystem loading.

Derive stable IDs from the resolved project root and name, preserving project isolation and main dependencies for watch-mode reruns. Remap legacy UUID-based IDs so Vitest can invalidate stale cached importers without requiring users to clear their caches.

Regression coverage:

  • Import cloudflare:test and read bindings with both module registries.
  • Verify each project imports its own main and uses its own SELF entrypoint across cached runs.
  • Populate a legacy UUID-based cache, then migrate without changing the configuration source or clearing cached files.
  • Verify changing Wrangler’s main between cached runs imports the new entrypoint without modifying Vitest config or clearing the cache.
  • Explicitly enable filesystem caching in both coverage fixtures.

Merge order

  1. Merge this PR into edmundhung/fix-vitest-fs-module-cache (PR [vitest-plugin] Fix filesystem module caching #16163).
  2. Merge [vitest-plugin] Fix V8 coverage teardown with Vitest 5.0.4 #16248 into main. It fixes the separate V8 coverage teardown incompatibility introduced by Vitest 5.0.4.
  3. Rebase edmundhung/fix-vitest-fs-module-cache onto the updated main. Resolve the coverage-fixture conflicts in favor of fsModuleCache: true, retaining the V8 teardown fix and expanded regression tests from [vitest-plugin] Fix V8 coverage teardown with Vitest 5.0.4 #16248.
  4. Rerun the cache and coverage tests with Vitest 5.0.4, then merge [vitest-plugin] Fix filesystem module caching #16163 into main.

The explicit fsModuleCache: true settings here intentionally conflict with #16248’s temporary false overrides so those overrides are removed when the fixes are combined.

Validation

  • Cache regressions passed with Vitest 5.0.4.
  • Legacy-cache migration passed with Vitest 5.0.3.
  • Watch and module-registry compatibility checks passed with Vitest 4.1.0.
  • Both cache-enabled coverage tests passed with Vitest 5.0.3.
  • With Vitest 5.0.4, Istanbul coverage passed; V8 coverage remains blocked by [vitest-plugin] Fix V8 coverage teardown with Vitest 5.0.4 #16248.
  • Build, typechecking, type-aware lint, and formatting passed.

  • Tests
    • Tests included/updated
    • Automated tests not possible - manual testing has been completed as follows:
    • Additional testing not necessary because:
  • Public documentation
    • Cloudflare docs PR(s):
    • Documentation not necessary because: this restores cached test behavior without changing the public API.

Devin Review

@changeset-bot

changeset-bot Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: b90d5b5

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@github-project-automation github-project-automation Bot moved this to Untriaged in workers-sdk Oct 13, 2026
@workers-devprod
workers-devprod requested review from a team and edmundhung and removed request for a team October 13, 2026 19:04
@workers-devprod

Copy link
Copy Markdown
Contributor

Codeowners approval required for this PR:

  • @cloudflare/wrangler
Show detailed file reviewers
  • packages/vitest-plugin/src/pool/plugin.ts: [@cloudflare/wrangler]
  • packages/vitest-plugin/test/coverage.test.ts: [@cloudflare/wrangler]
  • packages/vitest-plugin/test/fs-module-cache.test.ts: [@cloudflare/wrangler]

devin-ai-integration[bot]

This comment was marked as resolved.

@ask-bonk

ask-bonk Bot commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

LGTM

github run

@pkg-pr-new

pkg-pr-new Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
@cloudflare/autoconfig

npm i https://pkg.pr.new/@cloudflare/autoconfig@16249

@cloudflare/build-output-utils

npm i https://pkg.pr.new/@cloudflare/build-output-utils@16249

@cloudflare/codemods

npm i https://pkg.pr.new/@cloudflare/codemods@16249

@cloudflare/config

npm i https://pkg.pr.new/@cloudflare/config@16249

@cloudflare/containers-shared

npm i https://pkg.pr.new/@cloudflare/containers-shared@16249

create-cloudflare

npm i https://pkg.pr.new/create-cloudflare@16249

@cloudflare/deploy-helpers

npm i https://pkg.pr.new/@cloudflare/deploy-helpers@16249

@cloudflare/kv-asset-handler

npm i https://pkg.pr.new/@cloudflare/kv-asset-handler@16249

miniflare

npm i https://pkg.pr.new/miniflare@16249

@cloudflare/pages-functions

npm i https://pkg.pr.new/@cloudflare/pages-functions@16249

@cloudflare/pages-shared

npm i https://pkg.pr.new/@cloudflare/pages-shared@16249

@cloudflare/runtime-types

npm i https://pkg.pr.new/@cloudflare/runtime-types@16249

@cloudflare/unenv-preset

npm i https://pkg.pr.new/@cloudflare/unenv-preset@16249

@cloudflare/vite-plugin

npm i https://pkg.pr.new/@cloudflare/vite-plugin@16249

@cloudflare/vitest-plugin

npm i https://pkg.pr.new/@cloudflare/vitest-plugin@16249

@cloudflare/workers-auth

npm i https://pkg.pr.new/@cloudflare/workers-auth@16249

@cloudflare/workers-editor-shared

npm i https://pkg.pr.new/@cloudflare/workers-editor-shared@16249

@cloudflare/workers-utils

npm i https://pkg.pr.new/@cloudflare/workers-utils@16249

wrangler

npm i https://pkg.pr.new/wrangler@16249

commit: b90d5b5

@mattjohnsonpint mattjohnsonpint added the ci:no-changeset-required Skip pull request checks for a valid changeset label Oct 13, 2026
@mattjohnsonpint
mattjohnsonpint force-pushed the mjp/fix-vitest-fs-module-cache branch from 4e61b81 to df8fd09 Compare October 13, 2026 19:16
devin-ai-integration[bot]

This comment was marked as resolved.

Vitest filesystem caches retain transformed imports of cloudflare:test, but randomly generated virtual module IDs change between sessions and leave cached imports pointing at unavailable modules.

Derive stable IDs from the resolved project root and name while preserving project-specific main dependencies for watch-mode reruns. Remap legacy UUID-based IDs to the current project ID so Vitest can invalidate stale cached importers without requiring users to clear their caches.

Extend both module-registry cache regressions to exercise cloudflare:test bindings. Cover main and SELF isolation across cached multi-project runs, and migration from legacy IDs without changing the configuration source or clearing cached files.

Validation: filesystem-cache regressions passed with Vitest 5.0.4, legacy-cache migration passed with Vitest 5.0.3, and watch/module-registry compatibility checks passed with Vitest 4.1.0. Build, typechecking, type-aware lint, and formatting passed.
Exercise V8 and Istanbul coverage with fsModuleCache enabled rather than relying on version-dependent defaults.

Validation: both coverage tests passed with Vitest 5.0.3; with Vitest 5.0.4, Istanbul passed and V8 still failed due to the separate coverage teardown incompatibility. Build, type-aware lint, and formatting passed.
@mattjohnsonpint
mattjohnsonpint force-pushed the mjp/fix-vitest-fs-module-cache branch from df8fd09 to b90d5b5 Compare October 13, 2026 19:20
@edmundhung
edmundhung merged commit b90d5b5 into edmundhung/fix-vitest-fs-module-cache Oct 14, 2026
57 of 61 checks passed
@edmundhung
edmundhung deleted the mjp/fix-vitest-fs-module-cache branch October 14, 2026 10:21
@github-project-automation github-project-automation Bot moved this from Untriaged to Done in workers-sdk Oct 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci:no-changeset-required Skip pull request checks for a valid changeset

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants