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

jest-circus Timeouts #3760

Merged
merged 2 commits into from
Jun 8, 2017
Merged

Conversation

aaronabramov
Copy link
Contributor

jest.setTestTimeout will actually set a timeout per async fn.
So if there's a timeout of 20ms and there's a beforeEach hook defined, the total timeout for a test will be 40ms (20ms for beforeEach and 20ms for the test itself).

i think this is reasonable, but maybe we'll need to rename setTestTimeout to setTimeout as @cpojer suggested earlier

@codecov-io
Copy link

codecov-io commented Jun 8, 2017

Codecov Report

Merging #3760 into master will decrease coverage by <.01%.
The diff coverage is 0%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3760      +/-   ##
==========================================
- Coverage   59.92%   59.91%   -0.01%     
==========================================
  Files         191      191              
  Lines        7001     7002       +1     
  Branches        6        6              
==========================================
  Hits         4195     4195              
- Misses       2803     2804       +1     
  Partials        3        3
Impacted Files Coverage Δ
packages/jest-circus/src/state.js 0% <ø> (ø) ⬆️
packages/jest-circus/src/run.js 0% <0%> (ø) ⬆️
packages/jest-circus/src/utils.js 0% <0%> (ø) ⬆️
packages/jest-runtime/src/index.js 76.37% <0%> (ø) ⬆️
packages/jest-runtime/src/ScriptTransformer.js 90.64% <0%> (ø) ⬆️
.../src/legacy_code_todo_rewrite/jest-adapter-init.js 0% <0%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a2a9664...d458736. Read the comment docs.

@@ -110,46 +110,59 @@ const getEachHooksForTest = (
return result;
};

const _makeTimeoutMessage = (timeout, isHook) => {
const message = `Exceeded timeout of ${timeout}ms for a ${isHook ? 'hook' : 'test'}.`;
Copy link
Contributor

Choose a reason for hiding this comment

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

What do you think about also receiving testEntry.name as a parameter? So that it is a bit more explicit about in which test this happened

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i actually did it first and then realized that the name of the test is already printed right before the error (cause it's going to be under the failing test) 🙂

Copy link
Member

Choose a reason for hiding this comment

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

What does this look like? Currently, timeouts are the hardest thing to deal with and the signal they give is so bad.

Also, you can write this function without curly braces, return statements or new variables. I believe in you.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

screen shot 2017-06-08 at 9 06 43 am

timeouts are hard to deal with, but mostly because of the quality of the test.
There's not much we can do here. We can try to print the exact hook that timeouted (if it happened in a hook) or we can try to print test coverage of the test function (to see which parts weren't called), but i'm not sure how helpful it is

Copy link
Member

Choose a reason for hiding this comment

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

Can we add "Use jest.setTimeout(…) to update the timeout" maybe?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

that's actually a good idea

{
isHook,
timeout,
test,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Shouldn't it be sorted alphabetically? It seems pretty important to @cpojer though, so I'm just stealing his thunder.

Copy link
Member

Choose a reason for hiding this comment

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

yes, it must be. It is sacred.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@cpojer that will go into your performance review! 😃

}
// If it's a Promise, return it.
if (returnedValue instanceof Promise) {
return returnedValue.then(resolve).catch(reject);
Copy link
Member

Choose a reason for hiding this comment

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

.then(resolve, reject)

@aaronabramov
Copy link
Contributor Author

i also renamed setTestTimeout to setTimeout until it's too late

@cpojer
Copy link
Member

cpojer commented Jun 8, 2017

I recommend making the jasmine.DEFAULT_TEST_TIMEOUT a getter/setter and write to jest.setTimeout for the compat layer.

@aaronabramov
Copy link
Contributor Author

screen shot 2017-06-08 at 9 42 50 am

@cpojer
Copy link
Member

cpojer commented Jun 8, 2017

Mind inverting this? "Use … if this is a long running test."

@aaronabramov
Copy link
Contributor Author

@cpojer done!

@cpojer
Copy link
Member

cpojer commented Jun 8, 2017

shipit

@aaronabramov aaronabramov merged commit 92e432a into jestjs:master Jun 8, 2017
@aaronabramov aaronabramov deleted the circus-timeouts-1 branch June 8, 2017 17:46
tushardhole pushed a commit to tushardhole/jest that referenced this pull request Aug 21, 2017
* jest-circus Timeouts

* setTestTimeout/setTimeout
@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants