From f1ac5485f19c15fc50b683bdbf27c666b7940f7e Mon Sep 17 00:00:00 2001 From: Dmitry Sorin Date: Thu, 22 Sep 2016 08:55:53 +0300 Subject: [PATCH] fix: fix uncaught TypeError if error occurs on next tick, closes #2315 (#2439) --- lib/runner.js | 3 +++ test/integration/fixtures/regression/issue-2315.js | 7 +++++++ test/integration/regression.spec.js | 13 ++++++++++++- 3 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 test/integration/fixtures/regression/issue-2315.js diff --git a/lib/runner.js b/lib/runner.js index 22907f570f..145d990351 100644 --- a/lib/runner.js +++ b/lib/runner.js @@ -420,6 +420,9 @@ Runner.prototype.runTest = function(fn) { var self = this; var test = this.test; + if (!test) { + return; + } if (this.asyncOnly) { test.asyncOnly = true; } diff --git a/test/integration/fixtures/regression/issue-2315.js b/test/integration/fixtures/regression/issue-2315.js new file mode 100644 index 0000000000..d3d1f9363c --- /dev/null +++ b/test/integration/fixtures/regression/issue-2315.js @@ -0,0 +1,7 @@ +describe('issue-2315: cannot read property currentRetry of undefined', function () { + before(function () { + require('http').createServer().listen(1); + }); + + it('something', function () {}); +}); diff --git a/test/integration/regression.spec.js b/test/integration/regression.spec.js index f9f96d31d6..f2a435a34c 100644 --- a/test/integration/regression.spec.js +++ b/test/integration/regression.spec.js @@ -1,4 +1,4 @@ -var assert = require('assert'); +var assert = require('assert'); var fs = require('fs'); var path = require('path'); var run = require('./helpers').runMocha; @@ -62,6 +62,17 @@ describe('regressions', function() { }); }); + it('issue-2315: cannot read property currentRetry of undefined', function (done) { + runJSON('regression/issue-2315.js', [], function(err, res) { + assert(!err); + assert.equal(res.stats.pending, 0); + assert.equal(res.stats.passes, 0); + assert.equal(res.stats.failures, 1); + assert.equal(res.code, 1); + done(); + }); + }); + it('issue-2406: should run nested describe.only suites', function(done) { this.timeout(2000); runJSON('regression/issue-2406.fixture.js', [], function(err, res) {