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

Bumping @babel/preset-env from 7.12.1 to 7.12.7 breaks tests (jest) #12393

Closed
1 task
wachunei opened this issue Nov 24, 2020 · 8 comments
Closed
1 task

Bumping @babel/preset-env from 7.12.1 to 7.12.7 breaks tests (jest) #12393

wachunei opened this issue Nov 24, 2020 · 8 comments
Labels
i: question outdated A closed issue/PR that is archived due to age. Recommended to make a new issue

Comments

@wachunei
Copy link

Bug Report

  • I would like to work on a fix!

Current behavior

Bumping @babel/preset-env from 7.12.1 to 7.12.7 breaks tests

Nullish coalescing and optional chaining operator are not parsed anymore.

Input Code

Example:

const getElement = container => container?.firstChild;

Expected behavior

To transform correctly

Babel Configuration (babel.config.js, .babelrc, package.json#babel, cli command, .eslintrc)

  • Filename: package.json#babel
  "babel": {
    "presets": [
      "@babel/preset-env",
      [
        "@babel/preset-react",
        {
          "runtime": "automatic"
        }
      ]
    ]
  }

Environment

  System:
    OS: macOS 11.0.1
  Binaries:
    Node: 12.19.0 - ~/.nvm/versions/node/v12.19.0/bin/node
    Yarn: 1.22.10 - /usr/local/bin/yarn
    npm: 6.14.8 - ~/.nvm/versions/node/v12.19.0/bin/npm
  npmPackages:
    @babel/core: ^7.12.8 => 7.12.8
    @babel/preset-env: ^7.12.7 => 7.12.7
    @babel/preset-react: ^7.12.7 => 7.12.7
    babel-jest: ^26.6.3 => 26.6.3
    eslint: ^7.14.0 => 7.14.0
    jest: ^26.6.3 => 26.6.3

Possible Solution

  • Maybe enabling these features is required in the babel config but I would not expect that since it works before bumping patch version.
  • Maybe babel-jest is ignoring babel config

Additional context

@babel-bot
Copy link
Collaborator

Hey @wachunei! We really appreciate you taking the time to report an issue. The collaborators on this project attempt to help as many people as possible, but we're a limited number of volunteers, so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack community that typically always has someone willing to help. You can sign-up here for an invite."

@nicolo-ribaudo
Copy link
Member

This should be fixed by #12391!
I'm trying to write a proper test case, hopefully we'll release it by today.

@wachunei
Copy link
Author

This should be fixed by #12391!
I'm trying to write a proper test case, hopefully we'll release it by today.

Hello @nicolo-ribaudo, sounds good, can we leave this open until release, bump and test pass? I can take care of closing it once that happens (hopefully 🤞)

@nicolo-ribaudo
Copy link
Member

Sure!

@JLHwung
Copy link
Contributor

JLHwung commented Nov 24, 2020

I don't think it is related to #12391.

The test in wachunei/directUC#162 fails because Babel does not transpile ?? and ?. given that the the target browsers

https://github.com/wachunei/directUC/blob/d3fe4c06cc940acef0c691d24cc34d5c0afabf95/package.json#L115-L120

have native ?? and ?. support, but the Jest tests is run on Node.js 12 https://github.com/wachunei/directUC/blob/develop/.github/workflows/checks.yml#L11 which doesn't.

You can either specify a different preset-env targets for Jest tests, or run tests on Node.js 14 which has native support.

@wachunei
Copy link
Author

wachunei commented Nov 24, 2020

That totally makes sense, but how is it explained that it worked before then?

Edit: How can I add { targets: { node: true } } to preset-env options when process.env.NODE_ENV is test, but using package.json#babel config?

@JLHwung
Copy link
Contributor

JLHwung commented Nov 24, 2020

but how is it explained that it worked before then?

Because what last N versions resolves to is determined by caniuse-lite, which is indirectly bumped in #12241.

How can I add { targets: { node: true } } to preset-env options when process.env.NODE_ENV is test, but using package.json#babel config?

You can create a .browserslistrc on your project root

[production]
last 5 Chrome versions
# and other targets

[test]
current node

@wachunei
Copy link
Author

I did not use environment keys in my package.json@browserslist config because it was not being picked up correctly by parcel@v1. I resolved to upgrade to use node 14 for development. Thank you for the help.

@github-actions github-actions bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Feb 24, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 24, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
i: question outdated A closed issue/PR that is archived due to age. Recommended to make a new issue
Projects
None yet
Development

No branches or pull requests

4 participants