Commit 41710652 41710652a88cb91db35ff82209f891fe77b2cb67 by Nicolas Perriault

introduced TimedOutError for timed out tests

1 parent 1932d880
...@@ -45,6 +45,15 @@ function AssertionError(msg, result) { ...@@ -45,6 +45,15 @@ function AssertionError(msg, result) {
45 AssertionError.prototype = new Error(); 45 AssertionError.prototype = new Error();
46 exports.AssertionError = AssertionError; 46 exports.AssertionError = AssertionError;
47 47
48 function TimedOutError(msg) {
49 "use strict";
50 Error.call(this);
51 this.message = msg;
52 this.name = 'TimedOutError';
53 }
54 TimedOutError.prototype = new Error();
55 exports.TimedOutError = TimedOutError;
56
48 /** 57 /**
49 * Creates a tester instance. 58 * Creates a tester instance.
50 * 59 *
...@@ -101,8 +110,6 @@ var Tester = function Tester(casper, options) { ...@@ -101,8 +110,6 @@ var Tester = function Tester(casper, options) {
101 this.started = false; 110 this.started = false;
102 this.suiteResults = new TestSuiteResult(); 111 this.suiteResults = new TestSuiteResult();
103 112
104 this.configure();
105
106 this.on('success', function onSuccess(success) { 113 this.on('success', function onSuccess(success) {
107 var timeElapsed = new Date() - this.currentTestStartTime; 114 var timeElapsed = new Date() - this.currentTestStartTime;
108 this.currentSuite.addSuccess(success, timeElapsed - this.lastAssertTime); 115 this.currentSuite.addSuccess(success, timeElapsed - this.lastAssertTime);
...@@ -167,6 +174,28 @@ var Tester = function Tester(casper, options) { ...@@ -167,6 +174,28 @@ var Tester = function Tester(casper, options) {
167 self.currentSuite.addWarning(warning); 174 self.currentSuite.addWarning(warning);
168 } 175 }
169 }); 176 });
177
178 // Do not hook casper if we're not testing
179 if (!phantom.casperTest) {
180 return;
181 }
182
183 // onRunComplete
184 this.casper.options.onRunComplete = function test_onRunComplete(casper) {
185 };
186
187 // specific timeout callbacks
188 this.casper.options.onStepTimeout = function test_onStepTimeout(timeout, step) {
189 throw new TimedOutError(f("Step timeout occured at step %s (%dms)", step, timeout));
190 };
191
192 this.casper.options.onTimeout = function test_onTimeout(timeout) {
193 throw new TimedOutError(f("Timeout occured (%dms)", timeout));
194 };
195
196 this.casper.options.onWaitTimeout = function test_onWaitTimeout(timeout) {
197 throw new TimedOutError(f("Wait timeout occured (%dms)", timeout));
198 };
170 }; 199 };
171 200
172 // Tester class is an EventEmitter 201 // Tester class is an EventEmitter
...@@ -800,33 +829,6 @@ Tester.prototype.comment = function comment(message) { ...@@ -800,33 +829,6 @@ Tester.prototype.comment = function comment(message) {
800 }; 829 };
801 830
802 /** 831 /**
803 * Configure casper callbacks for testing purpose.
804 *
805 */
806 Tester.prototype.configure = function configure() {
807 "use strict";
808 var tester = this;
809
810 // Do not hook casper if we're not testing
811 if (!phantom.casperTest) {
812 return;
813 }
814
815 // specific timeout callbacks
816 this.casper.options.onStepTimeout = function test_onStepTimeout(timeout, step) {
817 tester.fail(f("Step timeout occured at step %s (%dms)", step, timeout));
818 };
819
820 this.casper.options.onTimeout = function test_onTimeout(timeout) {
821 tester.fail(f("Timeout occured (%dms)", timeout));
822 };
823
824 this.casper.options.onWaitTimeout = function test_onWaitTimeout(timeout) {
825 tester.fail(f("Wait timeout occured (%dms)", timeout));
826 };
827 };
828
829 /**
830 * Declares the current test suite done. 832 * Declares the current test suite done.
831 * 833 *
832 * @param Number planned Number of planned tests 834 * @param Number planned Number of planned tests
......