Skip to content

Store test source files in a WeakMap instead of mutating module exports - #180

Open
DmitrySharabin wants to merge 1 commit into
mainfrom
weakmap-file-tagging
Open

Store test source files in a WeakMap instead of mutating module exports#180
DmitrySharabin wants to merge 1 commit into
mainfrom
weakmap-file-tagging

Conversation

@DmitrySharabin

Copy link
Copy Markdown
Member

Fixes #179.

The Node env tags every loaded module's default export with a file property, but loadedFiles holds all transitively imported modules — so plain data modules got a file key injected, shadowing real keys and leaking into Object.keys().

The loop has to walk every loaded module (nested test definitions come from transitive imports), so the fix is to stop storing the metadata on the object: Test.files is a WeakMap keyed by the test definition, read in the Test constructor. file still lives on the Test instance, so no consumer changes.

Verified with the issue's repro — TypeError: object is not iterable on main, passes here.

Note: an explicit file on a test definition no longer survives; the registry wins. Undocumented property, no known users.

File +
src/classes/Test.js 5 0
src/env/node.js 5 5
tests/module-tagging.js 25 0
tests/fixtures/plain-module.js 1 0

🤖 Generated with Claude Code

@netlify

netlify Bot commented Aug 13, 2026

Copy link
Copy Markdown

Deploy Preview for h-test ready!

Name Link
🔨 Latest commit 368dae3
🔍 Latest deploy log https://app.netlify.com/projects/h-test/deploys/6a7da485e7923d00083765ea
😎 Deploy Preview https://deploy-preview-180--h-test.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Node env mutates every loaded module's default export with a .file property, corrupting non-test data modules

1 participant