if the module is not yet in require cache (.noPreserveCache() NOT being used) proxyquire will install the proxied module in require cache
opened this issue · comments
// a.js
exports.foo = function () {require('./b').foo()}
// b.js
exports.foo = function () {console.log('foo');}
// test1.js, prints bar, bar (unexpected)
require('proxyquire')('./a', {'./b': {foo: function () {console.log('bar');}}}).foo();
require('./a').foo();
// test2.js, prints bar, foo (expected)
require('./a');
require('proxyquire')('./a', {'./b': {foo: function () {console.log('bar');}}}).foo();
require('./a').foo();
That's expected, proxyquire uses the normal require cache by default
still feels like a bug, IMHO if the module is not yet in the require cache proxyquire should
option 1) install the original, not yet proxified module in the cache 1st, so that later calls to require can get the unmodified version, and carry on as usual
option 2) leave the cache empty, so that later calls to require can install the original version
anyway, thanks for looking into it