Commit 36ca5058 36ca5058b2d251b4e45a757710059f165ae10d1c by Nicolas Perriault

Merge remote-tracking branch 'lizjulien/master' into pr-231

2 parents 8e37f3f0 83a68850
......@@ -55,7 +55,11 @@ var Tester = function Tester(casper, options) {
this.currentTestFile = null;
this.exporter = require('xunit').create();
this.includes = [];
this.loadIncludes = {
includes: [],
pre: [],
post: []
};
this.running = false;
this.suites = [];
this.options = utils.mergeObjects({
......@@ -721,9 +725,14 @@ var Tester = function Tester(casper, options) {
if (arguments.length === 0) {
throw new CasperError("runSuites() needs at least one path argument");
}
this.includes.forEach(function(include) {
this.loadIncludes.includes.forEach(function(include) {
phantom.injectJs(include);
});
this.loadIncludes.pre.forEach(function(include) {
testFiles = testFiles.concat(include);
});
Array.prototype.forEach.call(arguments, function _forEach(path) {
if (!fs.exists(path)) {
self.bar(f("Path %s doesn't exist", path), "RED_BAR");
......@@ -734,6 +743,11 @@ var Tester = function Tester(casper, options) {
testFiles.push(path);
}
});
this.loadIncludes.post.forEach(function(include) {
testFiles = testFiles.concat(include);
});
if (testFiles.length === 0) {
this.bar(f("No test file found in %s, aborting.", Array.prototype.slice.call(arguments)), "RED_BAR");
casper.exit(1);
......
......@@ -3,13 +3,12 @@ if (!phantom.casperLoaded) {
phantom.exit(1);
}
var colorizer = require('colorizer');
var fs = require('fs');
var utils = require('utils');
var f = utils.format;
var includes = [];
var tests = [];
var casper = require('casper').create({
var fs = require('fs');
var utils = require('utils');
var f = utils.format;
var loadIncludes = ['includes', 'pre', 'post'];
var tests = [];
var casper = require('casper').create({
exitOnError: false
});
......@@ -55,15 +54,18 @@ if (casper.cli.args.length) {
}
// includes handling
if (casper.cli.has('includes')) {
includes = casper.cli.get('includes').split(',').map(function(include) {
// we can't use filter() directly because of abspath transformation
return checkIncludeFile(include);
}).filter(function(include) {
return utils.isString(include);
});
casper.test.includes = utils.unique(includes);
}
this.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() {
......