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

test: unit test fixes for jest 29.5 #4029

Merged

Conversation

richshaffer
Copy link
Contributor

@richshaffer richshaffer commented Mar 14, 2023

This adds some minor changes that will allow the jest 29.5 updates in #3979 to pass unit tests:

  • Use mockImplementation instead of mockReset on Jest spy mock. The jest implementation has changed, and mockReset no longer sets an empty mock function on spy mocks.
  • Update the snapshots for the e2e enum tests. A line number in the stack traces has changed.
  • Update the caniuse-lite version. browserlist was writing a 'Browserslist: caniuse-lite is outdated...' message to stderr, which caused parsing of jest output to fail in the e2e transform-js test.
  • Fix the configuration of jest transforms in the examples tests. These configurations previously specified two regex configurations that matched .ts and .tsx files (^.+\\.(ts|tsx)$ and ^.+\\.tsx?$). Only the second one specified the necessary options to ts-jest for ESM and isolated configurations. This only worked because jest stored options per-transform-script and not per-regex. That changed in a recent fix, which broke these tests.

Summary

Test plan

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

  * Use mockImplementation instead of mockReset on Jest spy mock. The jest implementation has changed, and mockReset no longer sets an empty mock function on spy mocks.
  * Update the snapshots for the e2e enum tests. A line number in the stack traces has changed.
  * Update the caniuse-lite version. browserlist was writing a 'Browserslist: caniuse-lite is outdated...' message to stderr, which caused parsing of jest output to fail in the e2e transform-js test.
@richshaffer
Copy link
Contributor Author

Note that I made this PR against the existing renovate/jest-packages branch. If merged into that branch, it should fix the unit tests that are currently failing for #3979. I thought that would be better than losing or trying to reproduce the description included in that MR.

For isolated and esm example tests, the jest config specified multiple transforms to match .ts and .tsx files. This accidentally worked because if multiple regex blocks specified the same preprocessor (e.g., 'ts-jest'), then the last one would clobber the options set by earlier ones. This behavior was recently fixed in jest, which broke these tests.
@richshaffer
Copy link
Contributor Author

Pushed another commit to fix test-examples.

Copy link
Collaborator

@ahnpnl ahnpnl left a comment

Choose a reason for hiding this comment

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

Thanks a lot!

@ahnpnl ahnpnl merged commit 1296190 into kulshekhar:renovate/jest-packages Mar 15, 2023
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

2 participants