From 816cdbe0590797feec49ef4e1f696ed935b33947 Mon Sep 17 00:00:00 2001 From: Johannes Ewald Date: Tue, 20 May 2014 12:09:13 +0200 Subject: Added istanbul for test coverage --- .istanbul.yml | 3 +++ .travis.yml | 7 ++++++- README.md | 7 ++++--- lib/rewire.js | 8 ++++++-- test/testModules/fake_node_modules/rewire/package.json | 3 --- test/testModules/module.coffee | 2 +- test/testModules/sharedTestCases.js | 5 +++++ 7 files changed, 25 insertions(+), 10 deletions(-) create mode 100644 .istanbul.yml delete mode 100644 test/testModules/fake_node_modules/rewire/package.json 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)
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 -- cgit v1.2.3