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()); ...@@ -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) {
......
1 var require = patchRequire(require);
2 var casper = require('casper').create();
3 var mod = require('./mod');
4 console.log(mod.hello);
5 casper.exit();
...@@ -74,7 +74,7 @@ class BasicCommandsTest(CasperExecTestBase): ...@@ -74,7 +74,7 @@ class BasicCommandsTest(CasperExecTestBase):
74 self.assertCommandOutputContains('--help', self.pkg_version) 74 self.assertCommandOutputContains('--help', self.pkg_version)
75 75
76 76
77 class RequireTest(CasperExecTestBase): 77 class RequireScriptFullPathTest(CasperExecTestBase):
78 @timeout(20) 78 @timeout(20)
79 def test_simple_require(self): 79 def test_simple_require(self):
80 script_path = os.path.join(TEST_ROOT, 'modules', 'test.js') 80 script_path = os.path.join(TEST_ROOT, 'modules', 'test.js')
...@@ -101,6 +101,77 @@ class RequireTest(CasperExecTestBase): ...@@ -101,6 +101,77 @@ class RequireTest(CasperExecTestBase):
101 self.assertCommandOutputEquals(script_path, '42') 101 self.assertCommandOutputEquals(script_path, '42')
102 102
103 103
104
105 class RequireWithOnlyScriptNameTest(CasperExecTestBase):
106
107 def setUp(self):
108 self.currentPath = os.getcwd()
109 os.chdir(os.path.join(TEST_ROOT, 'modules'))
110 super(RequireWithOnlyScriptNameTest, self).setUp()
111
112 def tearDown(self):
113 os.chdir(self.currentPath)
114 super(RequireWithOnlyScriptNameTest, self).tearDown()
115
116 @timeout(20)
117 def test_simple_require(self):
118 self.assertCommandOutputEquals('test.js', 'hello, world')
119
120 @timeout(20)
121 def test_simple_patched_require(self):
122 self.assertCommandOutputEquals('test_patched_require.js', 'hello, world')
123
124 @timeout(20)
125 def test_require_coffee(self):
126 self.assertCommandOutputEquals('test_coffee.js', '42')
127
128 @timeout(20)
129 def test_node_module_require(self):
130 self.assertCommandOutputEquals('test_node_mod.js', '42')
131
132 @timeout(20)
133 def test_node_module_require_index(self):
134 self.assertCommandOutputEquals('test_node_mod_index.js', '42')
135
136 @timeout(20)
137 def test_node_module_require_json(self):
138 self.assertCommandOutputEquals('test_node_json.js', '42')
139
140 class RequireWithRelativeScriptPathTest(CasperExecTestBase):
141
142 def setUp(self):
143 self.currentPath = os.getcwd()
144 os.chdir(os.path.join(TEST_ROOT, 'modules'))
145 super(RequireWithRelativeScriptPathTest, self).setUp()
146
147 def tearDown(self):
148 os.chdir(self.currentPath)
149 super(RequireWithRelativeScriptPathTest, self).tearDown()
150
151 @timeout(20)
152 def test_simple_require(self):
153 self.assertCommandOutputEquals('./test.js', 'hello, world')
154
155 @timeout(20)
156 def test_simple_patched_require(self):
157 self.assertCommandOutputEquals('test_patched_require.js', 'hello, world')
158
159 @timeout(20)
160 def test_require_coffee(self):
161 self.assertCommandOutputEquals('./test_coffee.js', '42')
162
163 @timeout(20)
164 def test_node_module_require(self):
165 self.assertCommandOutputEquals('./test_node_mod.js', '42')
166
167 @timeout(20)
168 def test_node_module_require_index(self):
169 self.assertCommandOutputEquals('./test_node_mod_index.js', '42')
170
171 @timeout(20)
172 def test_node_module_require_json(self):
173 self.assertCommandOutputEquals('./test_node_json.js', '42')
174
104 class ScriptOutputTest(CasperExecTestBase): 175 class ScriptOutputTest(CasperExecTestBase):
105 @timeout(20) 176 @timeout(20)
106 def test_simple_script(self): 177 def test_simple_script(self):
......