Commit 83a68850 83a688508b400b6f3bc4dd0049f9ab8229b8aa36 by Julien Moulin

Refacto for pre/post

1 parent 428f8000
......@@ -55,9 +55,11 @@ var Tester = function Tester(casper, options) {
this.currentTestFile = null;
this.exporter = require('xunit').create();
this.includes = [];
this.pre = [];
this.post = [];
this.loadIncludes = {
includes: [],
pre: [],
post: []
};
this.running = false;
this.suites = [];
this.options = utils.mergeObjects({
......@@ -723,21 +725,29 @@ 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");
}
if (fs.isDirectory(path)) {
testFiles = testFiles.concat(this.pre);
testFiles = testFiles.concat(self.findTestFiles(path));
testFiles = testFiles.concat(this.post);
} else if (fs.isFile(path)) {
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,14 +3,12 @@ if (!phantom.casperLoaded) {
phantom.exit(1);
}
var fs = require('fs');
var utils = require('utils');
var f = utils.format;
var includes = [];
var pre = [];
var post = [];
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
});
......@@ -56,37 +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);
}
// pre handling
if (casper.cli.has('pre')) {
pre = casper.cli.get('pre').split(',').map(function(unique_pre) {
// we can't use filter() directly because of abspath transformation
return checkIncludeFile(unique_pre);
}).filter(function(unique_pre) {
return utils.isString(unique_pre);
});
casper.test.pre = utils.unique(pre);
}
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);
});
// post handling
if (casper.cli.has('post')) {
post = casper.cli.get('post').split(',').map(function(unique_post) {
// we can't use filter() directly because of abspath transformation
return checkIncludeFile(unique_post);
}).filter(function(unique_post) {
return utils.isString(unique_post);
});
casper.test.post = utils.unique(post);
}
casper.test.loadIncludes[include] = utils.unique(container);
}
});
// test suites completion listener
casper.test.on('tests.complete', function() {
......