-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
Only in coverage mode, latest babel: 'import' and 'export' may appear only with 'sourceType: "module"' #6053
Comments
I upgraded to latest packages (I do this once a week) and my tests stopped working too, but not only in coverage mode.
and
My // Babel configuration
// https://babeljs.io/docs/usage/api/
module.exports = {
presets: [
[
'@babel/preset-env',
{
targets: {
node: 'current',
},
},
],
['@babel/preset-stage-2', { decoratorsLegacy: true }],
'@babel/preset-flow',
'@babel/preset-react',
],
// ignore: ['node_modules', 'build'],
env: {
test: {
presets: [
// A Babel preset that can automatically determine the Babel plugins and polyfills
// https://github.com/babel/babel-preset-env
[
'@babel/preset-env',
{
targets: {
node: 'current',
},
modules: 'commonjs',
useBuiltIns: false,
debug: false,
},
],
// Experimental ECMAScript proposals
// https://babeljs.io/docs/plugins/#presets-stage-x-experimental-presets-
['@babel/preset-stage-2', { decoratorsLegacy: true }],
// Flow
// https://github.com/babel/babel/tree/master/packages/babel-preset-flow
'@babel/preset-flow',
// JSX
// https://github.com/babel/babel/tree/master/packages/babel-preset-react
'@babel/preset-react',
],
plugins: [
'transform-es2015-modules-commonjs',
'babel-plugin-dynamic-import-node',
],
},
},
}; |
Does it happen with |
It worked with |
Forgot to mention it worked with beta.44, but not since beta.46 too. |
I discovered that breakage is between babel |
This isn't a bug in Jest, babel did something. Not sure if we need to track it here? |
If babel guys (@hzoo, …) think that they are doing well, jest must take an action… so it's tightly connected. |
Is there a repository or branch somewhere I can test with? I can figure out what's changed. |
Got the same problem. Renaming |
Babel
In most monorepos, that means that a config at the root will be ignored, and configs in sub-packages will also. To have a config at the root of your monorepo, you should name the file
in the programmatic options. For people compiling If your config doesn't fall into one of those changes, then there could always still be a bug somewhere. |
Thanks for the detailed explanation @loganfsmyth! |
Also if it's helpful, here's the PR in Babel for this change babel/babel#7784 |
@SimenB does |
For cache-busting purposes, we should. But I don't think it's needed to work. Are you still having issues? If so, please setup a reproduction. |
See relevant discussion jestjs/jest#6053 (comment)
* Upgrade JS dependencies A few patch changes added in here as a patch change in prettier was actually a breaking change :/ so I thought I'd do the lot * Fix issue with new babel not compiling panda-session See relevant discussion jestjs/jest#6053 (comment)
@loganfsmyth Does If so, is there a way to use Should I remove the Just tested, the config is indeed merged. Also, I think its really bad to merge the configs. We should favor composition over inheritance. I.e. If you need the top-level config you should explicitly require it from your local At present there seems no easy way to use a babel configuration for all packages, and then override on a per-package basis. You are forced to add a
|
Might be best to continue this discussion in Babel's Slack or something to avoid pinging everyone on this issue, but here's my thoughts, assuming I understand what you're asking.
Yes, we perform merging, with
The goal of the
We merge because merging is already a necessary feature in order to support
I don't follow what you mean here. Why would you have to add a |
I only learned about |
Due to a change in Babel 7 that affects resolution of babel configs[1] (`.babelrc` is now a hierarchical config, while `babel.config.js` is not), source files outside of the source root of jest will not be transpiled. That means, plugins running tests were not able to require/import source files of core. With this change, `.babelrc` will be renamed to `babel.config.js`, so it is still used when a plugin imports a file from core. [1]: jestjs/jest#6053 (comment)
* Bumping package versions to Babel 7 and required dependency versions. * Adapting preset/plugin names. * Using correct import scope for Spinner in OutputList. * Fixing Jest for Babel 7 in Plugins. Due to a change in Babel 7 that affects resolution of babel configs[1] (`.babelrc` is now a hierarchical config, while `babel.config.js` is not), source files outside of the source root of jest will not be transpiled. That means, plugins running tests were not able to require/import source files of core. With this change, `.babelrc` will be renamed to `babel.config.js`, so it is still used when a plugin imports a file from core. [1]: jestjs/jest#6053 (comment) * Generating cjs modules to enable default-less requires of modules. * Updating yarn.lock.
anybody has an example of lerna using jest with babelrcRoots? |
@vikr01 I'd like an example like this one https://github.com/paularmstrong/jest-multi-project-example one jest.config.js in the root that have the packages option, and then each package has it's own jest.config.js config I'm trying to fix this in this boilerplate/playground: https://github.com/entria/entria-fullstack, but jest is not transpiling tests inside packages, neither when using babelrcRoots |
I also had this issue, try doing it this way: https://babeljs.io/docs/en/config-files#jest So, dont put |
Following jestjs/jest#6053 (comment) Otherwise, cozy-ui files were not properly transformed during tests
is there an example repo? |
- Setup an error boundry component based on [React Documentation](https://reactjs.org/docs/error-boundaries.html) - Renamed `.babelrc` to `.babel.config.js` based on [GitHub issues](jestjs/jest#6053 (comment)) - Added `babel-plugin-dynamic-import-node` because of Jest errors regarding `import` syntax - Added `react-dom` to devDependencies as it's used in `@testing-library/jest-dom`
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. |
Do you want to request a feature or report a bug?
Bug
What is the current behavior?
Since updating to Babel 7.0-beta.46, Jest fails only when using
--coverage
with this error:If the current behavior is a bug, please provide the steps to reproduce and
either a repl.it demo through https://repl.it/languages/jest or a minimal
repository on GitHub that we can
yarn install
andyarn test
.Couldn't manage to reproduce it in a minimal environment (yet). Still working on it.
What is the expected behavior?
Jest should work the same with or without
--coverage
Please provide your exact Jest configuration
Run
npx envinfo --preset jest
in your project directory and paste theresults here
The text was updated successfully, but these errors were encountered: