Skip to content
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

Bump jest to v26 and update focus tests #1102

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

joshuarrrr
Copy link
Member

@joshuarrrr joshuarrrr commented Oct 17, 2023

Description

Smaller change than #1094, but actually resolves the CVE, unlike #1091

Issues Resolved

Partially fixes #630 (CVE-2023-28155)

Check List

  • New functionality includes testing.
  • New functionality has been documented.
  • All tests pass
    • yarn lint
    • yarn test-unit
  • Update CHANGELOG.md
  • Commits are signed per the DCO using --signoff

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

For more information on following Developer Certificate of Origin and signing off your commits, please check here.

@BSFishy
Copy link
Contributor

BSFishy commented Oct 17, 2023

How is this different from #1094? Is there a case we would want this older version as apposed to the newer one?

@joshuarrrr joshuarrrr changed the title Bump jest to v26 and update or skip focus tests Bump jest to v26 and update focus tests Oct 17, 2023
@joshuarrrr
Copy link
Member Author

How is this different from #1094? Is there a case we would want this older version as apposed to the newer one?

It's more incremental, so there's a smaller diff. It gives us a chance to avoid a bunch of simultaneous changes due to jest, jsdom, and others. But now that I've got all the focus tests working (including re-enabling some long skipped), we may be able to very easily follow this with an upgrade to v29.

package.json Show resolved Hide resolved
Comment on lines +227 to +229
setTimeout(() => {
expect(childWrapper).toBe(document.activeElement);
}, 0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does the setTimeout fix the issues? I remember seeing changes about spying on the focus event, why don't we do that? It seems less flaky to me

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know the exact reason this changed between jsdom versions, but previously you could check for the activeElement immediately, whereas with the update you need to await an update cycle for focus changes to be applied. (There are probably other possible ways of doing this that may be better, such as jest.useFakeTimers(); and jest.advanceTimersByTime(0);). But I found that the setTimeout method worked consistently in all cases, including some which were previously skipped, with minimal changes to existing test structure.

Before I got this working, I was spying on the focus event, but that's actually worse, because it only tells you that the event was triggered, but mostly we want to test where the focus actually ends up, which is better tested via document.activeElement.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How confident are we that we are not introducing flakiness?

Have you by chance experimented with enzymejs/enzyme#2337 (comment)?

src/components/datagrid/data_grid.test.tsx Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

jest-cli-24.9.0.tgz: 4 vulnerabilities (highest severity is: 7.5)
3 participants