https://github.com/krasimir/hackerify
Stubbing Browserify modules
https://github.com/krasimir/hackerify
Last synced: 6 months ago
JSON representation
Stubbing Browserify modules
- Host: GitHub
- URL: https://github.com/krasimir/hackerify
- Owner: krasimir
- License: mit
- Created: 2015-06-05T22:08:59.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2015-06-06T08:22:52.000Z (over 10 years ago)
- Last Synced: 2024-12-22T17:46:27.255Z (10 months ago)
- Language: JavaScript
- Size: 148 KB
- Stars: 4
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Hackerify
* ~30 lines of JavaScript for stubbing Browserify modules.
* Defining the stubs in only one place. Works for modules required deeply in your app.## Instalation
`npm install hackerify`
## Usage
Let's say that you have the following modules:
```js
// label.js
module.exports = function() {
return 'The answer is: ';
}// answer.js
var label = require('./label');
module.exports = function() {
return label() + 42;
}// app.js
var a = require('./answer');
console.log(a());
```And you want to stub the function in `label.js`. All you have to do is adding the following code in `app.js`.
```js
// app.jsvar Hackerify = require('hackerify');
Hackerify(arguments, {
'./label': function() {
return 'The answer is not always ';
}
});var a = require('./answer');
console.log(a());
```Notice the `arguments` variable. No, that's not a typo. When you use Browserify your code is put in a closure. So `arguments` is refering the arguments passed to that closure.
## Testing
* `npm install`
* `npm test`## The example
* `npm install`
* `cd ./example`
* `sh ./run.sh`
* Open `./example/index.html` in a browser