fix(jest-haste-map): Fix clobbering/errors when multiple configs use different haste impls #15522
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
jest-haste-map
'sworker
currently enforces (or tries to enforce) that all of its workloads use the samehasteImplModulePath
.This is problematic when multiple configurations, whose
hasteImplModulePath
may differ, share ajest-haste-map
worker - in particular:--runInBand
or--maxWorkers=1
Math.floor(maxWorkers / configs.length) == 1
,jest-file-map
processing is in-band.In these cases, where
worker.js
is loaded as an ordinary module by the host process, there are two bugs:hasteImpl
will be set by the first config and incorrectly silently reused by the second config (because we don't trigger the error condition, but do reusehasteImpl
), potentially causing spurious collision errors.The point of this check seems to be to allow caching of
hasteImpl
on the assumption that a given worker only sees one config. That caching doesn't really save any time though, becauserequire
calls are already backed by Node's own module cache.So we simplify the worker, fix the bugs, and incur no observable performance penalty by just removing the check.
Test plan
Made this modification locally to Jest at Meta, where we currently have 5 projects including 2 different haste impls. We observed the bug on 10 core machines where
jest-haste-map
instances were allocatedMath.floor( (10-1) / 5 ) == 1
workers, and this change fixes it.