-
Notifications
You must be signed in to change notification settings - Fork 161
Replace deprecated testing library in unit tests #4572
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
Conversation
3d72172
to
b0747de
Compare
b0747de
to
24d43ac
Compare
Seems like the package intentions is to support newer versions of Jest, ref. Em-Ant/jest-transformer-svg#5. Maybe we should file an issue and eventually help with fixing the Jest 29 support? |
Ideal if we can.
…On Sun, 19 Jan 2025 at 12:55, Erik Godding Boye ***@***.***> wrote:
Seems like the package intentions is to support newer versions of Jest,
ref. Em-Ant/jest-transformer-svg#5
<Em-Ant/jest-transformer-svg#5>. Maybe we
should file an issue and eventually help with fixing the Jest 29 support?
—
Reply to this email directly, view it on GitHub
<#4572 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAA6C3ZYHDSDVD4XVGSZ2A32LOACTAVCNFSM6AAAAABVOPJMUWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDMMBQHAYDQMJVHE>
.
You are receiving this because your review was requested.Message ID:
***@***.***>
|
I've done some more digging on this and it's not a bug in the weave-gitops/ui/components/DarkModeSwitch.tsx Lines 28 to 34 in 22a1bd7
This seems to be the result of this issue in From what I understand, the correct behaviour to resolve this would be to encode the images as base64 instead of plain XML. This would allow both the browser, and the tests to interpret them properly instead of them only being interpretable inside the browser. |
This commit upgrades the testing library from `react-test-renderer` to `@testing-library/react`. This largely results in changes to `renderer.create().toJSON()` becoming `render().asFragment()`. To ensure minimal snapshot changes were recorded, I used `firstChild` from the fragment so the fragment wrapper was not added to the snapshots. During testing, a large number of failure messages such as: ```plaintext An empty string ("") was passed to the src attribute ``` This message would cause tests to fail and is the result of `svg` images being passed to the fileMock in `ui/lib/fileMock.js` To resolve this, I replaced `svg` management with `jest-svg-transformer` but this raises a concern that the library is 7 years old with no recent maintainence. Whilst there is a more modern variant `jest-transformer-svg`, this transformer does not seem to work with `jest >= v29`, ultimately causing snapshots to fail with `:1:2088: property missing ':'` This replacement largely affects two test suites: - Page - Logo In both of these suites, images are now replaced with an empty `<img />` tag rather than a more complete styled tag
24d43ac
to
348156d
Compare
Introduced a util method to convert from |
Sounds good! Does this mean the PR is reviewable/mergeable? Maybe update the PR description with the latest news? 😉 |
It should be reviewable yes. I'd like to wait for @gusevda as he has way more experience with Typescript than I do and may know of a better way to solve the same issue. |
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.
Looks great to me!
Only one comment which should not block merging. I'm not sure about use of .firstChild()
. If it's only about existing snapshots, I would not worry about them. We are not changing the implementation in this PR, only tests, so we can be sure that we are not introducing any new bugs, so we can safely update all the snapshots. Use of firstChild()
can be confusing for developers in the future.
I think if you're happy for it to go, it's a |
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.
Awesome!
What changed?
This commit upgrades the testing library from
react-test-renderer
to@testing-library/react
.This largely results in changes to
renderer.create().toJSON()
becomingrender().asFragment()
. To ensure minimal snapshot changes were recorded, I usedfirstChild
from the fragment so the fragment wrapper was not added to the snapshots.Why was this change made?
This change was made to replace the deprecated
react-test-renderer
with a more modern equivelent which is compatible with future versions of React frameworkSide effects
During testing, a large number of failure messages such as:
This message would cause tests to fail and is the result of
svg
images being passed to the fileMock inui/lib/fileMock.js
To resolve this, I have replaced
svg
management withjest-transformer-svg
and introduced a helper method to convert importedsvg
images to a usable base64 encoded version for use in CSS styling