Skip to content

fix: setup files run only once with no-isolate#947

Merged
9aoy merged 3 commits intomainfrom
fix-setup-no-isolate
Feb 6, 2026
Merged

fix: setup files run only once with no-isolate#947
9aoy merged 3 commits intomainfrom
fix-setup-no-isolate

Conversation

@claneo
Copy link
Copy Markdown
Collaborator

@claneo claneo commented Feb 6, 2026

Summary

In no-isolate mode, the module cache can cause several issues:

  1. Modules are not re-executed, so setup files run only once
  2. The context used by modules is not updated—e.g., assetFiles in [Bug]: Set isolate option to false causes some errors #777 or document.body in testing-library

This PR adds a step to clear the module cache after each test file finishes running.

Related Links

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

@claneo claneo marked this pull request as ready for review February 6, 2026 03:29
Copilot AI review requested due to automatic review settings February 6, 2026 03:29
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a critical issue in no-isolate mode where setup files and their dependencies were only executed once across multiple test files due to module caching. The fix clears the module cache after each test file completes, ensuring setup files re-execute for every test file.

Changes:

  • Removed the latestAssetFiles workaround that attempted to address stale asset references but didn't solve the underlying module caching issue
  • Added clearModuleCache() exports to both loadModule.ts and loadEsModule.ts to clear the internal module caches
  • Modified runInPool teardown to call clearModuleCache() after each test file completes

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
packages/core/src/runtime/worker/loadModule.ts Removed latestAssetFiles workaround; added clearModuleCache export to clear moduleCache
packages/core/src/runtime/worker/loadEsModule.ts Removed latestAssetFiles workaround; added clearModuleCache export to clear esmCache
packages/core/src/runtime/worker/index.ts Removed updateLatestAssetFiles call; added clearModuleCache call in teardown
e2e/setup/index.test.ts Added test case to verify setup files run once per test file in no-isolate mode
e2e/setup/fixtures/no-isolate/rstest.setup.ts New test fixture with beforeAll/afterAll hooks to verify re-execution
e2e/setup/fixtures/no-isolate/rstest.config.ts Config for no-isolate test with isolate:false and maxWorkers:1
e2e/setup/fixtures/no-isolate/foo.test.ts Test file verifying setup file effects and snapshot serializer
e2e/setup/fixtures/no-isolate/bar.test.ts Second test file verifying setup runs again

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@fi3ework fi3ework requested a review from 9aoy February 6, 2026 03:45
claneo and others added 2 commits February 6, 2026 14:10
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@9aoy
Copy link
Copy Markdown
Collaborator

9aoy commented Feb 6, 2026

👍

@9aoy 9aoy merged commit 08180ab into main Feb 6, 2026
9 checks passed
@9aoy 9aoy deleted the fix-setup-no-isolate branch February 6, 2026 06:43
@9aoy 9aoy mentioned this pull request Feb 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants