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

[Circus] Add timeout event, and don't print both timeout and expect.assertions error #7201

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

rickhanlonii
Copy link
Member

@rickhanlonii rickhanlonii commented Oct 18, 2018

Summary

This PR adds a new event for jest-circus called test_fn_timeout dispatched when a test times out.

This event will be fired in addition to test_fn_failure (that choice is up for discussion)

Motivation

The motivation for this change is to fix #3742

We do this by:

  • adding test.expired to TestEntry
  • set test.expired = true in the new test_fn_timeout hook
  • check that flag before printing expect.assertion errors

Test plan

Added e2e tests

@rickhanlonii
Copy link
Member Author

There are a few ways to fix the bug but adding this event seemed to make the most sense -- if this doesn't fit into the vision of jest-circus I'll happily try a different strategy

@@ -160,7 +160,12 @@ const _callCircusTest = (

return callAsyncCircusFn(test.fn, testContext, {isHook: false, timeout})
.then(() => dispatch({name: 'test_fn_success', test}))
.catch(error => dispatch({error, name: 'test_fn_failure', test}));
.catch(message => {
if (/^(Error: )?Exceeded timeout/.test(message)) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Not crazy about string matching here, any alternatives?

Copy link
Member

Choose a reason for hiding this comment

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

We might consider adding a property to the error we reject with, which can be set to timeout, assertion etc? Kind of like code for node core errors. Not sure

Copy link
Member Author

Choose a reason for hiding this comment

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

I thought to do that but we don't reject with an Error we reject with a message (oops)

Copy link
Member

Choose a reason for hiding this comment

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

seems fixable :D

@rickhanlonii rickhanlonii changed the title [Circus] Add test_fn_timeout, and bugfix for double error printing [Circus] Add test_fn_timeout, and don't print both timeout and expect.assertions error Oct 18, 2018
@rickhanlonii rickhanlonii changed the title [Circus] Add test_fn_timeout, and don't print both timeout and expect.assertions error [Circus] Add timeout event, and don't print both timeout and expect.assertions error Oct 18, 2018
@@ -79,6 +79,7 @@ export const makeTest = (
asyncError,
duration: null,
errors: [],
expired: false,
Copy link
Collaborator

Choose a reason for hiding this comment

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

I wonder if timedOut would be better name?

Copy link
Member Author

Choose a reason for hiding this comment

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

I was between both, not strongly opinionated either way

Copy link
Member

@SimenB SimenB Oct 18, 2018

Choose a reason for hiding this comment

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

more of a fan of failureReason: 'timeout' | 'error' | 'assertion-error' or something.
error being anything not JestAssertionError (and maybe node core assertion)

@SimenB
Copy link
Member

SimenB commented Nov 9, 2019

@rickhanlonii possible to bring this over the line?

@rickhanlonii
Copy link
Member Author

Oh wow I forgot about this. I won't have time to look at this until next year

@SimenB SimenB added this to the Jest 27 milestone May 4, 2020
@SimenB
Copy link
Member

SimenB commented May 4, 2020

We'll make circus the default in 27, would be nice to include this

@jeysal
Copy link
Contributor

jeysal commented May 4, 2020

Would be nice to get out before the major as well, as it seems non-breaking, and then we can be confident we make a version of circus the default that has already been proven

@jeysal jeysal modified the milestones: Jest 27, Jest 26.x May 4, 2020
@rickhanlonii
Copy link
Member Author

AFAIK we can rebase and land this as-is?

@SimenB
Copy link
Member

SimenB commented May 5, 2020

@rickhanlonii I still like my feedback here #7201 (comment) but other than that I think so yeah 😀

@@ -233,6 +233,8 @@ const eventHandler = (event: Event) => {
};

const _addExpectedAssertionErrors = (test: TestEntry) => {
if (test.expired) return;
Copy link
Member

Choose a reason for hiding this comment

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

instead of a new prop here, we could also check if test.errors > 0 and then not add from expect?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Reaching Timeout causes expect.assertions() to fail
5 participants