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

Upgrade jest #1892

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

darthmaim
Copy link
Contributor

@darthmaim darthmaim commented Dec 6, 2024

🏠 Internal

  • Upgrade jest and related dependencies to the latest version

Yet another step closer towards running tests with react@19 (#1883).

Comment on lines +3 to +6
const { TextEncoder, TextDecoder } = require('util');

global.TextEncoder = TextEncoder;
global.TextDecoder = TextDecoder;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've had to add this because jest-environment-jsdom does not contain TextEncoder and TextDecorder, but react requires them.

},
fakeTimers: {
enableGlobally: true,
legacyFakeTimers: true,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is only a single test that fails when using the modern mock timers, but it wasn't immediately obvious how to fix this (probably just jest.useRealTimers()?), so I've just kept using the legacy fake timers for now which were the default with jest 25.

expect(data[0].date.constructor).toEqual(Date);

failed with

 FAIL  packages/visx-mock-data/test/genDateValue.test.ts
  ● generators/genDateValue › should return [{ date, value }]

    expect(received).toEqual(expected) // deep equality

    Expected: [Function ClockDate]
    Received: [Function Date]

      19 |     const n = 1;
      20 |     const data = genDateValue(n);
    > 21 |     expect(data[0].date.constructor).toEqual(Date);
         |                                      ^
      22 |     expect(typeof data[0].value).toBe('number');
      23 |   });
      24 |

      at Object.toEqual (packages/visx-mock-data/test/genDateValue.test.ts:21:38)

There is another test referencing fake timers, so that one should be revisited as well when switching from legacy to modern fake timers:

// fake timers in Jest 25 are completely unusable so I'm using real timers here
// when it's upgraded should be updated to use advanceTimersByTime

@darthmaim darthmaim changed the title Upgrade babel Upgrade jest Dec 6, 2024
@darthmaim darthmaim mentioned this pull request Dec 6, 2024
@darthmaim darthmaim force-pushed the feature/upgrade-jest branch 2 times, most recently from e673fd7 to 0482ca3 Compare December 16, 2024 19:49
@darthmaim darthmaim marked this pull request as ready for review December 16, 2024 19:50
@darthmaim
Copy link
Contributor Author

The CI errors are probably caused by still using [email protected] (release over 3 years ago). We might need to upgrade typescript first.

@darthmaim darthmaim force-pushed the feature/upgrade-jest branch from 0482ca3 to 85957e0 Compare December 16, 2024 21:17
@williaster
Copy link
Collaborator

thanks for starting this. I wanted to try the typescript 4 upgrade and thought it'd be worth pulling in these changes. have a wip branch here, lots of issues to work through #1894

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.

2 participants