-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
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
Pass jest-diff options to fix a11 y issues#12576 #13362
base: main
Are you sure you want to change the base?
Pass jest-diff options to fix a11 y issues#12576 #13362
Conversation
Hi @grazirs! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at [email protected]. Thanks! |
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
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.
Thanks for working on this. Looks very interesting.
I think unit tests should be added to make sure there is no regression in the future.
This is a great start, thanks for working on it! I have no comments beyond the ones left by @mrazauskas 👍 And yeah, tests that assert options passed through are respected seems reasonable. This PR brings down overall code coverage - while admittedly it's not super high currently, this PR should quite easily be able to keep the status quo 🙂 |
Hi @SimenB and @mrazauskas, thanks for your suggestions. Here's an example of how it would look like for a test of the
I would do the same in all the matchers and test where styled strings are printed. To ensure that there are no hardcoded colors used somewhere, I'm not passing the default colors in the matcher's state. This will make the snapshots update, as the output of the tests will have a different style. As I wrote in the PR description, there are some matchers that cannot be updated in this PR, therefore their tests will not be updated. |
That seems reasonable to me! |
Hi @SimenB @mrazauskas! Are there any updates on this? |
@@ -1,295 +1,295 @@ | |||
// Jest Snapshot v1, https://goo.gl/fbAQLP | |||
|
|||
exports[`.rejects fails for promise that resolves 1`] = ` | |||
<d>expect(</><r>received</><d>).</>rejects<d>.</>toBe<d>()</> | |||
expect([35mreceived</>).rejects.toBe() |
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.
seems the escape sequences are off now
const receivedColor = options.receivedColor ?? RECEIVED_COLOR; | ||
const expectedColor = options.receivedColor ?? EXPECTED_COLOR; |
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.
We already have this.utils.RECEIVED_COLOR
and this.utils.EXPECTED_COLOR
already. I wonder if we should add the configured colors to this.utils
a bit more cleanly, and then use that ourselves instead of checking within every single matcher?
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.
See #13567 - if this PR makes sure to tweak matcher context instead of looking through options
in every matcher, it should in theory be easier for all matchers to use the correct colors.
a1a1e19
to
c8890be
Compare
This PR is stale because it has been open 90 days with no activity. Remove stale label or comment or this will be closed in 30 days. |
This PR was closed because it has been stalled for 30 days with no activity. Please open a new PR if the issue is still relevant, linking to this one. |
…her in matcher.ts
…tcher in index.ts
c0f56d7
to
5d97465
Compare
✅ Deploy Preview for jestjs ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify site configuration. |
Hi @SimenB and @mrazauskas . I synced my branch with main and resolved the conflicts. All the tests are passing on my machine (node 16.20.0 on macOS) but the snapshot are failing on the CI. Any idea on what it might be? |
Summary
This PR is a first step to solve #12576. The proposed solution was to let the user pass a
DiffOptions
to the configs, allowing them to set their own color choices. However, accessing the config where the default colors are used would require deep refactoring.As a first approach, with this PR we let the user pass a
MatcherHintOptions
andDiffOptions
in the expect state with expect.setState, and we make sure the default colors are used only if the user didn't overwrite them.There are some methods where the default colors are still being used because passing a
MatcherHintOptions
orDiffOptions
to them would require deep refactoring.The affected files are:
Test plan
These changes are not affecting the current behavior of the code or breaking any test, so no new tests have been added.