Permalink
Browse files

Support exceptions thrown outside current stack

ie. in another iteration of the event loop. Very basic support.
Just print outs stack and aborts.
  • Loading branch information...
1 parent f9df6a8 commit cedfcd0b786c0c01c43b375740b76cd8e07ae8e2 @joelplane joelplane committed Jun 18, 2011
Showing with 39 additions and 8 deletions.
  1. +13 −0 examples/exceptionOutsideStackTest.js
  2. +5 −0 noodleTestConsole.js
  3. +8 −0 system.js
  4. +13 −8 test.js
@@ -0,0 +1,13 @@
+var test = require('../noodleTest')();
+test.onFailureExitNonZero();
+test.handleUncaughtExceptions();
+
+test.context("Example Test Suite", function() {
+ this.context("Example Sub-Context", function() {
+ this.it("Test code throws exception on next tick", function(test) {
+ process.nextTick(function(){
+ throw new Error('bleh');
+ });
+ });
+ });
+});
View
@@ -93,6 +93,11 @@ module.exports = (function(test){
last = null;
});
+ test.on('uncaughtException', function(error){
+ log(0, error.stack, 'white');
+ log(0, '');
+ });
+
test.on('testDone', function(t){
var contextIndent = t._context._depth();
var n = t._failures.length || t._passes.length;
View
@@ -11,6 +11,7 @@ module.exports = function(main) {
};
main.on('assertionFailed', seenFailureCallback);
main.on('testFlunk', seenFailureCallback);
+ main.on('uncaughtException', seenFailureCallback);
var calledOnFailureExitNonZero = false;
main.onFailureExitNonZero = function() {
@@ -24,4 +25,11 @@ module.exports = function(main) {
});
}
};
+
+ main.handleUncaughtExceptions = function() {
+ process.on('uncaughtException', function (error) {
+ main.emit('uncaughtException', error);
+ });
+ };
+
};
View
21 test.js
@@ -48,24 +48,29 @@ module.exports = (function(Assertion, testQueue, timeout){
var doneCalled = false;
this.done = function() {
doneCalled = true;
- clearTimeout(timer);
+ test._clearDoneTimer();
test._emit('testDone', test);
};
- var timer = setTimeout(function(){
- test._emit('testTimeout', test);
- }, timeout);
+ this._startDoneTimer();
try {
this._testFunction.call(this, this);
} catch(error) {
if (!doneCalled) {
- clearTimeout(timer);
+ this._clearDoneTimer();
}
this._failures.push(new Flunk(this, error));
- test._emit('testDone', this);
- //this._emit('testFlunk', this);
- //this.flunk();
+ test._emit('testDone', this);
}
};
+ Test.prototype._startDoneTimer = function() {
+ var test = this;
+ this._timer = setTimeout(function(){
+ test._emit('testTimeout', test);
+ }, timeout);
+ };
+ Test.prototype._clearDoneTimer = function() {
+ clearTimeout(this._timer);
+ };
/*Test.prototype.flunk = function() {
this._emit('testFlunk', this);
};*/

0 comments on commit cedfcd0

Please sign in to comment.