fix(jest-transform): ensure correct config is passed to preprocessors specified multiple times in transform
#13770
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.
Fixes #13769.
Summary
Regarding the
transform
option of Jest configuration, it's not currently possible to use the same preprocessor with different configuration objects for different match patterns. This is because the latest entry intransform
for a given preprocessor will always overwrite the configuration of earlier entries. See #13769 for more context.Implementation
Instead of caching preprocessors and the corresponding configuration based solely on the preprocessor path, we can cache based on the match pattern + preprocessor path pair. While there are different ways of going about this, here I've updated
transformCache
to use a simple string concatenation of the file match pattern + preprocessor path for its keys. This ensures that the correct configuration can be identified.Please let me know if you'd prefer an alternative means of solving this problem - I'm happy to adjust.
Test plan
I included a new unit test which validates this case. In addition to ensuring all current tests pass, please let me know if there's any other tests that would be useful to write.