Commit e7b0e1da e7b0e1dacf3c2bf7d43b06e731376c76fb2de79f by Nicolas Perriault

Merge pull request #561 from hexid/test-dirname-fix

Allow test cases to use the directory when only the script name is passed
2 parents c62b646b 67db3a36
...@@ -227,13 +227,21 @@ CasperError.prototype = Object.getPrototypeOf(new Error()); ...@@ -227,13 +227,21 @@ CasperError.prototype = Object.getPrototypeOf(new Error());
227 function initCasperCli(casperArgs) { 227 function initCasperCli(casperArgs) {
228 var baseTestsPath = fs.pathJoin(phantom.casperPath, 'tests'); 228 var baseTestsPath = fs.pathJoin(phantom.casperPath, 'tests');
229 229
230 function setScriptBaseDir(scriptName) {
231 var dir = fs.dirname(scriptName);
232 if(dir === scriptName) {
233 dir = '.';
234 }
235 phantom.casperScriptBaseDir = dir;
236 }
237
230 if (!!casperArgs.options.version) { 238 if (!!casperArgs.options.version) {
231 return __terminate(phantom.casperVersion.toString()) 239 return __terminate(phantom.casperVersion.toString())
232 } else if (casperArgs.get(0) === "test") { 240 } else if (casperArgs.get(0) === "test") {
233 phantom.casperScript = fs.absolute(fs.pathJoin(baseTestsPath, 'run.js')); 241 phantom.casperScript = fs.absolute(fs.pathJoin(baseTestsPath, 'run.js'));
234 phantom.casperTest = true; 242 phantom.casperTest = true;
235 casperArgs.drop("test"); 243 casperArgs.drop("test");
236 phantom.casperScriptBaseDir = fs.dirname(casperArgs.get(0)); 244 setScriptBaseDir(casperArgs.get(0));
237 } else if (casperArgs.get(0) === "selftest") { 245 } else if (casperArgs.get(0) === "selftest") {
238 phantom.casperScript = fs.absolute(fs.pathJoin(baseTestsPath, 'run.js')); 246 phantom.casperScript = fs.absolute(fs.pathJoin(baseTestsPath, 'run.js'));
239 phantom.casperSelfTest = phantom.casperTest = true; 247 phantom.casperSelfTest = phantom.casperTest = true;
...@@ -256,11 +264,7 @@ CasperError.prototype = Object.getPrototypeOf(new Error()); ...@@ -256,11 +264,7 @@ CasperError.prototype = Object.getPrototypeOf(new Error());
256 } 264 }
257 265
258 if (!phantom.casperScriptBaseDir) { 266 if (!phantom.casperScriptBaseDir) {
259 var scriptDir = fs.dirname(phantom.casperScript); 267 setScriptBaseDir(phantom.casperScript);
260 if (scriptDir === phantom.casperScript) {
261 scriptDir = '.';
262 }
263 phantom.casperScriptBaseDir = fs.absolute(scriptDir);
264 } 268 }
265 269
266 // filter out the called script name from casper args 270 // filter out the called script name from casper args
......