Commit 428f8000 428f8000c0241794179890be346fea5cafe72cee by Julien Moulin

First init of pre/post modification

1 parent 5ed461e8
...@@ -56,6 +56,8 @@ var Tester = function Tester(casper, options) { ...@@ -56,6 +56,8 @@ var Tester = function Tester(casper, options) {
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.includes = [];
59 this.pre = [];
60 this.post = [];
59 this.running = false; 61 this.running = false;
60 this.suites = []; 62 this.suites = [];
61 this.options = utils.mergeObjects({ 63 this.options = utils.mergeObjects({
...@@ -729,7 +731,9 @@ var Tester = function Tester(casper, options) { ...@@ -729,7 +731,9 @@ var Tester = function Tester(casper, options) {
729 self.bar(f("Path %s doesn't exist", path), "RED_BAR"); 731 self.bar(f("Path %s doesn't exist", path), "RED_BAR");
730 } 732 }
731 if (fs.isDirectory(path)) { 733 if (fs.isDirectory(path)) {
734 testFiles = testFiles.concat(this.pre);
732 testFiles = testFiles.concat(self.findTestFiles(path)); 735 testFiles = testFiles.concat(self.findTestFiles(path));
736 testFiles = testFiles.concat(this.post);
733 } else if (fs.isFile(path)) { 737 } else if (fs.isFile(path)) {
734 testFiles.push(path); 738 testFiles.push(path);
735 } 739 }
......
...@@ -3,11 +3,12 @@ if (!phantom.casperLoaded) { ...@@ -3,11 +3,12 @@ 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 includes = [];
10 var pre = [];
11 var post = [];
11 var tests = []; 12 var tests = [];
12 var casper = require('casper').create({ 13 var casper = require('casper').create({
13 exitOnError: false 14 exitOnError: false
...@@ -65,6 +66,28 @@ if (casper.cli.has('includes')) { ...@@ -65,6 +66,28 @@ if (casper.cli.has('includes')) {
65 casper.test.includes = utils.unique(includes); 66 casper.test.includes = utils.unique(includes);
66 } 67 }
67 68
69 // pre handling
70 if (casper.cli.has('pre')) {
71 pre = casper.cli.get('pre').split(',').map(function(unique_pre) {
72 // we can't use filter() directly because of abspath transformation
73 return checkIncludeFile(unique_pre);
74 }).filter(function(unique_pre) {
75 return utils.isString(unique_pre);
76 });
77 casper.test.pre = utils.unique(pre);
78 }
79
80 // post handling
81 if (casper.cli.has('post')) {
82 post = casper.cli.get('post').split(',').map(function(unique_post) {
83 // we can't use filter() directly because of abspath transformation
84 return checkIncludeFile(unique_post);
85 }).filter(function(unique_post) {
86 return utils.isString(unique_post);
87 });
88 casper.test.post = utils.unique(post);
89 }
90
68 // test suites completion listener 91 // test suites completion listener
69 casper.test.on('tests.complete', function() { 92 casper.test.on('tests.complete', function() {
70 this.renderResults(true, undefined, casper.cli.get('xunit') || undefined); 93 this.renderResults(true, undefined, casper.cli.get('xunit') || undefined);
......