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) { ...@@ -55,7 +55,11 @@ var Tester = function Tester(casper, options) {
55 55
56 this.currentTestFile = null; 56 this.currentTestFile = null;
57 this.exporter = require('xunit').create(); 57 this.exporter = require('xunit').create();
58 this.includes = []; 58 this.loadIncludes = {
59 includes: [],
60 pre: [],
61 post: []
62 };
59 this.running = false; 63 this.running = false;
60 this.suites = []; 64 this.suites = [];
61 this.options = utils.mergeObjects({ 65 this.options = utils.mergeObjects({
...@@ -721,9 +725,14 @@ var Tester = function Tester(casper, options) { ...@@ -721,9 +725,14 @@ var Tester = function Tester(casper, options) {
721 if (arguments.length === 0) { 725 if (arguments.length === 0) {
722 throw new CasperError("runSuites() needs at least one path argument"); 726 throw new CasperError("runSuites() needs at least one path argument");
723 } 727 }
724 this.includes.forEach(function(include) { 728 this.loadIncludes.includes.forEach(function(include) {
725 phantom.injectJs(include); 729 phantom.injectJs(include);
726 }); 730 });
731
732 this.loadIncludes.pre.forEach(function(include) {
733 testFiles = testFiles.concat(include);
734 });
735
727 Array.prototype.forEach.call(arguments, function _forEach(path) { 736 Array.prototype.forEach.call(arguments, function _forEach(path) {
728 if (!fs.exists(path)) { 737 if (!fs.exists(path)) {
729 self.bar(f("Path %s doesn't exist", path), "RED_BAR"); 738 self.bar(f("Path %s doesn't exist", path), "RED_BAR");
...@@ -734,6 +743,11 @@ var Tester = function Tester(casper, options) { ...@@ -734,6 +743,11 @@ var Tester = function Tester(casper, options) {
734 testFiles.push(path); 743 testFiles.push(path);
735 } 744 }
736 }); 745 });
746
747 this.loadIncludes.post.forEach(function(include) {
748 testFiles = testFiles.concat(include);
749 });
750
737 if (testFiles.length === 0) { 751 if (testFiles.length === 0) {
738 this.bar(f("No test file found in %s, aborting.", Array.prototype.slice.call(arguments)), "RED_BAR"); 752 this.bar(f("No test file found in %s, aborting.", Array.prototype.slice.call(arguments)), "RED_BAR");
739 casper.exit(1); 753 casper.exit(1);
......
...@@ -3,11 +3,10 @@ if (!phantom.casperLoaded) { ...@@ -3,11 +3,10 @@ if (!phantom.casperLoaded) {
3 phantom.exit(1); 3 phantom.exit(1);
4 } 4 }
5 5
6 var colorizer = require('colorizer');
7 var fs = require('fs'); 6 var fs = require('fs');
8 var utils = require('utils'); 7 var utils = require('utils');
9 var f = utils.format; 8 var f = utils.format;
10 var includes = []; 9 var loadIncludes = ['includes', 'pre', 'post'];
11 var tests = []; 10 var tests = [];
12 var casper = require('casper').create({ 11 var casper = require('casper').create({
13 exitOnError: false 12 exitOnError: false
...@@ -55,15 +54,18 @@ if (casper.cli.args.length) { ...@@ -55,15 +54,18 @@ if (casper.cli.args.length) {
55 } 54 }
56 55
57 // includes handling 56 // includes handling
58 if (casper.cli.has('includes')) { 57 this.loadIncludes.forEach(function(include){
59 includes = casper.cli.get('includes').split(',').map(function(include) { 58 var container;
60 // we can't use filter() directly because of abspath transformation 59 if (casper.cli.has(include)) {
61 return checkIncludeFile(include); 60 container = casper.cli.get(include).split(',').map(function(file) {
62 }).filter(function(include) { 61 return checkIncludeFile(file);
63 return utils.isString(include); 62 }).filter(function(file) {
63 return utils.isString(file);
64 }); 64 });
65 casper.test.includes = utils.unique(includes); 65
66 } 66 casper.test.loadIncludes[include] = utils.unique(container);
67 }
68 });
67 69
68 // test suites completion listener 70 // test suites completion listener
69 casper.test.on('tests.complete', function() { 71 casper.test.on('tests.complete', function() {
......