Expose require.dumpCache() for resetting the module cache#16
Closed
benjamn wants to merge 2 commits intobrowserify:masterfrom
Closed
Expose require.dumpCache() for resetting the module cache#16benjamn wants to merge 2 commits intobrowserify:masterfrom
benjamn wants to merge 2 commits intobrowserify:masterfrom
Conversation
This way it's much easier to know how the value of the cache variable was initialized. Were there any use cases that depended on creating the cache elsewhere?
Resetting the module cache is an important point of hygiene when running multiple tests, and sometimes within a single test, because it prevents earlier test activity from interfering with current test behavior. Without modifying prelude.js, it seems to be impossible to modify the cache in any way. Unfortunately, shipping a modified version of prelude.js requires forking both browserify and browser-pack. The other option would be to use something other than browserify for tests, but then the benefits of end-to-end testing the actual browserified bundle are lost. Am I missing an easier way of clearing the cache?
|
This is wonky and not a use-case I'm interested in supporting. If you really actually need to get uncached module references, you could generate separate bundles for each test file. I really don't see why you even need to invalidate the module cache in the first place. |
pcaronde
pushed a commit
to pcaronde/react
that referenced
this pull request
May 21, 2024
This is far from ideal, but it seems to be the easiest way to expose the
require.dumpCache method for use by require("mock-modules").dumpCache.
Upstream patch that would make this hack unnecessary if accepted:
browserify/browser-pack#16
pcaronde
pushed a commit
to pcaronde/react
that referenced
this pull request
May 21, 2024
This is far from ideal, but it seems to be the easiest way to expose the
require.dumpCache method for use by require("mock-modules").dumpCache.
Upstream patch that would make this hack unnecessary if accepted:
browserify/browser-pack#16
This pull request was closed.
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.
Resetting the module cache is an important point of hygiene when running multiple tests, and sometimes within a single test, because it prevents earlier test activity from interfering with current test behavior.
Without modifying prelude.js, it seems to be impossible to modify the cache in any way. Unfortunately, shipping a modified version of prelude.js requires forking both browserify and browser-pack.
Another option would be to use something other than browserify for tests, but then the benefits of end-to-end testing of the actual browserified bundle would be lost.
Am I missing an easier way of clearing the cache?