Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: include stack in browser uncaught error reporting #5107

Merged
4 changes: 2 additions & 2 deletions browser-entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ process.listenerCount = function (name) {

process.on = function (e, fn) {
if (e === 'uncaughtException') {
global.onerror = function (err, url, line) {
fn(new Error(err + ' (' + url + ':' + line + ')'));
global.onerror = function (msg, url, line, col, err) {
fn(err || new Error(msg + ' (' + url + ':' + line + ':' + col + ')'));
return !mocha.options.allowUncaught;
};
uncaughtExceptionHandlers.push(fn);
Expand Down
33 changes: 33 additions & 0 deletions test/unit/throw.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

/* eslint no-throw-literal: off */

var sinon = require('sinon');
var Mocha = require('../../lib/mocha');
var Suite = Mocha.Suite;
var Test = Mocha.Test;
Expand Down Expand Up @@ -29,6 +30,7 @@ describe('a test that throws', function () {
uncaughtHandlers.forEach(function (listener) {
process.on('uncaughtException', listener);
});
sinon.restore();
});

describe('non-extensible', function () {
Expand Down Expand Up @@ -172,4 +174,35 @@ describe('a test that throws', function () {
runner.run();
});
});

describe('stack', function() {
it('should include the stack when throwing async', function(done) {
var test = new Test('im async and throw null async', function(done2) {
process.nextTick(function throwError() {
throw new Error('test error');
});
});
suite.addTest(test);
runner = new Runner(suite);
sinon.stub(runner, 'fail');

runner.on(EVENT_RUN_END, function() {
try {
expect(runner.fail, 'to have all calls satisfying', [
expect.it('to be a', Runnable),
expect.it('to be an', Error).and('to satisfy', {
message: /test error/i,
stack: /throwError/i,
uncaught: true
})
]).and('was called once');
} catch (err) {
return done(err);
}

done();
});
runner.run();
});
});
});
Loading