-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
(re-)enable after each hooks to fail tests. #1944
Conversation
cafc4ff
to
80fc890
Compare
@@ -16,7 +16,7 @@ describe('multiple calls to done()', function() { | |||
|
|||
it('results in failures', function() { | |||
assert.equal(res.stats.pending, 0); | |||
assert.equal(res.stats.passes, 1); | |||
assert.equal(res.stats.passes, 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I can tell this is a bug that has been fixed by my changes, this is the content of the test fixture:
describe('Multiple Done calls', function(){
it('should report an error if done was called more than once', function(done){
done();
done();
})
it('should report an error if an exception happened async after done was called', function (done) {
done();
setTimeout(done, 50);
})
it('should report an error if an exception happened after done was called', function(done){
done();
throw new Error("thrown error");
})
})
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure that code corresponds to the right test? Running that with mocha --reporter json
on master yields:
"stats": {
"suites": 1,
"tests": 3,
"passes": 3,
"pending": 0,
"failures": 2,
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nvm, the fixture highlighted above is the wrong one. It's actually: https://github.com/jjoos/mocha/blob/master/test/integration/fixtures/multiple.done.js Which makes sense then :) Since its contents are:
it('should fail in a test-case', function(done) {
process.nextTick(function(){
done();
done();
});
});
In that case, your code is an improvement! I'd be curious if you fixed the issue here as well: https://github.com/jjoos/mocha/blob/master/test/integration/fixtures/multiple.done.js#L4-L11
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah sorry for quoting the wrong fixture.
I actually looked at the commented out section of that fixture, but didn't know what the the correct behaviour is.
If I uncomment that fixture, the change to the test to make it pass looks like this:
it('results in failures', function() {
assert.equal(res.stats.pending, 0);
- assert.equal(res.stats.passes, 0);
- assert.equal(res.stats.failures, 1);
- assert.equal(res.code, 1);
+ assert.equal(res.stats.passes, 1);
+ assert.equal(res.stats.failures, 2);
+ assert.equal(res.code, 2);
});
Which seems strange since the beforeEach
error should cancel the execution of the test, but doesn't do that (I confirmed that the test is executed) But this could be an acceptable limitation of the async beforeEach implementation. If you clarify if this is acceptable I can uncomment it in my PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nvm, I'd leave that be then :)
Related: #1635 |
Mind rebasing on top of master? :) |
Heh, anytime we touch the runner code, it's a lot to QA 😅 |
In version 1.2.1, support was added to fail test in the after each hook: >* Added `this.test.error(err)` support to after each hooks. Closes mochajs#287 While migrating from teaspoon-mocha to karma-mocha, we discovered that in the current mocha version this isn't supported anymore. That behaviour has been changed in: ebc6aee without any documentation change. If this was a conscious decision adding some documentation about dropping this functionality would then be nice. The old behaviour is documented in: https://github.com/mochajs/mocha/wiki/Conditionally-failing-tests-in-afterEach()-hooks .
@danielstjules Ah missed #1635, this pr will fix that issue. Just rebased this commit on master. |
Exactly what I'm thinking :) |
I think if this gets merged it'd be reasonable to close #1635 as the main reason I requested it would be to do exactly what this PR enables. |
Was very excited when I found the wiki article - alas it is not working - can we get this soon? https://github.com/mochajs/mocha/wiki/Conditionally-failing-tests-in-afterEach()-hooks |
@jjoos any chance you're up for fixing the merge conflicts? This would be a huge help if/when it gets merged! |
I'm happy to adopt this if it's likely to be merged afterwards. There was a time when it was mergeable but wasn't integrated - so I'm not sure whether there was some other reason it wasn't accepted. |
@danielstjules sry to push on this so much, are you a potential gatekeeper for this? |
Any news about this? |
Anybody? |
Any updates? Does a workaround exist? |
FYI, pasted a workaround here #1635 (comment) |
can't use this unless the CLA is signed; please reopen if interested. |
In version 1.2.1, support was added to fail test in the after each hook:
While migrating from teaspoon-mocha to karma-mocha, we discovered that
in the current mocha version this isn't supported anymore. That behaviour has been changed in: ebc6aee without any documentation change.
If this was a conscious decision adding some documentation about dropping this functionality would then be nice. The old behaviour is documented in: https://github.com/mochajs/mocha/wiki/Conditionally-failing-tests-in-afterEach()-hooks .