diff options
author | Johannes <mail@johannesewald.de> | 2012-06-04 02:23:27 +0400 |
---|---|---|
committer | Johannes <mail@johannesewald.de> | 2012-06-04 02:23:27 +0400 |
commit | b4b2794f5a5e5977e048ff777ac53263144126e6 (patch) | |
tree | 11213db4acbb4bd220069bd426b83d9739339379 /lib | |
parent | d4eea33555f4e67be674c046ff1d1a9a460af94a (diff) |
changed repo-name to rewire
Diffstat (limited to 'lib')
-rw-r--r-- | lib/index.js | 4 | ||||
-rw-r--r-- | lib/rewire.js (renamed from lib/trick.js) | 15 |
2 files changed, 10 insertions, 9 deletions
diff --git a/lib/index.js b/lib/index.js index f8f57ca..097a7b8 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,6 +1,6 @@ "use strict"; // run code in ES5 strict mode
-var trick = require("./trick.js");
+var rewire = require("./rewire.js");
module.exports = function (request, mocks, injections, leaks, cache) {
delete require.cache[__filename]; // deleting self from module cache so the parent module is always up to date
@@ -9,5 +9,5 @@ module.exports = function (request, mocks, injections, leaks, cache) { cache = true;
}
- return trick(module.parent, request, mocks, injections, leaks, cache);
+ return rewire(module.parent, request, mocks, injections, leaks, cache);
};
\ No newline at end of file diff --git a/lib/trick.js b/lib/rewire.js index 89cbe32..0f96e4d 100644 --- a/lib/trick.js +++ b/lib/rewire.js @@ -7,13 +7,13 @@ var Module = require("module"), getInjectionSrc = require("./getInjectionSrc.js");
function restoreOriginalWrappers() {
- Module.wrapper[0] = nodeWrapper0;
Module.wrapper[1] = nodeWrapper1;
}
-function trick(parentModule, filename, mocks, injections, leaks, cache) {
+function rewire(parentModule, filename, mocks, injections, leaks, cache) {
var testModule,
- nodeRequire;
+ nodeRequire,
+ wrapperExtensions = "";
function requireTrick(path) {
restoreOriginalWrappers(); // we need to restore the wrappers now so we don't influence other modules
@@ -37,15 +37,16 @@ function trick(parentModule, filename, mocks, injections, leaks, cache) { // Prepare module for injection
if (typeof injections === "object") {
- Module.wrapper[0] = nodeWrapper0 + getInjectionSrc(injections);
+ wrapperExtensions += getInjectionSrc(injections);
} else if (typeof injections === "string") {
- Module.wrapper[0] = nodeWrapper0 + injections;
+ wrapperExtensions += injections;
}
// Prepare module for leaking private vars
if (Array.isArray(leaks)) {
- Module.wrapper[1] = getLeakingSrc(leaks) + nodeWrapper1;
+ wrapperExtensions += getLeakingSrc(leaks);
}
+ Module.wrapper[1] = wrapperExtensions + nodeWrapper1;
// Mocking module.require-function
testModule.require = requireTrick;
@@ -61,4 +62,4 @@ function trick(parentModule, filename, mocks, injections, leaks, cache) { return testModule.exports;
}
-module.exports = trick;
\ No newline at end of file +module.exports = rewire;
\ No newline at end of file |