require-stash
v1.0.0
Published
Evict a module from `require.cache` so the next `require` re-evaluates it fresh, with a `restore` to put the original back
Maintainers
Readme
require-stash 
Evict a module from require.cache so the next require re-evaluates it fresh — and get back a restore function that puts the original cached module back exactly as it was.
It's the eager, restorable counterpart to deleting a require.cache entry by hand: useful in tests that need to load a module under a mutated environment (a swapped global, a deleted intrinsic) and then leave the cache exactly as they found it.
Example
var requireStash = require('require-stash');
var assert = require('assert');
var before = require('resolve');
var restore = requireStash(__dirname, 'resolve'); // evicted from require.cache
assert.notEqual(require('resolve'), before); // re-evaluated: a fresh instance
restore();
assert.equal(require('resolve'), before); // the original is back in the cacheIn a tape test, register the returned restore as the teardown, then require normally to observe the module under a mutation — e.g. t.teardown(requireStash(__dirname, '../')) evicts ../ immediately and puts the original back when the test ends, while var underTest = require('../') in the body re-evaluates it under whatever global state the test has set up.
id may be relative ('../') or a bare specifier ('get-intrinsic'); it's resolved from dirname.

