Skip to content

armgit / mocha

Public Imported from GitHub
0

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

fix uncaught error support for the browser

TJ Holowaychukeb58761bb334
diff --git a/mocha.js b/mocha.js
index b14eb174..de329bdb 100644
--- a/mocha.js
+++ b/mocha.js
@@ -4215,15 +4215,10 @@ Runner.prototype.run = function(fn){
debug('start');
- // uncaught callback
- function uncaught(err, url, line) {
- self.uncaught(new Error(err + ' (' + url + ':' + line + ')'));
- }
-
// callback
this.on('end', function(){
debug('end');
- process.removeListener('uncaughtException', uncaught);
+ process.removeListener('uncaughtException', self.uncaught.bind(self));
fn(self.failures);
});
@@ -4235,7 +4230,7 @@ Runner.prototype.run = function(fn){
});
// uncaught exception
- process.on('uncaughtException', uncaught);
+ process.on('uncaughtException', this.uncaught.bind(this));
return this;
};
@@ -4946,7 +4941,9 @@ process.removeListener = function(e){
process.on = function(e, fn){
if ('uncaughtException' == e) {
- window.onerror = fn;
+ window.onerror = function(err, url, line){
+ fn(new Error(err + ' (' + url + ':' + line + ')'));
+ };
}
};
diff --git a/support/tail.js b/support/tail.js
index 9b7a533b..0f9b64a4 100644
--- a/support/tail.js
+++ b/support/tail.js
@@ -56,7 +56,9 @@ process.removeListener = function(e){
process.on = function(e, fn){
if ('uncaughtException' == e) {
- window.onerror = fn;
+ window.onerror = function(err, url, line){
+ fn(new Error(err + ' (' + url + ':' + line + ')'));
+ };
}
};
diff --git a/test/browser/large.js b/test/browser/large.js
index 5137daa5..7974bb6f 100644
--- a/test/browser/large.js
+++ b/test/browser/large.js
@@ -20,4 +20,13 @@ while (n--) {
})
})
})
-}
\ No newline at end of file
+}
+
+describe('something', function(){
+ it('should provide a useful error', function(done){
+ setTimeout(function(){
+ throw new Error('boom');
+ done();
+ }, 1);
+ })
+})
\ No newline at end of file