Commit 40a0edc2 40a0edc2d553c7efb86d35d266e53eb5edf066a0 by Laurent Jouanneau

Fixes a regression on sub module loading

CasperJS didn't find any more users modules, when we
indicate only the name of the main script (it worked only
when we indicate the full path of the script on the command line).

Fixes #601
1 parent be96826c
......@@ -190,9 +190,9 @@ CasperError.prototype = Object.getPrototypeOf(new Error());
var basenames = [path, path + '/index'];
var paths = [];
basenames.forEach(function(basename) {
paths.push(fs.pathJoin(dir, basename));
paths.push(fs.absolute(fs.pathJoin(dir, basename)));
extensions.forEach(function(extension) {
paths.push(fs.pathJoin(dir, [basename, extension].join('.')));
paths.push(fs.absolute(fs.pathJoin(dir, [basename, extension].join('.'))));
});
});
for (var i = 0; i < paths.length; i++) {
......@@ -200,6 +200,7 @@ CasperError.prototype = Object.getPrototypeOf(new Error());
return paths[i];
}
}
return null;
}
function getCurrentScriptRoot() {
if ((phantom.casperScriptBaseDir || "").indexOf(fs.workingDirectory) === 0) {
......
var require = patchRequire(require);
var casper = require('casper').create();
var mod = require('./mod');
console.log(mod.hello);
casper.exit();
......@@ -74,7 +74,7 @@ class BasicCommandsTest(CasperExecTestBase):
self.assertCommandOutputContains('--help', self.pkg_version)
class RequireTest(CasperExecTestBase):
class RequireScriptFullPathTest(CasperExecTestBase):
@timeout(20)
def test_simple_require(self):
script_path = os.path.join(TEST_ROOT, 'modules', 'test.js')
......@@ -101,6 +101,77 @@ class RequireTest(CasperExecTestBase):
self.assertCommandOutputEquals(script_path, '42')
class RequireWithOnlyScriptNameTest(CasperExecTestBase):
def setUp(self):
self.currentPath = os.getcwd()
os.chdir(os.path.join(TEST_ROOT, 'modules'))
super(RequireWithOnlyScriptNameTest, self).setUp()
def tearDown(self):
os.chdir(self.currentPath)
super(RequireWithOnlyScriptNameTest, self).tearDown()
@timeout(20)
def test_simple_require(self):
self.assertCommandOutputEquals('test.js', 'hello, world')
@timeout(20)
def test_simple_patched_require(self):
self.assertCommandOutputEquals('test_patched_require.js', 'hello, world')
@timeout(20)
def test_require_coffee(self):
self.assertCommandOutputEquals('test_coffee.js', '42')
@timeout(20)
def test_node_module_require(self):
self.assertCommandOutputEquals('test_node_mod.js', '42')
@timeout(20)
def test_node_module_require_index(self):
self.assertCommandOutputEquals('test_node_mod_index.js', '42')
@timeout(20)
def test_node_module_require_json(self):
self.assertCommandOutputEquals('test_node_json.js', '42')
class RequireWithRelativeScriptPathTest(CasperExecTestBase):
def setUp(self):
self.currentPath = os.getcwd()
os.chdir(os.path.join(TEST_ROOT, 'modules'))
super(RequireWithRelativeScriptPathTest, self).setUp()
def tearDown(self):
os.chdir(self.currentPath)
super(RequireWithRelativeScriptPathTest, self).tearDown()
@timeout(20)
def test_simple_require(self):
self.assertCommandOutputEquals('./test.js', 'hello, world')
@timeout(20)
def test_simple_patched_require(self):
self.assertCommandOutputEquals('test_patched_require.js', 'hello, world')
@timeout(20)
def test_require_coffee(self):
self.assertCommandOutputEquals('./test_coffee.js', '42')
@timeout(20)
def test_node_module_require(self):
self.assertCommandOutputEquals('./test_node_mod.js', '42')
@timeout(20)
def test_node_module_require_index(self):
self.assertCommandOutputEquals('./test_node_mod_index.js', '42')
@timeout(20)
def test_node_module_require_json(self):
self.assertCommandOutputEquals('./test_node_json.js', '42')
class ScriptOutputTest(CasperExecTestBase):
@timeout(20)
def test_simple_script(self):
......