Open lassegit opened 2 years ago
I too noticed with latest versions from 12.1.5 to 12.2.5 that jest is not picking up babel config
It works without createJestConfig()
I can confirm the problem. Related to formatjs/formatjs#3789. I believe it's something related to how Jest transform is set up using the SWC compiler.
I created the following code sandbox: https://codesandbox.io/s/admiring-currying-0phokz
I am not using Next.js but encountered this problem. I wound up upgrading all @babel
packages (including babel-jest
& babel-plugin-formatjs
), but only after I upgraded to jest 29 did the issue go away.
For the jest.config.js file in the original issue description:
I found that with Next.js 13.1.0, changing the "transform" line to
"^.+\\.(js|jsx|ts|tsx|mjs)$": ["babel-jest", { presets: ["next/babel"] }],
allowed Babel + plugins to work in my Jest tests. Note, specifically, that the key includes the "mjs" file suffix. This works because the key now matches the one provided by next/js and overrides it, switching the transformer from SWC to Babel.
Verify canary release
Provide environment information
What browser are you using? (if relevant)
No response
How are you deploying your application? (if relevant)
No response
Describe the Bug
Trying to add the babel-plugin-formatjs plugin to Jest testing environment. It automatically injects hash generated IDs for translations. This works on
12.1.0
but with newer releases I only get non-specific error message when I runyarn test
:My configuration:
.babelrc:
jest.config.js:
jest.setup.js:
Installed dependencies:
I am unsure which direction to look in. Has Next changed how it load Jest configuration/Babel plugins?
Expected Behavior
It should load the
babel-plugin-formatjs
as previously.To Reproduce
Install the package and run
yarn test
: