Commit b02269c0 b02269c00056397a217e41b9a597eb4a9d01d67e by Nicolas Perriault

fixed #306 - Raise an explicit error on invalid test path

1 parent 363fd828
......@@ -80,6 +80,7 @@ Also, `Casper.mouseEvent()` will now directly trigger an error on failure instea
### Bugfixes & enhancements
- fixed [#306](https://github.com/n1k0/casperjs/issues/306) - Raise an explicit error on invalid test path
- fixed [#300](https://github.com/n1k0/casperjs/issues/300) - Ensure that `findOne()` and `findAll()` observe the scope for XPath expressions, not just when passed CSS selectors
- fixed [#294](https://github.com/n1k0/casperjs/issues/294) - Automatically fail test on any runtime error or timeout
- fixed [#281](https://github.com/n1k0/casperjs/issues/281) - `Casper.evaluate()` should take an array as context not object
......
......@@ -290,12 +290,9 @@ function bootstrap(global) {
phantom.exit(0);
}
if (!phantom.casperScript) {
phantom.casperScript = phantom.casperArgs.get(0);
}
if (phantom.casperScript) {
} else {
if (!fs.isFile(phantom.casperScript)) {
console.error('Unable to open file: ' + phantom.casperScript);
phantom.exit(1);
......
/*global phantom*/
/*global phantom CasperError*/
if (!phantom.casperLoaded) {
console.log('This script must be invoked using the casperjs executable');
......@@ -50,55 +50,72 @@ function checkIncludeFile(include) {
return absInclude;
}
// parse some options from cli
casper.options.verbose = casper.cli.get('direct') || false;
casper.options.logLevel = casper.cli.get('log-level') || "error";
if (casper.cli.get('no-colors') === true) {
var cls = 'Dummy';
casper.options.colorizerType = cls;
casper.colorizer = colorizer.create(cls);
function checkArgs() {
"use strict";
// parse some options from cli
casper.options.verbose = casper.cli.get('direct') || false;
casper.options.logLevel = casper.cli.get('log-level') || "error";
if (casper.cli.get('no-colors') === true) {
var cls = 'Dummy';
casper.options.colorizerType = cls;
casper.colorizer = colorizer.create(cls);
}
casper.test.options.failFast = casper.cli.get('fail-fast') || false;
// test paths are passed as args
if (casper.cli.args.length) {
tests = casper.cli.args.filter(function(path) {
if (fs.isFile(path) || fs.isDirectory(path)) {
return true;
}
throw new CasperError(f("Invalid test path: %s", path));
});
} else {
casper.echo('No test path passed, exiting.', 'RED_BAR', 80);
casper.exit(1);
}
// check for casper selftests
if (!phantom.casperSelfTest && checkSelfTest(tests)) {
casper.warn('To run casper self tests, use the `selftest` command.');
casper.exit(1);
}
}
casper.test.options.failFast = casper.cli.get('fail-fast') || false;
// test paths are passed as args
if (casper.cli.args.length) {
tests = casper.cli.args.filter(function(path) {
"use strict";
return fs.isFile(path) || fs.isDirectory(path);
function initRunner() {
"use strict";
// includes handling
loadIncludes.forEach(function(include){
var container;
if (casper.cli.has(include)) {
container = casper.cli.get(include).split(',').map(function(file) {
return checkIncludeFile(file);
}).filter(function(file) {
return utils.isString(file);
});
casper.test.loadIncludes[include] = utils.unique(container);
}
});
// test suites completion listener
casper.test.on('tests.complete', function() {
this.renderResults(true, undefined, casper.cli.get('xunit') || undefined);
if (this.options.failFast && this.testResults.failures.length > 0) {
casper.warn('Test suite failed fast, all tests may not have been executed.');
}
});
} else {
casper.echo('No test path passed, exiting.', 'RED_BAR', 80);
casper.exit(1);
}
// check for casper selftests
if (!phantom.casperSelfTest && checkSelfTest(tests)) {
casper.warn('To run casper self tests, use the `selftest` command.');
var error;
try {
checkArgs();
} catch (e) {
error = true;
casper.warn(e);
casper.exit(1);
}
// includes handling
this.loadIncludes.forEach(function(include){
"use strict";
var container;
if (casper.cli.has(include)) {
container = casper.cli.get(include).split(',').map(function(file) {
return checkIncludeFile(file);
}).filter(function(file) {
return utils.isString(file);
});
casper.test.loadIncludes[include] = utils.unique(container);
}
});
// test suites completion listener
casper.test.on('tests.complete', function() {
"use strict";
this.renderResults(true, undefined, casper.cli.get('xunit') || undefined);
if (this.options.failFast && this.testResults.failures.length > 0) {
casper.warn('Test suite failed fast, all tests may not have been executed.');
}
});
// run all the suites
casper.test.runSuites.apply(casper.test, tests);
if (!error) {
initRunner();
casper.test.runSuites.apply(casper.test, tests);
}
......