From 2c9966c950f5960c80b48d55a783b752a7e12a36 Mon Sep 17 00:00:00 2001 From: David da Silva Date: Sun, 29 May 2016 20:18:04 +0200 Subject: [PATCH 1/5] Add failing test: after hook not run if beforeEach skipped test Related to #2286. --- test/integration/fixtures/regression/issue-2286.js | 5 +++++ test/integration/regression.js | 14 ++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 test/integration/fixtures/regression/issue-2286.js diff --git a/test/integration/fixtures/regression/issue-2286.js b/test/integration/fixtures/regression/issue-2286.js new file mode 100644 index 0000000000..e912d93815 --- /dev/null +++ b/test/integration/fixtures/regression/issue-2286.js @@ -0,0 +1,5 @@ +describe('suite', function () { + beforeEach(function () { this.skip() }) + after(function () { console.log('after in suite') }) + it('test', function () {}) +}) diff --git a/test/integration/regression.js b/test/integration/regression.js index f20f601ea1..2edec801a3 100644 --- a/test/integration/regression.js +++ b/test/integration/regression.js @@ -50,4 +50,18 @@ describe('regressions', function() { done(); }); }) + + it('issue-2286: after doesn\'t execute if test was skipped in beforeEach', function(done) { + var args = []; + run('regression/issue-2286.js', args, function(err, res) { + var occurences = function(str) { + var pattern = new RegExp(str, 'g'); + return (res.output.match(pattern) || []).length; + }; + + assert(!err); + assert.equal(occurences('after in suite'), 1); + done(); + }); + }) }); From 22dbad7c8d4e6619119558497d7b91f240a8fb79 Mon Sep 17 00:00:00 2001 From: David da Silva Date: Mon, 30 May 2016 00:35:55 +0200 Subject: [PATCH 2/5] wip Fix suite being marked as pending when beforeEach skips --- lib/runner.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/runner.js b/lib/runner.js index ba4d7df97c..f4e30c72a2 100644 --- a/lib/runner.js +++ b/lib/runner.js @@ -302,7 +302,8 @@ Runner.prototype.hook = function(name, fn) { } if (err) { if (err instanceof Pending) { - suite.pending = true; + self.test.pending = true; + console.log(self.test); } else { self.failHook(hook, err); @@ -516,7 +517,7 @@ Runner.prototype.runTests = function(suite, fn) { // execute test and hook(s) self.emit('test', self.test = test); self.hookDown('beforeEach', function(err, errSuite) { - if (suite.isPending()) { + if (test.isPending()) { self.emit('pending', test); self.emit('test end', test); return next(); From 4f2e4549cc0407135f1fa96a7f7ae862e1d7e5c0 Mon Sep 17 00:00:00 2001 From: Christopher Hiller Date: Thu, 9 Jun 2016 16:19:38 -0700 Subject: [PATCH 3/5] update pending logic to closely mimic previous behavior --- lib/runner.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/runner.js b/lib/runner.js index f4e30c72a2..86bd4dc4af 100644 --- a/lib/runner.js +++ b/lib/runner.js @@ -302,8 +302,13 @@ Runner.prototype.hook = function(name, fn) { } if (err) { if (err instanceof Pending) { - self.test.pending = true; - console.log(self.test); + if (name === 'beforeEach' || name === 'afterEach') { + self.test.pending = true; + } else { + suite.tests.forEach(function(test) { + test.pending = true; + }); + } } else { self.failHook(hook, err); @@ -844,8 +849,8 @@ function filterLeaks(ok, globals) { } // in firefox - // if runner runs in an iframe, this iframe's window.getInterface method not init at first - // it is assigned in some seconds + // if runner runs in an iframe, this iframe's window.getInterface method + // not init at first it is assigned in some seconds if (global.navigator && (/^getInterface/).test(key)) { return false; } From d2ba7a9676c88d06709f383a6243d46977758bd1 Mon Sep 17 00:00:00 2001 From: ScottFreeCode Date: Fri, 10 Jun 2016 19:10:11 -0400 Subject: [PATCH 4/5] Clarify nature of meta test This should make it possible to understand when just looking at the fixture. --- test/integration/fixtures/regression/issue-2286.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/integration/fixtures/regression/issue-2286.js b/test/integration/fixtures/regression/issue-2286.js index e912d93815..8a3c1ac4dd 100644 --- a/test/integration/fixtures/regression/issue-2286.js +++ b/test/integration/fixtures/regression/issue-2286.js @@ -1,5 +1,5 @@ -describe('suite', function () { - beforeEach(function () { this.skip() }) - after(function () { console.log('after in suite') }) - it('test', function () {}) +describe('testception for issue 2286 meta test', function () { + beforeEach('skips tests', function () { this.skip() }) + after('should run', function () { console.log('after in suite') }) + it('skipped by beforeEach', function () {}) }) From d165c82fa94df2fa417362a7f7be6a857d12cd4b Mon Sep 17 00:00:00 2001 From: ScottFreeCode Date: Fri, 10 Jun 2016 19:21:42 -0400 Subject: [PATCH 5/5] Nested suites for meta test --- .../fixtures/regression/issue-2286.js | 5 ---- test/integration/regression.js | 24 +++++++++---------- 2 files changed, 11 insertions(+), 18 deletions(-) delete mode 100644 test/integration/fixtures/regression/issue-2286.js diff --git a/test/integration/fixtures/regression/issue-2286.js b/test/integration/fixtures/regression/issue-2286.js deleted file mode 100644 index 8a3c1ac4dd..0000000000 --- a/test/integration/fixtures/regression/issue-2286.js +++ /dev/null @@ -1,5 +0,0 @@ -describe('testception for issue 2286 meta test', function () { - beforeEach('skips tests', function () { this.skip() }) - after('should run', function () { console.log('after in suite') }) - it('skipped by beforeEach', function () {}) -}) diff --git a/test/integration/regression.js b/test/integration/regression.js index 2edec801a3..b8c64b84e7 100644 --- a/test/integration/regression.js +++ b/test/integration/regression.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; @@ -51,17 +51,15 @@ describe('regressions', function() { }); }) - it('issue-2286: after doesn\'t execute if test was skipped in beforeEach', function(done) { - var args = []; - run('regression/issue-2286.js', args, function(err, res) { - var occurences = function(str) { - var pattern = new RegExp(str, 'g'); - return (res.output.match(pattern) || []).length; - }; - - assert(!err); - assert.equal(occurences('after in suite'), 1); - done(); + describe('issue-2286: after doesn\'t execute if test was skipped in beforeEach', function () { + var afterWasRun = false; + describe('suite with skipped test for meta test', function () { + beforeEach(function () { this.skip(); }); + after(function () { afterWasRun = true; }); + it('should be pending', function () {}); + }) + after('meta test', function () { + afterWasRun.should.be.ok(); }); - }) + }); });