Merge pull request #609 from laurentj/issue-601
Fixes a regression on sub module loading
Showing
3 changed files
with
86 additions
and
5 deletions
... | @@ -190,9 +190,9 @@ CasperError.prototype = Object.getPrototypeOf(new Error()); | ... | @@ -190,9 +190,9 @@ CasperError.prototype = Object.getPrototypeOf(new Error()); |
190 | var basenames = [path, path + '/index']; | 190 | var basenames = [path, path + '/index']; |
191 | var paths = []; | 191 | var paths = []; |
192 | basenames.forEach(function(basename) { | 192 | basenames.forEach(function(basename) { |
193 | paths.push(fs.pathJoin(dir, basename)); | 193 | paths.push(fs.absolute(fs.pathJoin(dir, basename))); |
194 | extensions.forEach(function(extension) { | 194 | extensions.forEach(function(extension) { |
195 | paths.push(fs.pathJoin(dir, [basename, extension].join('.'))); | 195 | paths.push(fs.absolute(fs.pathJoin(dir, [basename, extension].join('.')))); |
196 | }); | 196 | }); |
197 | }); | 197 | }); |
198 | for (var i = 0; i < paths.length; i++) { | 198 | for (var i = 0; i < paths.length; i++) { |
... | @@ -200,6 +200,7 @@ CasperError.prototype = Object.getPrototypeOf(new Error()); | ... | @@ -200,6 +200,7 @@ CasperError.prototype = Object.getPrototypeOf(new Error()); |
200 | return paths[i]; | 200 | return paths[i]; |
201 | } | 201 | } |
202 | } | 202 | } |
203 | return null; | ||
203 | } | 204 | } |
204 | function getCurrentScriptRoot() { | 205 | function getCurrentScriptRoot() { |
205 | if ((phantom.casperScriptBaseDir || "").indexOf(fs.workingDirectory) === 0) { | 206 | if ((phantom.casperScriptBaseDir || "").indexOf(fs.workingDirectory) === 0) { | ... | ... |
... | @@ -9,7 +9,11 @@ import unittest | ... | @@ -9,7 +9,11 @@ import unittest |
9 | TEST_ROOT = os.path.abspath(os.path.dirname(__file__)) | 9 | TEST_ROOT = os.path.abspath(os.path.dirname(__file__)) |
10 | CASPERJS_ROOT = os.path.abspath(os.path.join(TEST_ROOT, '..', '..')) | 10 | CASPERJS_ROOT = os.path.abspath(os.path.join(TEST_ROOT, '..', '..')) |
11 | CASPER_EXEC = os.path.join(CASPERJS_ROOT, 'bin', 'casperjs') | 11 | CASPER_EXEC = os.path.join(CASPERJS_ROOT, 'bin', 'casperjs') |
12 | 12 | PHANTOMJS_EXEC = os.environ['PHANTOMJS_EXECUTABLE'] | |
13 | # make it to an absolute path, because some test change the working directory | ||
14 | # and relative path to phantomjs would be invalid | ||
15 | if not os.path.isabs(PHANTOMJS_EXEC): | ||
16 | os.environ['PHANTOMJS_EXECUTABLE'] = os.path.join(CASPERJS_ROOT, PHANTOMJS_EXEC) | ||
13 | 17 | ||
14 | class TimeoutException(Exception): | 18 | class TimeoutException(Exception): |
15 | pass | 19 | pass |
... | @@ -49,7 +53,7 @@ class CasperExecTestBase(unittest.TestCase): | ... | @@ -49,7 +53,7 @@ class CasperExecTestBase(unittest.TestCase): |
49 | except subprocess.CalledProcessError as err: | 53 | except subprocess.CalledProcessError as err: |
50 | if failing: | 54 | if failing: |
51 | return err.output.decode('utf-8') | 55 | return err.output.decode('utf-8') |
52 | raise IOError('Command %s exited: %s' % (cmd, err)) | 56 | raise IOError('Command %s exited: %s \n %s' % (cmd, err, err.output.decode('utf-8'))) |
53 | 57 | ||
54 | def assertCommandOutputEquals(self, cmd, result, **kwargs): | 58 | def assertCommandOutputEquals(self, cmd, result, **kwargs): |
55 | self.assertEqual(self.runCommand(cmd), result) | 59 | self.assertEqual(self.runCommand(cmd), result) |
... | @@ -74,7 +78,7 @@ class BasicCommandsTest(CasperExecTestBase): | ... | @@ -74,7 +78,7 @@ class BasicCommandsTest(CasperExecTestBase): |
74 | self.assertCommandOutputContains('--help', self.pkg_version) | 78 | self.assertCommandOutputContains('--help', self.pkg_version) |
75 | 79 | ||
76 | 80 | ||
77 | class RequireTest(CasperExecTestBase): | 81 | class RequireScriptFullPathTest(CasperExecTestBase): |
78 | @timeout(20) | 82 | @timeout(20) |
79 | def test_simple_require(self): | 83 | def test_simple_require(self): |
80 | script_path = os.path.join(TEST_ROOT, 'modules', 'test.js') | 84 | script_path = os.path.join(TEST_ROOT, 'modules', 'test.js') |
... | @@ -101,6 +105,77 @@ class RequireTest(CasperExecTestBase): | ... | @@ -101,6 +105,77 @@ class RequireTest(CasperExecTestBase): |
101 | self.assertCommandOutputEquals(script_path, '42') | 105 | self.assertCommandOutputEquals(script_path, '42') |
102 | 106 | ||
103 | 107 | ||
108 | |||
109 | class RequireWithOnlyScriptNameTest(CasperExecTestBase): | ||
110 | |||
111 | def setUp(self): | ||
112 | self.currentPath = os.getcwd() | ||
113 | os.chdir(os.path.join(TEST_ROOT, 'modules')) | ||
114 | super(RequireWithOnlyScriptNameTest, self).setUp() | ||
115 | |||
116 | def tearDown(self): | ||
117 | os.chdir(self.currentPath) | ||
118 | super(RequireWithOnlyScriptNameTest, self).tearDown() | ||
119 | |||
120 | @timeout(20) | ||
121 | def test_simple_require(self): | ||
122 | self.assertCommandOutputEquals('test.js', 'hello, world') | ||
123 | |||
124 | @timeout(20) | ||
125 | def test_simple_patched_require(self): | ||
126 | self.assertCommandOutputEquals('test_patched_require.js', 'hello, world') | ||
127 | |||
128 | @timeout(20) | ||
129 | def test_require_coffee(self): | ||
130 | self.assertCommandOutputEquals('test_coffee.js', '42') | ||
131 | |||
132 | @timeout(20) | ||
133 | def test_node_module_require(self): | ||
134 | self.assertCommandOutputEquals('test_node_mod.js', '42') | ||
135 | |||
136 | @timeout(20) | ||
137 | def test_node_module_require_index(self): | ||
138 | self.assertCommandOutputEquals('test_node_mod_index.js', '42') | ||
139 | |||
140 | @timeout(20) | ||
141 | def test_node_module_require_json(self): | ||
142 | self.assertCommandOutputEquals('test_node_json.js', '42') | ||
143 | |||
144 | class RequireWithRelativeScriptPathTest(CasperExecTestBase): | ||
145 | |||
146 | def setUp(self): | ||
147 | self.currentPath = os.getcwd() | ||
148 | os.chdir(os.path.join(TEST_ROOT, 'modules')) | ||
149 | super(RequireWithRelativeScriptPathTest, self).setUp() | ||
150 | |||
151 | def tearDown(self): | ||
152 | os.chdir(self.currentPath) | ||
153 | super(RequireWithRelativeScriptPathTest, self).tearDown() | ||
154 | |||
155 | @timeout(20) | ||
156 | def test_simple_require(self): | ||
157 | self.assertCommandOutputEquals('./test.js', 'hello, world') | ||
158 | |||
159 | @timeout(20) | ||
160 | def test_simple_patched_require(self): | ||
161 | self.assertCommandOutputEquals('test_patched_require.js', 'hello, world') | ||
162 | |||
163 | @timeout(20) | ||
164 | def test_require_coffee(self): | ||
165 | self.assertCommandOutputEquals('./test_coffee.js', '42') | ||
166 | |||
167 | @timeout(20) | ||
168 | def test_node_module_require(self): | ||
169 | self.assertCommandOutputEquals('./test_node_mod.js', '42') | ||
170 | |||
171 | @timeout(20) | ||
172 | def test_node_module_require_index(self): | ||
173 | self.assertCommandOutputEquals('./test_node_mod_index.js', '42') | ||
174 | |||
175 | @timeout(20) | ||
176 | def test_node_module_require_json(self): | ||
177 | self.assertCommandOutputEquals('./test_node_json.js', '42') | ||
178 | |||
104 | class ScriptOutputTest(CasperExecTestBase): | 179 | class ScriptOutputTest(CasperExecTestBase): |
105 | @timeout(20) | 180 | @timeout(20) |
106 | def test_simple_script(self): | 181 | def test_simple_script(self): | ... | ... |
-
Please register or sign in to post a comment