Store test source files in a WeakMap instead of mutating module exports - #180
Open
DmitrySharabin wants to merge 1 commit into
Open
Store test source files in a WeakMap instead of mutating module exports#180DmitrySharabin wants to merge 1 commit into
DmitrySharabin wants to merge 1 commit into
Conversation
✅ Deploy Preview for h-test ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
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.
Fixes #179.
The Node env tags every loaded module's default export with a
fileproperty, butloadedFilesholds all transitively imported modules — so plain data modules got afilekey injected, shadowing real keys and leaking intoObject.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.filesis aWeakMapkeyed by the test definition, read in theTestconstructor.filestill lives on theTestinstance, so no consumer changes.Verified with the issue's repro —
TypeError: object is not iterableonmain, passes here.Note: an explicit
fileon a test definition no longer survives; the registry wins. Undocumented property, no known users.src/classes/Test.jssrc/env/node.jstests/module-tagging.jstests/fixtures/plain-module.js🤖 Generated with Claude Code