-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
Document how parallelization works in Jest #6957
Comments
Your points are correct. We have Wanna send a PR? 🙂 One thing to note about |
Hi! I'm interested in picking up and trying to solve this issue. Now, I see some work was done in #6979 but it was never completed. Thanks |
We have since gotten an architecture page: https://jestjs.io/docs/en/architecture Adding it there would be perfect 🙂 |
Finished a first attempt at #7984 |
Merged the above PR (as code comments) |
Hi @SimenB , You wrote:
So, it's possible to run tests from same file in parallel, but it was buggy in the past... Have anything changed since then? I saw this commit: https://github.com/facebook/jest/pull/7408/files Thank you a lot! You answer will be very helpful, because we need such a feature on our project, and trying to decide between something more mature like jest and something new and experimental like toundra that was created specifically to support such type of parallelization... |
#7408 does not affect parallelization in a single test, just across test files (which Jest has had for years, and will use node workers when it's less buggy (see #7681)). However, relatively recent fixes like #7770 (which came in 24.1.0) does. So this is something we want to support properly at some point. I've created a label with a few of the main missing features: https://github.com/facebook/jest/labels/Area%3A%20Concurrent However, almost all of Yarn's tests use |
Hi @SimenB , Just to clarify, sorry if I am asking stupid questions... Will ever jest support "running tests inside one suite/file in parallel"? Or is this supported even now? |
@yashaka this is somewhat supported, see |
I'm finding that tests run concurrently even within a
-->
This runs contrary to my expectations, and to @callumlocke's "Pitch" above. Unless I'm missing something... I see this ticket is closed, but the Architecture page @SimenB mentioned doesn't actually describe the general rules for parallelizing tests. |
That's expected behaviour - tests do not execute synchronously. We execute |
Ok, thanks for the explanation. Is this behavior documented anywhere? It was a surprise to me, and took me some time to figure out why my tests like the above example (ported from EDIT: this is probably a good enough explanation, though the information about collecting |
So the only way to runs tests in parallel way is to create one testsuite (one file) for every test? i thought jest tries always to runs test in a parallel way if --runInBand is not set, but making a try it looks like it runs in parallel testsuites, not tests. You can understand the suites are running in a parallel way because the command prompt say RUNS a lot of file together even if you put more test in a file (a testsuite) they are runned sequentially both they are in a describe block or N describe block : i make this experiment : every test wait 5000ms before ends in a single describe block, it tooks more than 10 000 ms to ends
splitting in two describe block,
nothing changed splitting in two different files, they runs in a parallel way (there are 3 seconds of overhead) but i don't like so much to put one test in one file , because it's very time consuming. what i'm doing wrong? thanks. |
as suggestede by @octalmage , test.concurrent looks what we needed. anyway i make a try , webstorm looks confused about the execution time required, but it looks working as espected : there is a test that will wait 6 seconds and other 3 tests wait less, the total execution time is 6 seconds because i have 12 cpu and 4 test are runs in parallel. |
The above example using |
I would agree that test developers require a knowledge of how test scheduler works and how code is actually executed in parallel. This will allow writing tests in a more effective way from the performance endpoint. Sadly, this information is not available in the documentation. Christoph does touch this subject in his 50-minute video, but very briefly. I could also say that almost every regular developer will not go to the source code of the Jest to figure this out. I think this subject does require attention and should be documented in a more accessible manner. Therefore, I would suggest to re-open this issue. The problem I'm trying to solve (if this would help), is that my application requires a lot of runtime bootstrapping in order to execute the code. So I'm trying to figure out how to structure my tests in order to make them more performant. Obviously, I don't want to run this bootstrapping code for each test file cause it will degrade the performance very quickly. Also, it would be interesting to know how global state is shared between the tests. I'm gonna try to study the Jest source code to get a better understanding, but I will be very grateful for any hints and information regarding this subject. Thank you! |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
🚀 Feature Proposal
A piece of official documentation stating exactly how parallelization works in Jest, including whether it's safe to assume that all suites and test cases within a single file will always run serially in source order.
Motivation
It is basic information that should be officially documented.
Pitch
I've searched online for answers to this, and I can only find equivocal Stack Overflow threads and disagreement. From experimenting, I think it works like this:
runInBand
option). So it is not safe for multiple test files to share a mutable data store.describe
andtest
blocks within a file always run in serial, in declaration order. So you can safely mutate a module-scoped variable across several tests with predictable results (even when some tests are nested more deeply than others indescribe
trees). This can be useful when testing a series of mutations to a piece of state.That's how Jest seems to work today. But I want to see docs stating if that's the intended behaviour, so I can be sure it won't suddenly change without warning in a minor performance update.
The text was updated successfully, but these errors were encountered: