Permalink
Browse files

Add code to load mocks as if from script

  • Loading branch information...
1 parent e7766d6 commit f6567780e22020f398de792c34e168cef6e7c871 Scott McWhirter committed Jun 29, 2012
Showing with 7 additions and 3 deletions.
  1. +6 −2 lib/index.js
  2. +1 −1 package.json
View
@@ -26,9 +26,13 @@ module = module.exports = function (mock_path, libs){
return path.match(new RegExp(libname+'$'));
});
- if(foo.length > 0)
+ if(foo.length > 0) {
new_path = mock_path + p.normalize('/' + path);
-
+ // If we're using a mock lib, load it as if it was being loaded
+ // from the main script (for require() behaviour)
+ self.parent = process.mainModule;
+ }
+
return orig_req.apply(self, [new_path]);
}
}
View
@@ -1,7 +1,7 @@
{
"name": "mocked",
"description": "A small library to enable lightweight mocking for tests",
- "version": "0.0.1",
+ "version": "0.0.2",
"main": "lib/index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"

0 comments on commit f656778

Please sign in to comment.