-
-
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
The minimal custom scheduler #8478
Comments
Thanks a lot for the detailed write-up, this seems more well-thought-out than what I've seen so far. Still, I'm sort of worried about introducing a completely alternative code path to serve such an API into |
Thanks for the docs on Is there any way to specify certain tests should be run "in band"? I have tests for a bunch of Express routes which start up the server & shut it down, but I'm running into problems because Jest is trying to run then asynchronously. I know I can use the |
This issue is stale because it has been open for 1 year with no activity. Remove stale label or comment or this will be closed in 14 days. |
This issue was closed because it has been stalled for 7 days with no activity. Please open a new issue if the issue is still relevant, linking to this one. |
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
There should be a configurable function that accepts a list of test suites to execute, and this code lets Jest know when a given test suite can be executed. Jest will give back a promise of the test suite completing.
This is the minimal custom scheduler, and is sufficient for my needs.
Motivation
Custom scheduling of tests has been brought up in several issues, but without any concrete proposals for how it would work. The issues were resolved with "probably won't fix", which is why I'm opening an issue before working on a PR.
The core requirements for this are integration and e2e test suites where some tests need to run to completion before others can start, but most tests can run concurrently (up to the number of workers).
Example
This is the minimal example of an implementation of this custom function, which works for both concurrent execution (with any number of workers) and run-in-band, as jest can freely delay execution of the actual test suite.
My actual implementation with dependencies between test suites
Pitch
I switched my integration tests from a custom script to jest a few months back, but due to not being able to control the scheduling of tests, I had to always run each test suite sequentially (and ended up essentially running it as a single large test suite, which means no output until the end).
When I revisited the problem recently and read through jest's source, I found this little bit of code and experimented with changing it to support the above API.
Surprisingly, it worked very well and in a few hours I had my integration tests running in parallel, with constraints on the ordering. I'm aware that a PR will be more work.
In both of my code examples, as well as the original jest source code (specifically in _createParallelTestRun), it just asks all of the tests to start as soon as it can. This allows jest to retain control over when tests concretely execute (for run-in-band, or when there are more suites than workers). The user wants to tell jest when a test run can start, and wants jest to tell it when the test run completes. That's the full contract.
This is a small API that's very flexible and allows jest to be used in situations where it currently struggles to fit.
The text was updated successfully, but these errors were encountered: