Skip to content

armgit / mocha

Public Imported from GitHub
0

☕️ Classic, reliable, trusted test framework for Node.js and the browser

Revert to previously defined onerror handler

Jan Kopriva9cb278bd6c5a
diff --git a/support/tail.js b/support/tail.js
index 018add8d..87248243 100644
--- a/support/tail.js
+++ b/support/tail.js
@@ -26,13 +26,20 @@ process.stdout = {};
var uncaughtExceptionHandlers = [];
+var originalOnerrorHandler = global.onerror;
+
/**
* Remove uncaughtException listener.
+ * Revert to original onerror handler if previously defined.
*/
process.removeListener = function(e, fn){
if ('uncaughtException' == e) {
- global.onerror = function() {};
+ if (originalOnerrorHandler) {
+ global.onerror = originalOnerrorHandler;
+ } else {
+ global.onerror = function() {};
+ }
var i = Mocha.utils.indexOf(uncaughtExceptionHandlers, fn);
if (i != -1) { uncaughtExceptionHandlers.splice(i, 1); }
}