From c4731ab33801760ab99869a038e522d8cb7be2d4 Mon Sep 17 00:00:00 2001 From: juergba Date: Thu, 4 Apr 2019 09:53:24 +0200 Subject: [PATCH 1/2] runner.js: run "after each" hooks --- lib/runner.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/lib/runner.js b/lib/runner.js index 1b1d875a80..3ef0da1f4d 100644 --- a/lib/runner.js +++ b/lib/runner.js @@ -673,11 +673,6 @@ Runner.prototype.runTests = function(suite, fn) { self.fail(test, err); } self.emit(constants.EVENT_TEST_END, test); - - if (err instanceof Pending) { - return next(); - } - return self.hookUp(HOOK_TYPE_AFTER_EACH, next); } From d3a35760d3b585b4e24c6a3721613de3eafef6d0 Mon Sep 17 00:00:00 2001 From: juergba Date: Thu, 4 Apr 2019 13:54:59 +0200 Subject: [PATCH 2/2] extend existing tests --- .../pending/skip-async-spec.fixture.js | 20 +++++++++++++- .../pending/skip-sync-spec.fixture.js | 20 +++++++++++++- test/integration/pending.spec.js | 26 ++++++++++--------- 3 files changed, 52 insertions(+), 14 deletions(-) diff --git a/test/integration/fixtures/pending/skip-async-spec.fixture.js b/test/integration/fixtures/pending/skip-async-spec.fixture.js index 571ca5b851..402cd66c97 100644 --- a/test/integration/fixtures/pending/skip-async-spec.fixture.js +++ b/test/integration/fixtures/pending/skip-async-spec.fixture.js @@ -1,12 +1,30 @@ 'use strict'; +var assert = require('assert'); describe('skip in test', function () { + var runOrder = []; + beforeEach(function () { + runOrder.push('beforeEach'); + }); + it('should skip async', function (done) { var self = this; setTimeout(function () { self.skip(); // done() is not required }, 0); }); + it('should run other tests in suite', function () {}); - it('should run other tests in the suite', function () {}); + afterEach(function() { + runOrder.push('afterEach'); + }); + after(function() { + runOrder.push('after'); + assert.deepStrictEqual(runOrder, [ + 'beforeEach', 'afterEach', + 'beforeEach', 'afterEach', + 'after' + ]); + throw new Error('should throw this error'); + }); }); diff --git a/test/integration/fixtures/pending/skip-sync-spec.fixture.js b/test/integration/fixtures/pending/skip-sync-spec.fixture.js index 9178fce033..515c91d1ec 100644 --- a/test/integration/fixtures/pending/skip-sync-spec.fixture.js +++ b/test/integration/fixtures/pending/skip-sync-spec.fixture.js @@ -1,10 +1,28 @@ 'use strict'; +var assert = require('assert'); describe('skip in test', function () { + var runOrder = []; + beforeEach(function () { + runOrder.push('beforeEach'); + }); + it('should skip immediately', function () { this.skip(); throw new Error('never run this test'); }); + it('should run other tests in suite', function () {}); - it('should run other tests in the suite', function () {}); + afterEach(function() { + runOrder.push('afterEach'); + }); + after(function() { + runOrder.push('after'); + assert.deepStrictEqual(runOrder, [ + 'beforeEach', 'afterEach', + 'beforeEach', 'afterEach', + 'after' + ]); + throw new Error('should throw this error'); + }); }); diff --git a/test/integration/pending.spec.js b/test/integration/pending.spec.js index 7b96d36001..98620c8c9a 100644 --- a/test/integration/pending.spec.js +++ b/test/integration/pending.spec.js @@ -59,13 +59,14 @@ describe('pending', function() { it('should immediately skip the spec and run all others', function(done) { run('pending/skip-sync-spec.fixture.js', args, function(err, res) { if (err) { - done(err); - return; + return done(err); } - assert.strictEqual(res.stats.pending, 1); - assert.strictEqual(res.stats.passes, 1); - assert.strictEqual(res.stats.failures, 0); - assert.strictEqual(res.code, 0); + expect(res, 'to have failed with error', 'should throw this error') + .and('to have failed test count', 1) + .and('to have pending test count', 1) + .and('to have pending test order', 'should skip immediately') + .and('to have passed test count', 1) + .and('to have passed tests', 'should run other tests in suite'); done(); }); }); @@ -192,13 +193,14 @@ describe('pending', function() { it('should immediately skip the spec and run all others', function(done) { run('pending/skip-async-spec.fixture.js', args, function(err, res) { if (err) { - done(err); - return; + return done(err); } - assert.strictEqual(res.stats.pending, 1); - assert.strictEqual(res.stats.passes, 1); - assert.strictEqual(res.stats.failures, 0); - assert.strictEqual(res.code, 0); + expect(res, 'to have failed with error', 'should throw this error') + .and('to have failed test count', 1) + .and('to have pending test count', 1) + .and('to have pending test order', 'should skip async') + .and('to have passed test count', 1) + .and('to have passed tests', 'should run other tests in suite'); done(); }); });