rewireify

Rewireify is a port of Rewire for Browserify that adds setter and getter methods to each module so that their behaviour can be modified for better unit testing.

This module is no longer maintained
Last updated 7 years ago by i-like-robots .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install rewireify 
SYNC missed versions from official npm registry.

Rewireify Build status

Rewireify is a port of Rewire for Browserify that adds setter and getter methods to each module so that their behaviour can be modified for better unit testing. With Rewireify you can:

  • Inject mocks for other modules
  • Leak private variables
  • Override variables within the module

Rewireify is compatible with Browserify 3+

Usage

First install and save Rewireify into your project's development dependencies:

$ npm install rewireify --save-dev

Include the Rewireify transform as part of your test bundle:

$ browserify -e app.js -o test-bundle.js -t rewireify -s test-bundle

Rewireify can also ignore certain files with the --ignore option and a filename or glob expression. Multiple files or patterns can be excluded by separating them with commas:

$ browserify -e app.js -o test-bundle.js -t [ rewireify --ignore filename.js,**/*-mixin.js ] -s test-bundle

Now you can inspect, modify and override your modules internals in your tests. The __get__ and __set__ methods are the same as Rewire:

var bundle = require("./path/to/test-bundle");

// Private variables can be leaked...
subject.__get__("secretKey");

// ...or modified
subject.__set__("secretKey", 1234);

// Nested properties can be inspected or modified
subject.__set__("user.firstname", "Joe");

// Dependencies can be mocked...
subject.__set__("config", {
  cache: false,
  https: false
});

// ...or methods stubbed
subject.__set__("http.get", function(url, cb) {
  cb("This method has been stubbed");
});

// And everything can be reverted
var revert = subject.__set__("port", 3000);

revert();

For more details check out the Rewire documentation.

Current Tags

  • 0.2.5                                ...           latest (5 years ago)

19 Versions

  • 0.2.5 [deprecated]           ...           5 years ago
  • 0.2.4 [deprecated]           ...           5 years ago
  • 0.2.3 [deprecated]           ...           5 years ago
  • 0.2.2 [deprecated]           ...           5 years ago
  • 0.2.1 [deprecated]           ...           5 years ago
  • 0.2.0 [deprecated]           ...           5 years ago
  • 0.0.13 [deprecated]           ...           6 years ago
  • 0.0.12 [deprecated]           ...           6 years ago
  • 0.0.11 [deprecated]           ...           6 years ago
  • 0.0.10 [deprecated]           ...           6 years ago
  • 0.0.9 [deprecated]           ...           6 years ago
  • 0.0.8 [deprecated]           ...           6 years ago
  • 0.0.7 [deprecated]           ...           7 years ago
  • 0.0.5 [deprecated]           ...           7 years ago
  • 0.0.6 [deprecated]           ...           7 years ago
  • 0.0.4 [deprecated]           ...           7 years ago
  • 0.0.3 [deprecated]           ...           7 years ago
  • 0.0.2 [deprecated]           ...           7 years ago
  • 0.0.1 [deprecated]           ...           7 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 19
Last Day 0
Last Week 0
Last Month 0
Dependencies (1)
Dev Dependencies (3)

Copyright 2014 - 2016 © taobao.org |