babel-preset-es2015-rollup icon indicating copy to clipboard operation
babel-preset-es2015-rollup copied to clipboard

Does not work with Jest

Open drewloomer opened this issue 8 years ago • 3 comments

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.

drewloomer avatar Jan 05 '17 01:01 drewloomer

Also interested in a real solution for this

brettstack avatar Apr 03 '17 15:04 brettstack

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"
  }

atkinchris avatar May 09 '17 20:05 atkinchris

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.

wangzuo avatar Jun 02 '17 15:06 wangzuo