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

Change babel-core to peerDependency for compatibility with Babel 7 #4162

Merged
merged 2 commits into from
Aug 5, 2017
Merged

Change babel-core to peerDependency for compatibility with Babel 7 #4162

merged 2 commits into from
Aug 5, 2017

Conversation

bradchristensen
Copy link
Contributor

@bradchristensen bradchristensen commented Jul 31, 2017

Summary

This makes babel-jest compatible with whichever version of Babel is used in a given project, since babel-core@6 is not necessarily compatible with plugins made for Babel 7.

Note that this is a breaking change (albeit low impact).

Fixes #4055 (babel-jest is incompatible with plugins made for Babel 7).

Test plan

In a project using jest@20.0.4 and the following Babel packages:

"babel-cli": "^7.0.0-alpha.15",
"babel-core": "^7.0.0-alpha.15",
"babel-eslint": "^8.0.0-alpha.15",
"babel-loader": "^7.1.1",
"babel-plugin-dynamic-import-node": "^1.0.2",
"babel-plugin-syntax-dynamic-import": "^7.0.0-alpha.15",
"babel-plugin-transform-class-properties": "^7.0.0-alpha.15",
"babel-plugin-transform-object-rest-spread": "^7.0.0-alpha.15",

Install babel-jest using:

npm install babel-jest --save-dev

I run tests using a .jestrc.js config file (however the extra config can be omitted for this example):

jest --config .jestrc.js

The command fails with errors such as the following (indicating that JSX has not been transformed by Babel):

image

I published this fork of babel-jest as an npm package and installed it in the project as follows (public so that anyone can reproduce this):

npm uninstall babel-jest --save-dev
npm install @ubiquios/babel-jest --save-dev

Then modified the jest transform configuration to use it (instead of babel-jest which is default):

.jestrc.js

module.exports = {
    ...

    transform: {
        '^.+\\.jsx?$': '@ubiquios/babel-jest',
    },
};

Then run the tests again using jest --config .jestrc.js and see that all is well:

image

Note that although this is technically a breaking change, in general users should already have babel-core installed with their project, so I would expect impact to be minimal.

Also note that I've run the unit tests on my own (Windows) machine and they all pass, including at least some that fail in the CI runs. From what I can see, these tests seem to have been failing in CI already prior to this commit.

This makes babel-jest compatible with whichever version of Babel is
used in a given project, since babel-core@6 is not necessarily
compatible with plugins made for Babel 7.

Note that this is a breaking change (albeit low impact).
@facebook-github-bot
Copy link
Contributor

Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need the corporate CLA signed.

If you have received this in error or have any questions, please contact us at cla@fb.com. Thanks!

@facebook-github-bot
Copy link
Contributor

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

@cpojer
Copy link
Member

cpojer commented Jul 31, 2017

Seems like this at least breaks Circle

@bradchristensen
Copy link
Contributor Author

Ah I think I see why this is a problem now. The tests worked on my machine because I had misguidedly deleted the node_modules folder from the babel-jest package, which caused it to rely on the packages installed at the root. I assume that removing babel-core@7 as a devDependency would fix the issue for the other tests in this repository that rely on 6, since they all reference the babel-jest directory where 7 is installed, containing the devDependency that conflicts with Babel installed elsewhere. My goal with this was to at least prove that Babel 7 worked but since there are no tests specific to babel-jest, this doesn't make sense anyway 😅

In any case though, do you agree with the general idea of changing this to a peerDependency?

@cpojer
Copy link
Member

cpojer commented Jul 31, 2017

Yeah, I think that's reasonable.

@hzoo
Copy link

hzoo commented Aug 7, 2017

We've done this in babel-loader for a while https://github.com/babel/babel-loader/blob/f0bbb68ad484b5211926dafb57f25fd418d06dc4/package.json#L18

Might need to do the same if we release beta/rc 😛

tushardhole pushed a commit to tushardhole/jest that referenced this pull request Aug 21, 2017
…estjs#4162)

* Change babel-core to peerDependency for compatibility with Babel 7

This makes babel-jest compatible with whichever version of Babel is
used in a given project, since babel-core@6 is not necessarily
compatible with plugins made for Babel 7.

Note that this is a breaking change (albeit low impact).

* Revert babel-core upgrade to 7.x
@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 May 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

babel-jest is incompatible with plugins made for Babel 7
4 participants