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());
return resolveFile(path, fs.pathJoin(phantom.casperPath, 'modules'));
}
function nodeModulePath(path) {
return resolveFile(path, fs.pathJoin(getCurrentScriptRoot(), 'node_modules'));
var resolved, prevBaseDir;
var baseDir = getCurrentScriptRoot();
do {
resolved = resolveFile(path, fs.pathJoin(baseDir, 'node_modules'));
prevBaseDir = baseDir;
baseDir = fs.absolute(fs.pathJoin(prevBaseDir, '..'));
} while (!resolved && baseDir !== '/' && baseDir !== prevBaseDir);
return resolved;
}
function localModulePath(path) {
return resolveFile(path, phantom.casperScriptBaseDir || fs.workingDirectory);
......
var casper = require('casper').create();
var foo = require('foo');
console.log(foo);
casper.exit();
......@@ -198,6 +198,10 @@ class RequireWithRelativeScriptPathTest(CasperExecTestBase):
def test_node_module_require_json(self):
self.assertCommandOutputEquals('./test_node_json.js', '42')
@timeout(20)
def test_node_module_require_subdir(self):
self.assertCommandOutputEquals('./test_node_subdir/test_node_mod.js', '42')
class ScriptOutputTest(CasperExecTestBase):
@timeout(20)
......