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 v27 #1198

Merged
merged 6 commits into from Apr 21, 2023
Merged

Bump Jest to v27 #1198

merged 6 commits into from Apr 21, 2023

Conversation

mcmire
Copy link
Contributor

@mcmire mcmire commented Apr 18, 2023

Description

The mocked utility function from ts-jest, which we commonly use, was moved into Jest in v27.

Changes

N/A

References

This is a blocker for #1197, as we want to update the NetworkController tests to use jest.mocked instead of mocked from ts-jest/utils.

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation for new or updated code as appropriate (note: this will usually be JSDoc)
  • I've highlighted breaking changes using the "BREAKING" category above as appropriate

@mcmire mcmire requested a review from a team as a code owner April 18, 2023 02:00
@socket-security
Copy link

socket-security bot commented Apr 18, 2023

New dependency changes detected. Learn more about Socket for GitHub ↗︎


👍 No new dependency issues detected in pull request

Bot Commands

To ignore an alert, reply with a comment starting with @SocketSecurity ignore followed by a space separated list of package-name@version specifiers. e.g. @SocketSecurity ignore foo@1.0.0 bar@* or ignore all packages with @SocketSecurity ignore-all

Pull request alert summary
Issue Status
Install scripts ✅ 0 issues
Native code ✅ 0 issues
Bin script shell injection ✅ 0 issues
Unresolved require ✅ 0 issues
Invalid package.json ✅ 0 issues
HTTP dependency ✅ 0 issues
Git dependency ✅ 0 issues
Potential typo squat ✅ 0 issues
Known Malware ✅ 0 issues
Telemetry ✅ 0 issues
Protestware/Troll package ✅ 0 issues

📊 Modified Dependency Overview:

⬆️ Updated Package Version Diff Added Capability Access +/- Transitive Count Publisher
jest@27.5.1 26.6.3...27.5.1 None +990/-3222 simenb
jest-environment-jsdom@27.5.1 26.6.2...27.5.1 None +11/-91 simenb
ts-jest@27.1.5 26.5.6...27.1.5 environment +1044/-3240 kul
@types/jest@27.5.2 26.0.24...27.5.2 eval +108/-108 types

@legobeat
Copy link
Contributor

legobeat commented Apr 18, 2023

The test errors seem to be due to breaking changes in v28 that requires us to do changes in the setup.

https://jestjs.io/docs/28.x/upgrading-to-jest28#jsdom

jestjs/jest#12879

I'd suggest to

  1. Draw down this upgrade to 27.x for now
  2. Address the upgrade to 29 in a separate change

@mcmire mcmire changed the title Bump Jest to v29 Bump Jest to v27 Apr 18, 2023
@mcmire
Copy link
Contributor Author

mcmire commented Apr 19, 2023

@legobeat Ah, thanks! I've updated this PR to bump Jest to only v27.

@@ -44,7 +44,7 @@ function flushPromises(): Promise<unknown> {

describe('CurrencyRateController', () => {
beforeEach(() => {
jest.useFakeTimers();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed because Jest v27 switches to the "modern" fake timers by default and these must mock more things related to timers than the legacy fake timers, because now any of the tests that involve HTTP requests are timing out. I suspect because this is because node-fetch calls setTimeout on the request object during the request-response flow, but I didn't look beyond that.

Copy link
Member

Choose a reason for hiding this comment

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

More information on this: nock/nock#2200

It seems that using the legacy implementation is the best solution for now. Jest v28 offers more options though. When we update to v28 we should consider using the modern timers but configuring it to leave whatever we need here unmocked.

@@ -16,7 +16,7 @@ module.exports = merge(baseConfig, {
// An object that configures minimum threshold enforcement for coverage results
coverageThreshold: {
global: {
branches: 81.51,
branches: 80.79,
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we have an explanation for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, that's fair. Let me dive deeper into the coverage reports.

Copy link
Contributor

Choose a reason for hiding this comment

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

Rebased on main (there were some yarn.lock conflicts) and ran a project-wide jest-it-up - the drop here persists.

Copy link
Member

Choose a reason for hiding this comment

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

For the preferences controller tests, the branch coverage went from 22/24 to 13/15. Here in the transactions controller, branch coverage went from 217/264 to 185/229

The reports seem to show the same gaps, roughly. I did a visual comparison and they were nearly identical. The one difference is that the else case for this condition used to be flagged as uncovered, but now it isn't.

I did a quick search in the Jest issue tracker but couldn't find any reference to this.

This is curious, but I don't think it needs to block this PR.

@mcmire mcmire self-assigned this Apr 19, 2023
The `mocked` utility function from `ts-jest`, which we commonly use, was
moved into Jest in v27.
@legobeat legobeat force-pushed the bump-jest branch 2 times, most recently from c186550 to 0503bbb Compare April 19, 2023 11:05
Copy link
Member

@Gudahtt Gudahtt left a comment

Choose a reason for hiding this comment

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

Looks great! I can approve once the conflicts are resolved

@legobeat legobeat requested a review from Gudahtt April 19, 2023 13:15
@@ -16,7 +16,7 @@ module.exports = merge(baseConfig, {
// An object that configures minimum threshold enforcement for coverage results
coverageThreshold: {
global: {
branches: 86.67,
Copy link
Contributor

Choose a reason for hiding this comment

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

Had to do this after merge of main

Copy link
Member

@Gudahtt Gudahtt left a comment

Choose a reason for hiding this comment

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

LGTM!

@Gudahtt Gudahtt merged commit 3fd38b8 into main Apr 21, 2023
85 checks passed
@Gudahtt Gudahtt deleted the bump-jest branch April 21, 2023 12:51
MajorLift pushed a commit that referenced this pull request Oct 11, 2023
* Bump Jest to v27

The `mocked` utility function from `ts-jest`, which we commonly use, was
moved into Jest in v27.

* jest-it-down

---------

Co-authored-by: legobt <6wbvkn0j@anonaddy.me>
Co-authored-by: legobeat <109787230+legobeat@users.noreply.github.com>
MajorLift pushed a commit that referenced this pull request Oct 11, 2023
* Bump Jest to v27

The `mocked` utility function from `ts-jest`, which we commonly use, was
moved into Jest in v27.

* jest-it-down

---------

Co-authored-by: legobt <6wbvkn0j@anonaddy.me>
Co-authored-by: legobeat <109787230+legobeat@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants