Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/twbs/rewire.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Ewald <johannes.ewald@peerigon.com>2014-05-20 14:09:13 +0400
committerJohannes Ewald <johannes.ewald@peerigon.com>2014-05-20 14:09:13 +0400
commit816cdbe0590797feec49ef4e1f696ed935b33947 (patch)
treed76fa3f632fd0be3cc1b14951c2629bd1373dfd9
parent125d7e2f4ec12eeb66c2ebc7e4e27d56cb7f1505 (diff)
Added istanbul for test coverage
-rw-r--r--.istanbul.yml3
-rw-r--r--.travis.yml7
-rw-r--r--README.md7
-rw-r--r--lib/rewire.js8
-rw-r--r--test/testModules/fake_node_modules/rewire/package.json3
-rw-r--r--test/testModules/module.coffee2
-rw-r--r--test/testModules/sharedTestCases.js5
7 files changed, 25 insertions, 10 deletions
diff --git a/.istanbul.yml b/.istanbul.yml
new file mode 100644
index 0000000..480671f
--- /dev/null
+++ b/.istanbul.yml
@@ -0,0 +1,3 @@
+instrumentation:
+ # __get__ and __set__ will be stringified and evaled again. Thus it's difficult to include them into the test coverage
+ excludes: ['lib/__get__.js', 'lib/__set__.js'] \ No newline at end of file
diff --git a/.travis.yml b/.travis.yml
index f162fbb..5257b85 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -2,6 +2,11 @@ language: node_js
node_js:
- "0.8"
- "0.10"
+ - "0.11"
script:
- - npm test \ No newline at end of file
+ - npm test
+after_success:
+ - npm install -g istanbul
+ - npm install coveralls
+ - istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -R spec && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage \ No newline at end of file
diff --git a/README.md b/README.md
index 963a08b..2ab584c 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,6 @@
rewire
=====
-**Dependency injection for node.js applications**.
+**Easy dependency injection for node.js unit testing**.
rewire adds a special setter and getter to modules so you can modify their behaviour for better unit testing. You may
@@ -17,8 +17,9 @@ case CoffeeScript needs to be listed in your devDependencies.
If you want to use rewire also on the client-side take a look at [client-side bundlers](https://github.com/jhnns/rewire#client-side-bundlers)
-[![Build Status](https://secure.travis-ci.org/jhnns/rewire.png?branch=master)](http://travis-ci.org/jhnns/rewire)
-[![Dependency Status](https://david-dm.org/jhnns/rewire/status.png)](http://david-dm.org/jhnns/rewire)
+[![Build Status](https://travis-ci.org/jhnns/rewire.svg?branch=master)](http://travis-ci.org/jhnns/rewire)
+[![Dependency Status](https://david-dm.org/jhnns/rewire.svg)](https://david-dm.org/jhnns/rewire)
+[![Coverage Status](https://coveralls.io/repos/jhnns/rewire/badge.png)](https://coveralls.io/r/jhnns/rewire)
<br />
diff --git a/lib/rewire.js b/lib/rewire.js
index bb7c176..3daacef 100644
--- a/lib/rewire.js
+++ b/lib/rewire.js
@@ -6,6 +6,9 @@ var Module = require("module"),
detectStrictMode = require("./detectStrictMode.js"),
moduleEnv = require("./moduleEnv.js");
+var __get__Src = __get__.toString(),
+ __set__Src = __set__.toString();
+
/**
* Does actual rewiring the module. For further documentation @see index.js
*/
@@ -26,6 +29,7 @@ function internalRewire(parentModulePath, targetPath) {
// Special support for older node versions that returned an array on Module._resolveFilename
// @see https://github.com/joyent/node/blob/865b077819a9271a29f982faaef99dc635b57fbc/lib/module.js#L319
// TODO Remove this switch on the next major release
+ /* istanbul ignore next because it will be removed soon */
if (Array.isArray(targetPath)) {
targetPath = targetPath[1];
}
@@ -38,8 +42,8 @@ function internalRewire(parentModulePath, targetPath) {
// We append our special setter and getter.
appendix = "\n";
- appendix += "module.exports.__set__ = " + __set__.toString() + "; ";
- appendix += "module.exports.__get__ = " + __get__.toString() + "; ";
+ appendix += "module.exports.__set__ = " + __set__Src + "; ";
+ appendix += "module.exports.__get__ = " + __get__Src + "; ";
// Check if the module uses the strict mode.
// If so we must ensure that "use strict"; stays at the beginning of the module.
diff --git a/test/testModules/fake_node_modules/rewire/package.json b/test/testModules/fake_node_modules/rewire/package.json
deleted file mode 100644
index d8927cd..0000000
--- a/test/testModules/fake_node_modules/rewire/package.json
+++ /dev/null
@@ -1,3 +0,0 @@
-{
- "main": "../../../../lib/index.js"
-} \ No newline at end of file
diff --git a/test/testModules/module.coffee b/test/testModules/module.coffee
index 02fa5d5..5487878 100644
--- a/test/testModules/module.coffee
+++ b/test/testModules/module.coffee
@@ -1,3 +1,3 @@
-fs = require "fs"
+fs = require "fs"
exports.readFileSync = () -> fs.readFileSync() \ No newline at end of file
diff --git a/test/testModules/sharedTestCases.js b/test/testModules/sharedTestCases.js
index 65537e6..3672769 100644
--- a/test/testModules/sharedTestCases.js
+++ b/test/testModules/sharedTestCases.js
@@ -175,4 +175,9 @@ describe("rewire " + (typeof testEnv === "undefined"? "(node)": "(" + testEnv +
}
}
});
+ it("should throw a TypeError if the path is not a string", function () {
+ expect(function () {
+ rewire(null);
+ }).to.throwException(checkForTypeError);
+ });
}); \ No newline at end of file