-
-
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
add example using babel 7 #6983
Conversation
Hey nice idea 👍 But why not keep it simple and remove Also I don't understand why jest is not working smoothly with babel 7, it used to be so simple. Can you add an explanation? Like what exactly is Thanks PS: Related to #6982 |
Small remark: Also for readability thinks like |
Fair enough. The typescript example will change with #6949, so I can remove that part
You can read through #4557, which lead to the creation of that module 🙂
Very good feedback, thank you! Will do 🙂 |
de1c20d
to
65f01e2
Compare
@yvele the example is quite a bit slimmer now, any other comments? |
@SimenB Looks pretty straightforward 👍 |
That's cool! But I think it would be nice to make an explicit note that when you want to transpile node_modules, you likely need to use babel.config.js instead of .babelrc. Plus a link to Babel configuration docs maybe |
in the docs, or readme of the example? |
In the docs, folks are not looking up examples that often. |
65f01e2
to
d6e712c
Compare
done |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍Would be cool to include it in all versioned docs, as some are missing
@@ -91,6 +91,10 @@ yarn add --dev babel-jest babel-core regenerator-runtime | |||
> ```bash | |||
> yarn add --dev babel-jest babel-core@^7.0.0-bridge.0 @babel/core regenerator-runtime | |||
> ``` | |||
> | |||
> You will need to use babel.config.js in order to transpile `node_modules`. See https://babeljs.io/docs/en/next/config-files for more information. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we wrap babel.config.js
with backticks for visibility?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done!
Nope, not every version has that document. See the netlify deployment - every versioned doc includes this 🙂 |
Missed that! I was redirected to Jest website from deploy preview while using search XD |
@SimenB In my case Jest only uses Babel if a create a file with the name: .babel.config.js . If i create a file with the name: babel.config.js it doesn't work. It is supposed to work like that? Here is my package.json: {
"name": "learn-jest",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "jest"
},
"author": "",
"license": "ISC",
"devDependencies": {
"@babel/core": "^7.1.2",
"@babel/preset-env": "^7.1.0",
"babel-core": "^7.0.0-bridge.0",
"babel-jest": "^23.6.0",
"jest": "^23.6.0",
"regenerator-runtime": "^0.12.1"
},
"babel": {
"presets": [
"./.babel.config.js"
]
}
} And here is my .babel.config.js: const isTest = String(process.env.NODE_ENV) === "test";
module.exports = function() {
return {
presets: [
[
"@babel/preset-env",
{
modules: isTest ? "commonjs" : false
}
]
]
};
}; when i run npm run test it only works if i'm using .babel.config.js instead of babel.config.js |
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. |
Summary
A lot of people are struggling with running Babel 7 using Jest. This adds a minimal example (all you have to do is install the bridge package for
babel-core
, but it doesn't seem like stating that in the docs is enough).For fun, I added the typescript preset as well as just module transformation.
Closes #6913.
Test plan
Green CI.