Directory structure:
./index.js
./a/index.js
./a/util.js
./b/index.js
./b/util.js
Files:
// ./index.js
const proxyquire = require('proxyquire');
proxyquire('./a/index.js', {"./util": {c: "c"}});
// ./a/index.js
const util = require('./util');
require('../b');
console.log(util);
// ./a/util.js
exports.a = "a";
// ./b/index.js
const util = require('./util');
// ./b/util.js
exports.b = "b";
Expected behavior:
index.js requires ./a/index.js via proxyquire, and overrides the propery c of './util.js. Since a/util.jsdefines a propertya, we would expect the console.log()in./a/index.js` to print:
Actual behavior:
{ c: 'c', a: 'a', b: 'b' }
Every time any file does require('./util'), proxyquire requires the file, and merges it together into one giant object. This does bad things if you have two different files with the same name, that both contain the same property (which is pretty common in ES6 land, where we often export default ...).
Directory structure:
Files:
Expected behavior:
index.jsrequires./a/index.jsvia proxyquire, and overrides the properycof './util.js. Sincea/util.jsdefines a propertya, we would expect theconsole.log()in./a/index.js` to print:Actual behavior:
Every time any file does
require('./util'), proxyquire requires the file, and merges it together into one giant object. This does bad things if you have two different files with the same name, that both contain the same property (which is pretty common in ES6 land, where we oftenexport default ...).