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

regenerator 0.13.1 breaks Jest #7579

Closed
mattjohnsonpint opened this issue Jan 4, 2019 · 11 comments
Closed

regenerator 0.13.1 breaks Jest #7579

mattjohnsonpint opened this issue Jan 4, 2019 · 11 comments

Comments

@mattjohnsonpint
Copy link

Tests fail with ReferenceError: regeneratorRuntime is not defined after updating regenerator-runtime to 0.13.1. This is because regeneratorRuntime is no longer a global.

facebook/regenerator#363

Per notes in that issue, we should be using @babel/plugin-transform-runtime now. Jest and its docs need to be updated accordingly. Thanks.

@SimenB
Copy link
Member

SimenB commented Jan 5, 2019

PR most welcome updating the docs.

If there's anything else that needs doing, please follow the issue template

@open-source-explorer
Copy link
Contributor

@SimenB I'm a novice here. Can you guide me?

@SimenB
Copy link
Member

SimenB commented Jan 9, 2019

@open-source-explorer sorry, I don't know what needs doing. 😅 @mj1856 @thymikee?

@thymikee
Copy link
Collaborator

thymikee commented Jan 9, 2019

Based on this comment facebook/regenerator#363 (comment):

See #353. With regenerator-runtime@0.13.x, the global regeneratorRuntime variable is no longer automatically created (unless you evaluate the runtime code in global scope, rather than a Webpack wrapper), but you can import the runtime and define the variable globally yourself.

This is all handled for you if you use @babel/plugin-transform-runtime, by the way. Any file that needs regeneratorRuntime imports it from @babel/runtime/regenerator.

Maybe we don't need to include regenerator-runtime/runtime in setupFiles, but instead add @babel/plugin-transform-runtime inside babel-jest?

@open-source-explorer
Copy link
Contributor

@thymikee I'm not familiar with the jest codebase. It would be great if you could guide me on which files are to be edited 😄

@thymikee
Copy link
Collaborator

I opened #7595 to track that. We also don't mention regenerator-runtime in master docs (for future release) so I'm not sure what should we change in the documentation – just add a mention that it's advised to use @babel/plugin-transform-runtime along with @babel/runtime to support async iterators with Babel instead of regenerator-runtime if you're on Babel7 and Jest 23? 🤔

@DylanVann
Copy link
Contributor

DylanVann commented Jan 24, 2019

If users have a recent node version they can use:

// babel.config.js
module.exports = {
    presets: [
        ['@babel/preset-env', { targets: { node: 'current' } }],
    ],
}

Using @babel/preset-env without that target set will result in the tests using async failing with ReferenceError: regeneratorRuntime is not defined.

If you're using a recent Node version I think that's the best setting for Jest. If you need to support other targets you may need to use something like:

// babel.config.js
// NOTE: If you use this your tests aren't running exactly the same code as your production code.
// They may compile faster and be easier to debug though.
module.exports = process.env.NODE_ENV === 'test' ? {
    presets: [
        ['@babel/preset-env', { targets: { node: 'current' } }],
    ],
} : {
    // Configuration suitable for your targets.
    // Possibly including `@babel/plugin-transform-runtime`.
}

@SimenB
Copy link
Member

SimenB commented Jan 24, 2019

I think we're good here? We've removed special handling of this in Jest 24 (you can test with jest@24.0.0-alpha.13)

@leonardoraele
Copy link

[...] We've removed special handling of this in Jest 24 (you can test with jest@24.0.0-alpha.13)

Hmm Still got this issue using jest@25.1.0 🤔 (Dylan's solution worked fine, though)

@EduardoFLima
Copy link

Hmm Still got this issue using jest@25.1.0 (Dylan's solution worked fine, though)

Same here! (although using jest 24.9.0)

@github-actions
Copy link

This issue 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 May 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

7 participants