Proxyquire in Node and Proxyquireify in the browser with no code changes
npm install proxyquire-universalBrowserify plugin that allows you to replace proxyquire with proxyquireify without code changes. If you only need to run your tests in a browser, just use proxyquireify directly. Make sure you're not using proxyquire features that don't have proxyquireify counterparts.
``sh`
$ npm install --save-dev proxyquire-universal proxyquire proxyquireifynode_modules
proxyquire-universal sets proxyquire and proxyquireify as peer dependencies so all three packages will be siblings in your folder. You have full control over which versions are used.
Write your tests for Node:
`js`
var proxyquire = require('proxyquire');
proxyquire('./a', stubs);
Then add the 'proxyquire-universal' plugin when you build your test bundle for the browser:
`js`
browserify()
.plugin('proxyquire-universal')
.bundle()
.pipe(fs.createWriteStream('test-bundle.js'));
proxyquire-universal takes care of calling bundle.plugin(proxyquireify.plugin) automatically. You should not register proxyquireify manually.
proxyquireify has a very similar API to proxyquire and will be a perfect drop-in replacement for most use cases. However, there are certain proxyquire features that are not available in proxyquireify:
* Globally overriding require
* Disabling the require` cache
If you discover a case where proxyquire and proxyquireify behave differently, please open an issue with relevant code.
MIT © Ben Drucker