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

Add failing test: after hook is not run if test skipped in beforeEach #2287

Merged
merged 5 commits into from Jun 11, 2016

Conversation

dasilvacontin
Copy link
Contributor

Related to #2286.

@boneskull
Copy link
Member

@dasilvacontin I think this fixes it, but I need a sanity check

@boneskull boneskull added High priority type: bug a defect, confirmed by a maintainer labels Jun 10, 2016
@boneskull
Copy link
Member

cc @mochajs/mocha or anyone else who wants to test this out

@boneskull
Copy link
Member

as per discussion, I've updated my code to be more weird, but also more backwards-compatible.

cc @mochajs/mocha

@ScottFreeCode
Copy link
Contributor

I'm wary of depending on the run interface when all we want to test is hooks, and of splitting the test out into a separate file so you have to look in those two separate places to figure it out, but the only alternative I can think of will throw from an after or after each hook in case of failure instead (which is arguably an abuse):

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();
  })
})

beforeEach(function () { this.skip() })
after(function () { console.log('after in suite') })
it('test', function () {})
})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about some names that make this file's function obvious (both in viewing this file and if it were to end up run among the main tests in addition to the meta test calling it by run)? e.g.:
describe: 'testception for issue 2286 meta test'
beforeEach: 'skips tests'
after: 'should run'
it: 'skipped by beforeEach'

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ScottFreeCode I don't see this stuff as absolutely necessary given the filename, but if you wish to add to the branch, go for it

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually on second thought, I like your test above. please use it instead

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(to the first reply:) Yeah, it's pretty clear from the filename what issue this is testing, but it's not so obvious to me from looking just at this file that this is meant to be run by another test in another file that tests the output of this one (unless that's what all the stuff in this fixtures folder is -- I haven't looked at the files that were already there), so it looked at first as though this weren't actually testing it programmatically but only printing something to look at manually.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(to the second:) You mean the one that uses nested suites with code like this in the inner one and a test in the after of the outer one?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Went ahead and committed both; feel free to rebase away either you don't want.)

This should make it possible to understand when just looking at the
fixture.
@@ -1,4 +1,4 @@
var assert = require('assert');
var assert = require('assert');
var fs = require('fs');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did this... pick up a UTF-8 BOM or something? I will see if I can fix that when I get another free moment.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or not, if it's already merged into the history and isn't hurting anything...

@boneskull boneskull merged commit 8a37e01 into master Jun 11, 2016
@boneskull boneskull deleted the skip-after-regression branch June 11, 2016 06:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug a defect, confirmed by a maintainer
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants