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());
function initCasperCli(casperArgs) {
var baseTestsPath = fs.pathJoin(phantom.casperPath, 'tests');
function setScriptBaseDir(scriptName) {
var dir = fs.dirname(scriptName);
if(dir === scriptName) {
dir = '.';
}
phantom.casperScriptBaseDir = dir;
}
if (!!casperArgs.options.version) {
return __terminate(phantom.casperVersion.toString())
} else if (casperArgs.get(0) === "test") {
phantom.casperScript = fs.absolute(fs.pathJoin(baseTestsPath, 'run.js'));
phantom.casperTest = true;
casperArgs.drop("test");
phantom.casperScriptBaseDir = fs.dirname(casperArgs.get(0));
setScriptBaseDir(casperArgs.get(0));
} else if (casperArgs.get(0) === "selftest") {
phantom.casperScript = fs.absolute(fs.pathJoin(baseTestsPath, 'run.js'));
phantom.casperSelfTest = phantom.casperTest = true;
......@@ -256,11 +264,7 @@ CasperError.prototype = Object.getPrototypeOf(new Error());
}
if (!phantom.casperScriptBaseDir) {
var scriptDir = fs.dirname(phantom.casperScript);
if (scriptDir === phantom.casperScript) {
scriptDir = '.';
}
phantom.casperScriptBaseDir = fs.absolute(scriptDir);
setScriptBaseDir(phantom.casperScript);
}
// filter out the called script name from casper args
......