-
-
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
Retry logic is not working when beforeEach() or afterEach() functions fail #2120
Comments
@grvk some context on why it behaves as it does: #1989 (comment) |
re this (from #1989):
I'm not sure what side of the fence I'm on here. @danielstjules 's point makes sense. Yet, his suggestion of moving the functionality into the specs themselves would create boilerplate, which should be avoided. @grvk @DmitriiAbramov Why can't you explicitly handle potential errors in your hooks? |
A pattern that may be helpful is this: function tryToGetCriticalValue() {
// set a max # of retries here; something like lodash's _.before()
return getIt()
.catch(() => tryToGetCriticalValue());
}
describe('something wonky', () => {
let value;
beforeEach(() => {
return tryToGetCriticalValue()
.then(v => value = v);
});
it('should do something with the value', () => {
// ...
});
}); |
@boneskull yeah... if possible, i always try to do local retries. e.g. in e2e tests beforeEach(retryFiveTimes(() => navigateTo('http://localhost:3000'))); so that it stays in it('opens the page', function() {
clickSomeLink(); // at this point something throw an error (network call to profile_pic.jpg failed)
validateSomethingIsThere(); // all good, test passes
});
afterEach(function() {
let output = getConsoleErrorOutput(); // here we get our network error log
if (output) {
// even if we retry, it's not going to change anything. the output has been already printed
// to the console during `it` block execution
throw new Error(`some weird stuff got printed in the console: ${output}`);
}
}); |
@DmitriiAbramov The That being said, I'm going to close this for now, unless someone can make a reasoned argument against @danielstjules's comment:
@danielstjules It'd be helpful if you can explain exactly why we cannot be sure of the program state? |
@boneskull created a new issue with the explanation of the console stuff #2127 |
Hello,
I've been trying to run a simple suite:
My expectation was that if it(), beforeEach() or afterEach() fail, then beforeEach() > it () > afterEach() functions are to be executed again. However, it appears that retry logic is not triggered if beforeEach() or afterEach() fail. It works only if the failing function is it()
The text was updated successfully, but these errors were encountered: