-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
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
fix(jest-core): always use workers in watch mode #14059
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -27,25 +27,25 @@ export function shouldRunInBand( | |||||||
} | ||||||||
|
||||||||
/* | ||||||||
* Run in band if we only have one test or one worker available, unless we | ||||||||
* are using the watch mode, in which case the TTY has to be responsive and | ||||||||
* we cannot schedule anything in the main thread. Same logic applies to | ||||||||
* watchAll. | ||||||||
* If we are using watch/watchAll mode, don't schedule anything in the main | ||||||||
* thread to keep the TTY responsive and to keep the watcher running even if | ||||||||
* the test crashes. | ||||||||
*/ | ||||||||
const isWatchMode = watch || watchAll; | ||||||||
if (isWatchMode) { | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
return false; | ||||||||
} | ||||||||
|
||||||||
/* | ||||||||
* Otherwise, run in band if we only have one test or one worker available. | ||||||||
* Also, if we are confident from previous runs that the tests will finish | ||||||||
* quickly we also run in band to reduce the overhead of spawning workers. | ||||||||
* Finally, the user can provide the runInBand argument in the CLI to | ||||||||
* force running in band. | ||||||||
* https://github.com/facebook/jest/blob/700e0dadb85f5dc8ff5dac6c7e98956690049734/packages/jest-config/src/getMaxWorkers.js#L14-L17 | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Leave this comment in place, please. Check that link, the logic there sets There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, you're right, thanks. (It seems with the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||||
*/ | ||||||||
const isWatchMode = watch || watchAll; | ||||||||
const areFastTests = timings.every(timing => timing < SLOW_TEST_TIME); | ||||||||
const oneWorkerOrLess = maxWorkers <= 1; | ||||||||
const oneTestOrLess = tests.length <= 1; | ||||||||
|
||||||||
if (isWatchMode) { | ||||||||
return oneWorkerOrLess || (oneTestOrLess && areFastTests); | ||||||||
} | ||||||||
|
||||||||
return ( | ||||||||
// When specifying a memory limit, workers should be used | ||||||||
!workerIdleMemoryLimit && | ||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm.. Perhaps the comment should say: "and prevents watch mode crashes caused by tests leaking due to improper teardown". Or something that way?
It isn’t that workers do prevent watch mode to crash due to fatal errors in tests, that is more about preventing leaks / open handles or debugging them (as you pointed out in the issue).
There is no mechanism to deal with this problem if tests run in band. Leaks are handled more gracefully in parallel run, because worker farm gets killed after tests run is finished:
https://github.com/facebook/jest/blob/470d72ee74e50291bf8593954f24eb75b5621351/packages/jest-runner/src/index.ts#L180-L194
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the suggestions -- took another stab at explaining this.