https://github.com/bendrucker/proxyquire-universal
Proxyquire in Node and Proxyquireify in the browser with no code changes
https://github.com/bendrucker/proxyquire-universal
Last synced: over 1 year ago
JSON representation
Proxyquire in Node and Proxyquireify in the browser with no code changes
- Host: GitHub
- URL: https://github.com/bendrucker/proxyquire-universal
- Owner: bendrucker
- License: mit
- Created: 2014-10-20T17:10:42.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2022-04-21T17:43:31.000Z (over 4 years ago)
- Last Synced: 2025-04-10T08:14:05.106Z (over 1 year ago)
- Language: JavaScript
- Size: 56.6 KB
- Stars: 35
- Watchers: 4
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# proxyquire-universal [](https://github.com/bendrucker/proxyquire-universal/actions?query=workflow%3Atests)
Browserify plugin that allows you to replace [proxyquire](https://github.com/thlorenz/proxyquire) with [proxyquireify](https://github.com/thlorenz/proxyquireify) without code changes. If you only need to run your tests in a browser, just use [proxyquireify](https://github.com/thlorenz/proxyquireify) directly. Make sure you're not using [proxyquire features that don't have proxyquireify counterparts](#unsupported-proxyquire-features).
## Installing
```sh
$ npm install --save-dev proxyquire-universal proxyquire proxyquireify
```
proxyquire-universal sets proxyquire and proxyquireify as peer dependencies so all three packages will be siblings in your `node_modules` folder. You have full control over which versions are used.
## Usage
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.
## Unsupported Proxyquire Features
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`](https://github.com/thlorenz/proxyquire#globally-override-require)
* [Disabling the `require` cache](https://github.com/thlorenz/proxyquire#forcing-proxyquire-to-reload-modules)
If you discover a case where proxyquire and proxyquireify behave differently, please [open an issue](https://github.com/bendrucker/proxyquire-universal/issues/new) with relevant code.
## License
MIT © [Ben Drucker](http://bendrucker.me)