Commit 848791c2 848791c2521f5e4bcdab8d0011811b518f2a295d by Nicolas Perriault

added "complete.error" event

- this allows a test suite to fail within a casper.run() onComplete callback
- rewritten some tests
1 parent c64cd455
...@@ -348,18 +348,22 @@ Casper.prototype.checkStep = function checkStep(self, onComplete) { ...@@ -348,18 +348,22 @@ Casper.prototype.checkStep = function checkStep(self, onComplete) {
348 } 348 }
349 var step = self.steps[self.step++]; 349 var step = self.steps[self.step++];
350 if (utils.isFunction(step)) { 350 if (utils.isFunction(step)) {
351 self.runStep(step); 351 return self.runStep(step);
352 } else { 352 }
353 self.result.time = new Date().getTime() - self.startTime; 353 self.result.time = new Date().getTime() - self.startTime;
354 self.log(f("Done %s steps in %dms", self.steps.length, self.result.time), "info"); 354 self.log(f("Done %s steps in %dms", self.steps.length, self.result.time), "info");
355 clearInterval(self.checker); 355 clearInterval(self.checker);
356 self.step -= 1; 356 self.step -= 1;
357 self.emit('run.complete'); 357 self.emit('run.complete');
358 try {
358 if (utils.isFunction(onComplete)) { 359 if (utils.isFunction(onComplete)) {
359 onComplete.call(self, self); 360 onComplete.call(self, self);
360 } else if (utils.isFunction(self.options.onRunComplete)) { 361 } else if (utils.isFunction(self.options.onRunComplete)) {
361 self.options.onRunComplete.call(self, self); 362 self.options.onRunComplete.call(self, self);
362 } 363 }
364 } catch (error) {
365 self.emit('complete.error', error);
366 throw error;
363 } 367 }
364 }; 368 };
365 369
......
...@@ -184,6 +184,7 @@ var Tester = function Tester(casper, options) { ...@@ -184,6 +184,7 @@ var Tester = function Tester(casper, options) {
184 } 184 }
185 this.casper.on('event.error', errorHandler); 185 this.casper.on('event.error', errorHandler);
186 this.casper.on('step.error', errorHandler); 186 this.casper.on('step.error', errorHandler);
187 this.casper.on('complete.error', errorHandler);
187 188
188 this.casper.on('warn', function(warning) { 189 this.casper.on('warn', function(warning) {
189 if (self.currentSuite) { 190 if (self.currentSuite) {
......
1 /*global casper*/ 1 /*global casper*/
2 /*jshint strict:false*/ 2 /*jshint strict:false*/
3 casper.test.begin('can confirm dialog', 2, function(test) { 3 casper.test.begin('can confirm dialog', 2, {
4 var received; 4 received: undefined,
5 casper.removeAllFilters('page.confirm') 5
6 setUp: function(test) {
7 var self = this;
8 casper.removeAllFilters('page.confirm');
6 casper.setFilter('page.confirm', function(message) { 9 casper.setFilter('page.confirm', function(message) {
7 received = message; 10 self.received = message;
8 return true; 11 return true;
9 }); 12 });
13 },
14
15 tearDown: function(test) {
16 casper.removeAllFilters('page.confirm');
17 },
18
19 test: function(test) {
20 var self = this;
10 casper.start('tests/site/confirm.html', function() { 21 casper.start('tests/site/confirm.html', function() {
11 test.assert(this.getGlobal('confirmed'), 'confirmation dialog accepted'); 22 test.assert(this.getGlobal('confirmed'), 'confirmation dialog accepted');
12 }); 23 }).run(function() {
13 casper.run(function() { 24 test.assertEquals(self.received, 'are you sure?', 'confirmation message is ok');
14 test.assertEquals(received, 'are you sure?', 'confirmation message is ok');
15 test.done(); 25 test.done();
16 }); 26 });
27 }
17 }); 28 });
18 29
19 casper.test.begin('can cancel dialog', 1, function(test) { 30 casper.test.begin('can cancel dialog', {
20 casper.removeAllFilters('page.confirm') 31 received: undefined,
32
33 setUp: function(test) {
34 var self = this;
35 casper.removeAllFilters('page.confirm');
21 casper.setFilter('page.confirm', function(message) { 36 casper.setFilter('page.confirm', function(message) {
22 return false; 37 return false;
23 }); 38 });
39 },
40
41 tearDown: function(test) {
42 casper.removeAllFilters('page.confirm');
43 },
44
45 test: function(test) {
46 var self = this;
24 casper.start('tests/site/confirm.html', function() { 47 casper.start('tests/site/confirm.html', function() {
25 test.assertNot(this.getGlobal('confirmed'), 'confirmation dialog canceled'); 48 test.assertNot(this.getGlobal('confirmed'), 'confirmation dialog canceled');
26 }); 49 }).run(function() {
27 casper.run(function() {
28 test.done(); 50 test.done();
29 }); 51 });
52 }
30 }); 53 });
......