Skip to content

Conversation

@nicolo-ribaudo
Copy link
Contributor

@nicolo-ribaudo nicolo-ribaudo commented Jul 28, 2025

Summary

The only remaining blocker for the Babel 8 stable release is to make sure that it works for major Babel consumers. This PR is the first step towards making Jest ready for it. It updates babel-plugin-jest-hoist, babel-preset-jest and babel-jest to support running with Babel 8 in addition to supporting Babel 7.

Test plan

Tests updated to run both with Babel 7 and Babel 8.

Unfortunately, while the Babel plugins/presets maintained in this repo work reasonably well with Babel 8, Babel 8 itself cannot be loaded inside Jest-run tests, because it's written in ESM. Or maybe it's possible, but not the way that Jest is configured in this repo.

As a workaround, I'm loading the Babel 8 ESM packages using Node.js' native require, rather than Jest's sandboxed version.

Most of the diff in tests is indentation changes. I suggest disabling whitespace diff when reviewing.

(fyi @JLHwung @liuxingbaoyu)

@netlify
Copy link

netlify bot commented Jul 28, 2025

Deploy Preview for jestjs failed.

Built without sensitive environment variables

Name Link
🔨 Latest commit 1bc003d
🔍 Latest deploy log https://app.netlify.com/projects/jestjs/deploys/68d8dfae4b20740008972e10

@pkg-pr-new
Copy link

pkg-pr-new bot commented Jul 28, 2025

Open in StackBlitz

babel-jest

npm i https://pkg.pr.new/babel-jest@15750

babel-plugin-jest-hoist

npm i https://pkg.pr.new/babel-plugin-jest-hoist@15750

babel-preset-jest

npm i https://pkg.pr.new/babel-preset-jest@15750

create-jest

npm i https://pkg.pr.new/create-jest@15750

@jest/diff-sequences

npm i https://pkg.pr.new/@jest/diff-sequences@15750

expect

npm i https://pkg.pr.new/expect@15750

@jest/expect-utils

npm i https://pkg.pr.new/@jest/expect-utils@15750

jest

npm i https://pkg.pr.new/jest@15750

jest-changed-files

npm i https://pkg.pr.new/jest-changed-files@15750

jest-circus

npm i https://pkg.pr.new/jest-circus@15750

jest-cli

npm i https://pkg.pr.new/jest-cli@15750

jest-config

npm i https://pkg.pr.new/jest-config@15750

@jest/console

npm i https://pkg.pr.new/@jest/console@15750

@jest/core

npm i https://pkg.pr.new/@jest/core@15750

@jest/create-cache-key-function

npm i https://pkg.pr.new/@jest/create-cache-key-function@15750

jest-diff

npm i https://pkg.pr.new/jest-diff@15750

jest-docblock

npm i https://pkg.pr.new/jest-docblock@15750

jest-each

npm i https://pkg.pr.new/jest-each@15750

@jest/environment

npm i https://pkg.pr.new/@jest/environment@15750

jest-environment-jsdom

npm i https://pkg.pr.new/jest-environment-jsdom@15750

@jest/environment-jsdom-abstract

npm i https://pkg.pr.new/@jest/environment-jsdom-abstract@15750

jest-environment-node

npm i https://pkg.pr.new/jest-environment-node@15750

@jest/expect

npm i https://pkg.pr.new/@jest/expect@15750

@jest/fake-timers

npm i https://pkg.pr.new/@jest/fake-timers@15750

@jest/get-type

npm i https://pkg.pr.new/@jest/get-type@15750

@jest/globals

npm i https://pkg.pr.new/@jest/globals@15750

jest-haste-map

npm i https://pkg.pr.new/jest-haste-map@15750

jest-jasmine2

npm i https://pkg.pr.new/jest-jasmine2@15750

jest-leak-detector

npm i https://pkg.pr.new/jest-leak-detector@15750

jest-matcher-utils

npm i https://pkg.pr.new/jest-matcher-utils@15750

jest-message-util

npm i https://pkg.pr.new/jest-message-util@15750

jest-mock

npm i https://pkg.pr.new/jest-mock@15750

@jest/pattern

npm i https://pkg.pr.new/@jest/pattern@15750

jest-phabricator

npm i https://pkg.pr.new/jest-phabricator@15750

jest-regex-util

npm i https://pkg.pr.new/jest-regex-util@15750

@jest/reporters

npm i https://pkg.pr.new/@jest/reporters@15750

jest-resolve

npm i https://pkg.pr.new/jest-resolve@15750

jest-resolve-dependencies

npm i https://pkg.pr.new/jest-resolve-dependencies@15750

jest-runner

npm i https://pkg.pr.new/jest-runner@15750

jest-runtime

npm i https://pkg.pr.new/jest-runtime@15750

@jest/schemas

npm i https://pkg.pr.new/@jest/schemas@15750

jest-snapshot

npm i https://pkg.pr.new/jest-snapshot@15750

@jest/snapshot-utils

npm i https://pkg.pr.new/@jest/snapshot-utils@15750

@jest/source-map

npm i https://pkg.pr.new/@jest/source-map@15750

@jest/test-result

npm i https://pkg.pr.new/@jest/test-result@15750

@jest/test-sequencer

npm i https://pkg.pr.new/@jest/test-sequencer@15750

@jest/transform

npm i https://pkg.pr.new/@jest/transform@15750

@jest/types

npm i https://pkg.pr.new/@jest/types@15750

jest-util

npm i https://pkg.pr.new/jest-util@15750

jest-validate

npm i https://pkg.pr.new/jest-validate@15750

jest-watcher

npm i https://pkg.pr.new/jest-watcher@15750

jest-worker

npm i https://pkg.pr.new/jest-worker@15750

pretty-format

npm i https://pkg.pr.new/pretty-format@15750

commit: 92a3c81

@nicolo-ribaudo nicolo-ribaudo force-pushed the babel-8-2 branch 2 times, most recently from 501bd08 to 0d9a720 Compare July 28, 2025 16:36
@nicolo-ribaudo nicolo-ribaudo marked this pull request as draft July 30, 2025 13:42
@nicolo-ribaudo nicolo-ribaudo force-pushed the babel-8-2 branch 5 times, most recently from 2e3d659 to be3b812 Compare July 30, 2025 15:18
@nicolo-ribaudo
Copy link
Contributor Author

Ok I give up. @cpojer / @SimenB do you know how to solve that "› 12 obsolete snapshots found" error in Node.js 18, which I assume is due to those tests being skipped in Node.js 18?

@nicolo-ribaudo nicolo-ribaudo marked this pull request as ready for review July 30, 2025 21:14
@cpojer
Copy link
Member

cpojer commented Jul 31, 2025

I assume we'll release this as a major, and we'll drop Node 18 next so don't worry about those.

@nicolo-ribaudo
Copy link
Contributor Author

Oh I was planning to go with this PR first just allowing users to use Babel 8, and then a separate one (major) upgrading the whole repo to it. I'll do the whole upgrade immediately then.

In:
- babel-plugin-jest-hoist
- babel-preset-jest
- babel-jest
@cpojer
Copy link
Member

cpojer commented Aug 27, 2025

@nicolo-ribaudo sorry I was away for a month. Just to confirm, with this PR Babel 7 or 8 can be used with Jest, and this is not a breaking change, is that correct?

@nicolo-ribaudo
Copy link
Contributor Author

Correct! I can also open a PR with the breaking change next week of you prefer.

@cpojer
Copy link
Member

cpojer commented Aug 28, 2025

Got it! We can discuss the breaking changes in the other PR then and figure out what's the right time to merge that.

I see some test failures related to this change on CI: "TypeError: Cannot read properties of null (reading 'transformSync')".

@nicolo-ribaudo
Copy link
Contributor Author

@cpojer I'm struggling a bit with the CI failure. Babel 8 does not support Node.js 18, so I'm using describe.skip for its tests in Node.js 18. However, this means that the tests are skipped, so the snapshots are unused, and so CI is failing due to unused snapshots.

@nicolo-ribaudo
Copy link
Contributor Author

Ok maybe I found a (ugly) workaround.

@SimenB
Copy link
Member

SimenB commented Sep 5, 2025

@nicolo-ribaudo sorry, I've ignored all OSS for a long time 😅

We have a onNodeVersion (ish spelling) helper for skipping tests on certain node versions

@SimenB
Copy link
Member

SimenB commented Sep 5, 2025

export function onNodeVersions(
versionRange: string,
testBody: () => void,
): void {

This 🙂

@nicolo-ribaudo
Copy link
Contributor Author

Thanks, updated! Unfortunately I think I still need the workaround for the babel-plugin-jest-hoist tests, because snapshots in .skipped tests don't work (Jest wants me to remove the snapshot, as it's unused).

@SimenB
Copy link
Member

SimenB commented Sep 5, 2025

Hmm, that helper should fix that as it'll mark the snapshots as skipped rathe than unused 🤔

@cpojer
Copy link
Member

cpojer commented Sep 10, 2025

Ok, just checking in here to help move this over the line.

Is this understanding correct:

  • Babel 8 only works with Node 20+
  • Jest 30 still supports Node 18
  • I'm happy to drop Node 18 for Jest 31

If we merge this PR, Jest 30 with Babel 7 will still keep working in Node 18, right?

I can figure out the test skipping for Node 18, but I still see tests fail on all versions of Node, so let's fix that and then I'll take over.

@nicolo-ribaudo
Copy link
Contributor Author

Yes, right!

Sorry I've had limited time for this, I'll get CI green today :)

@nicolo-ribaudo
Copy link
Contributor Author

nicolo-ribaudo commented Sep 12, 2025

Jest really dislikes conditionally skipping tests that contain snapshots (also when using onNodeVersion, because internally it's just a describe.skip). I'm going to re-add the two separate files for Node.js 18 and Node.js 20+ so that it doesn't load the unused snapshot for 18.

@nicolo-ribaudo
Copy link
Contributor Author

Ping? :)

@cpojer
Copy link
Member

cpojer commented Sep 26, 2025

Oh apologies, I thought it was still in progress last time I checked. I'll get to it by Monday.

Copy link
Member

@cpojer cpojer left a comment

Choose a reason for hiding this comment

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

Thank you for doing this 🙇‍♂️

@cpojer cpojer merged commit d2a2491 into jestjs:main Sep 28, 2025
1 of 9 checks passed
@cpojer
Copy link
Member

cpojer commented Sep 28, 2025

@nicolo-ribaudo this was released in Jest 30.2.0.

@nicolo-ribaudo nicolo-ribaudo deleted the babel-8-2 branch September 28, 2025 08:02
@nicolo-ribaudo
Copy link
Contributor Author

Thank you! I'll now open a PR switching all of Jest packages to Babel 8.

It will be a breaking change, and also feel free to wait until Babel 8 is stable to release it, but I need to make sure that everything works before the stable release :)

@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 29, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants