-
Notifications
You must be signed in to change notification settings - Fork 860
test: React 18 snapshot adjustments #6944
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
test: React 18 snapshot adjustments #6944
Conversation
…yReactVersion utility
…y v14 (react 18-compatible) serializing and earlier versions
9a6d2c3 to
9c8441d
Compare
| return ( | ||
| <Fragment> | ||
| {preMatch} | ||
| {preMatch || undefined} |
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.
None of these || undefined changes affect output DOM, but they do unify how React Virtual DOM is being serialized no matter what versions of React and RTL are used.
| id="editorId" | ||
| rows="6" | ||
| style="height:100%;max-height:" | ||
| style="height:100%" |
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.
React 16-17 and 18 serializers generate different results here. The code underneath unifies it while keeping it working the same.
breehall
left a comment
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.
Hey Tomasz, I pulled this branch locally and didn't have any issues when I ran REACT_VERSION=17 yarn test-unit, but when running yarn test-unit, I did come across quite a few snapshot failures. I didn't have any issue with running yarn, so I don't think it has anything to do with me using an M1, but I never rule it out. There were about 377 snapshot failures.
I have also few questions about this process if that's ok!
- How do we determine which components need to have test cases that target React 17 or React 18?
- How long will we have to maintain two sets of test cases for the components that do require it?
| // Ignore invalid empty string style values | ||
| const style: CSSProperties = {}; | ||
| if (height !== '') { | ||
| style.height = height; | ||
| } | ||
| if (maxHeight !== '') { | ||
| style.maxHeight = maxHeight; | ||
| } | ||
|
|
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.
Super clean! 🧽
|
Hi @breehall! Thanks for testing the code locally! I forgot to mention that snapshots failing on React 18 because of
Realistically having tests targeting different React versions should be very rare. In our case we only need it because our drag and drop library
Technically the test cases are the same, but their snapshots differ between React versions due to tiny changes here and there. Since we only need them because of the DND library, I'd say there are at least two ways of getting rid of them:
|
breehall
left a comment
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.
Thank you so much for your explanations! Per your guidance, I'll skip over the test failures for now.
This would have been my strong preference, personally, especially if the react-drag/drop components are the only ones with this issue. The other major consideration to keep in mind here is how downstream Kibana snapshots are going to be affected. One option we could take is using our |
|
@cee-chen @breehall I just remembered what I wanted to add to my previous comment. None of our customers will need to use the conditional describe or test functions when running their tests. It exists purely to handle our React version switcher logic together with the huge amount of snapshot tests we have in place. |
|
Gotcha, that's definitely fair that consumers (I hope to god, anyway) won't be in the same situation as us in terms of having to support multiple versions of React. The |
* test: unify style properties values between React 18 and earlier versions * test: Separate Droppable snapshots by React version and add describeByReactVersion utility * test: separate Draggable snapshots by React version * test: separate column selector snapshots by React version * test: separate column sorting snapshots by React version * fix: unify empty string rendering in snapshots between testing-library v14 (react 18-compatible) serializing and earlier versions * docs: add testByReactVersion jsdoc
* test: unify style properties values between React 18 and earlier versions * test: Separate Droppable snapshots by React version and add describeByReactVersion utility * test: separate Draggable snapshots by React version * test: separate column selector snapshots by React version * test: separate column sorting snapshots by React version * fix: unify empty string rendering in snapshots between testing-library v14 (react 18-compatible) serializing and earlier versions * docs: add testByReactVersion jsdoc
* test: unify style properties values between React 18 and earlier versions * test: Separate Droppable snapshots by React version and add describeByReactVersion utility * test: separate Draggable snapshots by React version * test: separate column selector snapshots by React version * test: separate column sorting snapshots by React version * fix: unify empty string rendering in snapshots between testing-library v14 (react 18-compatible) serializing and earlier versions * docs: add testByReactVersion jsdoc
* test: unify style properties values between React 18 and earlier versions * test: Separate Droppable snapshots by React version and add describeByReactVersion utility * test: separate Draggable snapshots by React version * test: separate column selector snapshots by React version * test: separate column sorting snapshots by React version * fix: unify empty string rendering in snapshots between testing-library v14 (react 18-compatible) serializing and earlier versions * docs: add testByReactVersion jsdoc
Summary
Note: This branch contains changes from #6943 and needs rebasing when that one is merged.
This PR fixes all snapshot mismatches when running on different versions of React.
It adds
describeByReactVersionandtestByReactVersiontest utilities to separate snapshots by currently ran version of React for parts of the code where small implementation differences generate different snapshots, specificallyhello-pangea/dndusing different unique ID generators depending on version of React used (https://github.com/hello-pangea/dnd/blob/b1340b18b2987a31426fe6743b5ce3004e09fa08/src/view/use-unique-id.ts#L17-L37)QA
yarnto install dependenciesREACT_VERSION=17 yarn test-unitand ensure there are no errorsyarn test-unitand ensure there are not snapshot errors different thanclassattribute differences.This needs an improved emotion class name serializer that I'll add in a separate PR.