Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
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...
commit cedfcd0b786c0c01c43b375740b76cd8e07ae8e2 1 parent f9df6a8
@joelplane joelplane authored
View
13 examples/exceptionOutsideStackTest.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
5 noodleTestConsole.js
@@ -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
8 system.js
@@ -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);
};*/
Please sign in to comment.
Something went wrong with that request. Please try again.