Commit eb4be25d eb4be25d4122410d64db845b644ab630c6eebd3a by Nicolas Perriault

Merge pull request #609 from laurentj/issue-601

Fixes a regression on sub module loading
2 parents 1031b264 a6e6b04f
......@@ -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();
......@@ -9,7 +9,11 @@ import unittest
TEST_ROOT = os.path.abspath(os.path.dirname(__file__))
CASPERJS_ROOT = os.path.abspath(os.path.join(TEST_ROOT, '..', '..'))
CASPER_EXEC = os.path.join(CASPERJS_ROOT, 'bin', 'casperjs')
PHANTOMJS_EXEC = os.environ['PHANTOMJS_EXECUTABLE']
# make it to an absolute path, because some test change the working directory
# and relative path to phantomjs would be invalid
if not os.path.isabs(PHANTOMJS_EXEC):
os.environ['PHANTOMJS_EXECUTABLE'] = os.path.join(CASPERJS_ROOT, PHANTOMJS_EXEC)
class TimeoutException(Exception):
pass
......@@ -49,7 +53,7 @@ class CasperExecTestBase(unittest.TestCase):
except subprocess.CalledProcessError as err:
if failing:
return err.output.decode('utf-8')
raise IOError('Command %s exited: %s' % (cmd, err))
raise IOError('Command %s exited: %s \n %s' % (cmd, err, err.output.decode('utf-8')))
def assertCommandOutputEquals(self, cmd, result, **kwargs):
self.assertEqual(self.runCommand(cmd), result)
......@@ -74,7 +78,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 +105,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):
......