Skip to content

Commit

Permalink
Fix this.skip() async calls (#3745)
Browse files Browse the repository at this point in the history
- eat `Pending` errors bubbling up to uncaught handler, as intended
- fix cheating tests
  • Loading branch information
juergba authored and boneskull committed Mar 5, 2019
1 parent 754cbf9 commit f1662ac
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 21 deletions.
3 changes: 3 additions & 0 deletions lib/runner.js
Expand Up @@ -781,6 +781,9 @@ Runner.prototype.runSuite = function(suite, fn) {
* @private
*/
Runner.prototype.uncaught = function(err) {
if (err instanceof Pending) {
return;
}
if (err) {
debug('uncaught exception %O', err);
} else {
Expand Down
Expand Up @@ -14,8 +14,7 @@ describe('outer suite', function () {
console.log('inner before');
var self = this;
setTimeout(function () {
self.skip();
done();
self.skip(); // done() is not required
}, 0);
});

Expand Down
Expand Up @@ -2,8 +2,7 @@ describe('skip in before with nested describes', function () {
before(function (done) {
var self = this;
setTimeout(function () {
self.skip();
done();
self.skip(); // done() is not required
}, 0);
});

Expand Down
Expand Up @@ -7,7 +7,7 @@ describe('outer describe', function () {
before(function (done) {
var self = this;
setTimeout(function () {
self.skip();
self.skip(); // done() is not required
}, 0);
});

Expand Down
Expand Up @@ -4,18 +4,17 @@ describe('skip in beforeEach', function () {
beforeEach(function (done) {
var self = this;
setTimeout(function () {
self.skip();
done();
self.skip(); // done() is not required
}, 0);
});

it('should skip this test', function () {
it('should skip this test-1', function () {
throw new Error('never run this test');
});
it('should not reach this test', function () {
it('should skip this test-2', function () {
throw new Error('never run this test');
});
it('should not reach this test', function () {
it('should skip this test-3', function () {
throw new Error('never run this test');
});
});
Expand Up @@ -4,7 +4,7 @@ describe('skip in test', function () {
it('should skip async', function (done) {
var self = this;
setTimeout(function () {
self.skip();
self.skip(); // done() is not required
}, 0);
});

Expand Down
23 changes: 13 additions & 10 deletions test/integration/pending.spec.js
Expand Up @@ -258,18 +258,21 @@ describe('pending', function() {

describe('in beforeEach', function() {
it('should skip all suite specs', function(done) {
run('pending/skip-async-beforeEach.fixture.js', args, function(
err,
res
) {
var fixture = 'pending/skip-async-beforeEach.fixture.js';
run(fixture, args, function(err, res) {
if (err) {
done(err);
return;
return done(err);
}
assert.strictEqual(res.stats.pending, 1);
assert.strictEqual(res.stats.passes, 0);
assert.strictEqual(res.stats.failures, 1);
assert.strictEqual(res.code, 1);
expect(res, 'to have passed')
.and('to have passed test count', 0)
.and('to have pending test count', 3)
.and(
'to have pending test order',
'should skip this test-1',
'should skip this test-2',
'should skip this test-3'
)
.and('to have failed test count', 0);
done();
});
});
Expand Down

0 comments on commit f1662ac

Please sign in to comment.