fixes #41 - injecting casperjs lib crashes cmd.exe on Windows 7
Showing
2 changed files
with
24 additions
and
3 deletions
... | @@ -54,7 +54,7 @@ phantom.loadCasper = function() { | ... | @@ -54,7 +54,7 @@ phantom.loadCasper = function() { |
54 | } | 54 | } |
55 | if (!fs.hasOwnProperty('dirname')) { | 55 | if (!fs.hasOwnProperty('dirname')) { |
56 | fs.dirname = function(path) { | 56 | fs.dirname = function(path) { |
57 | return path.replace(/\/[^\/]*\/?$/, ''); | 57 | return path.replace(/\\/g, '/').replace(/\/[^\/]*$/, ''); |
58 | }; | 58 | }; |
59 | } | 59 | } |
60 | if (!fs.hasOwnProperty('pathJoin')) { | 60 | if (!fs.hasOwnProperty('pathJoin')) { |
... | @@ -151,7 +151,7 @@ phantom.loadCasper = function() { | ... | @@ -151,7 +151,7 @@ phantom.loadCasper = function() { |
151 | } | 151 | } |
152 | // trick to locate source file location on error | 152 | // trick to locate source file location on error |
153 | scriptCode += ";var __fe__ = new CasperError('__sourceId__')"; | 153 | scriptCode += ";var __fe__ = new CasperError('__sourceId__')"; |
154 | scriptCode += ";__fe__.fileName = '" + file + "'"; | 154 | scriptCode += ";__fe__.fileName = '" + file.replace(/\\+/g, '/') + "'"; |
155 | scriptCode += ";throw __fe__;"; | 155 | scriptCode += ";throw __fe__;"; |
156 | return scriptCode; | 156 | return scriptCode; |
157 | }; | 157 | }; |
... | @@ -211,7 +211,7 @@ phantom.loadCasper = function() { | ... | @@ -211,7 +211,7 @@ phantom.loadCasper = function() { |
211 | paths.push(path); | 211 | paths.push(path); |
212 | } else { | 212 | } else { |
213 | dir = fs.absolute(requireDir); | 213 | dir = fs.absolute(requireDir); |
214 | while (dir !== '') { | 214 | while (dir !== '' && dir.lastIndexOf(':') !== dir.length - 1) { |
215 | // nodejs compatibility | 215 | // nodejs compatibility |
216 | paths.push(fs.pathJoin(dir, 'node_modules', path)); | 216 | paths.push(fs.pathJoin(dir, 'node_modules', path)); |
217 | dir = fs.dirname(dir); | 217 | dir = fs.dirname(dir); | ... | ... |
tests/suites/fs.js
0 → 100644
1 | var fs = require('fs'), t = casper.test; | ||
2 | |||
3 | // Testing added methods | ||
4 | (function() { | ||
5 | t.comment('fs.dirname()'); | ||
6 | var tests = { | ||
7 | '/local/plop/foo.js': '/local/plop', | ||
8 | 'local/plop/foo.js': 'local/plop', | ||
9 | './local/plop/foo.js': './local/plop', | ||
10 | 'c:\\local\\plop\\foo.js': 'c:/local/plop', | ||
11 | 'D:\\local\\plop\\foo.js': 'D:/local/plop', | ||
12 | 'D:\\local\\plop\\': 'D:/local/plop', | ||
13 | 'c:\\': 'c:', | ||
14 | 'c:': 'c:' | ||
15 | }; | ||
16 | for (var testCase in tests) { | ||
17 | t.assertEquals(fs.dirname(testCase), tests[testCase], 'fs.dirname() does its job for ' + testCase); | ||
18 | } | ||
19 | })(); | ||
20 | |||
21 | t.done(); | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
-
Please register or sign in to post a comment