-
-
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
Hook error handling (#534) -- continue testing even if some hooks are failing #1043
Conversation
Any chances this is good/bad or no one needs this? |
@Rulikkk ++ @visionmedia @travisjeffery Any chance this can get reviewed.... Its is a pretty big deal that failing hooks fail the entire test run. |
Only suites affected by a failing hook will stop.
* Rulikkk-hook-error-handling: Handle errors in hooks (#1043)
looks good. merged. |
@travisjeffery big enough for a vbump? I would love to start using this ASAP. |
|
This doesn't seem to work if the before/beforeEach is asynchronous. In the following test, the after() function is never called: var assert = require('assert');
describe("before-and-after", function() {
before(function(done) {
process.nextTick(function() {
assert.ok(false);
done();
});
});
after(function() {
console.log("\nin after()");
});
it("the test", function() {
assert.ok(true);
});
}); Is it even possible to fix that? If so, should I file a separate bug? |
@BryanDonovan here's what should do it (I use it this to retrieve remote resources in var assert = require('assert');
describe("before-and-after", function() {
before(function(done) {
process.nextTick(function() {
try {
assert.ok(false);
} catch (e) {
done(e);
}
done();
});
});
after(function() {
console.log("\nin after()");
});
it("the test", function() {
assert.ok(true);
});
});``` |
Yeah, that would work, but it's very cumbersome to put a try/catch in every before() function. |
I have a question regarding this fix. So, this issues seems to be resolved and is working as expected when using the hooks in sync mode. When I attempt to use the hooks in async mode (with done callback), sibling suites do not get executed. If I have two sibling suites with async beforeEach, afterEach and tests - an async error thrown in the afterEach of the first suite will fail all tests in that suite (as expected) and also will stop execution of the second suite which does not seem expected. Sample Code: describe('Multiple Suites Test', function() {
// Code to throw Error in async mode
}); When the above file is executed you see the below output as expected: 3 passing (14ms)
If the same code is run with commented code enabled and the first afterEach in async mode, the output looks like below, Multiple Suites Test 1 passing (1s)
The second suite is completely ignored. |
@BryanDonovan , I think your issue is similar to what I am seeing above. I have tried fixing this in a branch - ajaks328@65eba1c |
This closes #534 and also affects #973, #975 and maybe #516, #581, #664, etc.
I have implemented hook-error behaviour in a try-finally manner, which means that for the failing hook, its counterpart will be executed (if exists), but the tests will be ignored, and the execution will skip to the next sibling suite.
In detail:
After any hook error, the next sibling suite (relative to the suite with hook error) is executed.
This allows writing test hooks in a symmetrical manner: