babel-preset-es2015-rollup
babel-preset-es2015-rollup copied to clipboard
Does not work with Jest
Not sure if this is a babel-preset-es2015-rollup bug or a babel-jest bug, but I wanted to log it to get a conversation started and hopefully help someone else who is hung up on this.
Basically, when using Jest to run your tests, this preset doesn't convert import statements (and maybe more ES2016 features) so the Jest test suite fails.
I couldn't figure out how to pass an alternate set of presets to Jest, so I did this:
.babelrc
{
"presets": ["react", "es2015", "stage-0", "stage-3"],
"plugins": ["transform-flow-strip-types"]
}
rollup.config.js
...
babel({
exclude: 'node_modules/**',
babelrc: false,
presets: ['react', 'es2015-rollup', 'stage-0', 'stage-3'],
plugins: ['transform-flow-strip-types']
}),
...
I will do some more digging to figure out exactly where this is breaking down, but I'm curious if anyone else has seen this issue.
Also interested in a real solution for this
This article, using Babel's env options, worked perfectly for me. https://www.josephearl.co.uk/post/jest-import-rollup-babel/
{
"ignore": [
"node_modules/**"
],
"env": {
"development": {
"presets": [
"es2015"
]
},
"production": {
"presets": [
["es2015", { "modules": false }]
],
"plugins": [
"external-helpers"
]
}
}
}
"scripts": {
"test": "NODE_ENV=development jest",
"build": "NODE_ENV=production rollup -c"
}
jest set NODE_ENV=test by default, so
{
"env": {
"test": {
"presets": [
"env"
],
"plugins": [
"transform-runtime"
]
},
"development": {
"presets": [
["env", { "modules": false }]
],
"plugins": [
"transform-runtime"
]
}
}
}
with
"scripts": {
"build": "rollup -c",
"test": "jest"
}
should work.