Call print for non-string children in ReactTestComponent plugin #3745
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
The most likely reason for the redundant branches deleted in #3731 was an unsuccessful attempt at a shortcut as in
ReactTestComponent
plugin to call itself directly for children, instead of calling the genericprint
serializer argument.When the plugin was written a year ago, that optimization made sense, but now since #3017
pretty-format
runs plugins before serializing nested basic values, it is more consistent:printChildren
inReactTestComponent
,ReactElement
, andHTMLElement
This pull request has a small optimization to make up some lost time. Reorder the plugins in
jest-snapshot
to what seems like decreasing frequency of occurrence:ReactTestComponent
moves to first placeReactElement
stays in second placeHTMLElement
moves to third placeImmutable
plugins stay in last place, mainly because ofconcat
methodHere are some measurements for 22 tests adapted from
React-test.js
:ReactTestComponent
originalReactTestComponent
proposedReactElement
Interpretation:
ReactTestComponent
with the improved plugins order is less time than originalReactTestComponent
and plugins order.ReactTestComponent
with improved plugins order.ReactElement
plugin stays the same, its test time is within the timing precision, although the test logic forReactTestComponent
is indeed less thanHTMLElement
.ReactElement
is slower because it distinguisheschildren
from rest of props and flattens children.Test plan
Jest
Residue
This PR will make
PLUGINS
order injest-snapshot
consistent withjest-diff
but can y’all explain whyjest-matcher-utils
doesn’t includeReactTestComponent
and what is the purpose of itsserialize
function?jest-diff
https://github.com/facebook/jest/blame/master/packages/jest-diff/src/index.js#L28-L33jest-matcher-utils
https://github.com/facebook/jest/blob/master/packages/jest-matcher-utils/src/index.js#L21-L23jest-snapshot
https://github.com/facebook/jest/blob/master/packages/jest-snapshot/src/plugins.js#L20