Skip to content

Expose require.dumpCache() for resetting the module cache#16

Closed
benjamn wants to merge 2 commits intobrowserify:masterfrom
benjamn:expose-require.dumpCache
Closed

Expose require.dumpCache() for resetting the module cache#16
benjamn wants to merge 2 commits intobrowserify:masterfrom
benjamn:expose-require.dumpCache

Conversation

@benjamn
Copy link

@benjamn benjamn commented Jul 8, 2013

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?

benjamn added 2 commits July 8, 2013 16:18
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?
@ghost
Copy link

ghost commented Jul 9, 2013

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.

@ghost ghost closed this Jul 9, 2013
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.
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.

1 participant