Commit 572224b5 572224b589baef8cf334fd208364115d36792dad by Nicolas Perriault

Merge pull request #991 from jazzzz/master

Search node_modules in parent directories until the root is reached
2 parents b62c37d9 2d6583a9
...@@ -248,7 +248,14 @@ CasperError.prototype = Object.getPrototypeOf(new Error()); ...@@ -248,7 +248,14 @@ CasperError.prototype = Object.getPrototypeOf(new Error());
248 return resolveFile(path, fs.pathJoin(phantom.casperPath, 'modules')); 248 return resolveFile(path, fs.pathJoin(phantom.casperPath, 'modules'));
249 } 249 }
250 function nodeModulePath(path) { 250 function nodeModulePath(path) {
251 return resolveFile(path, fs.pathJoin(getCurrentScriptRoot(), 'node_modules')); 251 var resolved, prevBaseDir;
252 var baseDir = getCurrentScriptRoot();
253 do {
254 resolved = resolveFile(path, fs.pathJoin(baseDir, 'node_modules'));
255 prevBaseDir = baseDir;
256 baseDir = fs.absolute(fs.pathJoin(prevBaseDir, '..'));
257 } while (!resolved && baseDir !== '/' && baseDir !== prevBaseDir);
258 return resolved;
252 } 259 }
253 function localModulePath(path) { 260 function localModulePath(path) {
254 return resolveFile(path, phantom.casperScriptBaseDir || fs.workingDirectory); 261 return resolveFile(path, phantom.casperScriptBaseDir || fs.workingDirectory);
......
1 var casper = require('casper').create();
2 var foo = require('foo');
3 console.log(foo);
4 casper.exit();
...@@ -198,6 +198,10 @@ class RequireWithRelativeScriptPathTest(CasperExecTestBase): ...@@ -198,6 +198,10 @@ class RequireWithRelativeScriptPathTest(CasperExecTestBase):
198 def test_node_module_require_json(self): 198 def test_node_module_require_json(self):
199 self.assertCommandOutputEquals('./test_node_json.js', '42') 199 self.assertCommandOutputEquals('./test_node_json.js', '42')
200 200
201 @timeout(20)
202 def test_node_module_require_subdir(self):
203 self.assertCommandOutputEquals('./test_node_subdir/test_node_mod.js', '42')
204
201 205
202 class ScriptOutputTest(CasperExecTestBase): 206 class ScriptOutputTest(CasperExecTestBase):
203 @timeout(20) 207 @timeout(20)
......