Jest: Flag to prevent Jest from using babel.

Created on 26 Feb 2018  路  6Comments  路  Source: facebook/jest

I have a post on stack overflow about having jest ignore the babel config.

I just also upgraded to babel-7 and I am getting issues. I saw this doc about using babel-jest.

Again as I state below, my code runs in node 9 I don't _need_ babel to run my tests, why is jest forcing me to use it?

From StackOverflow:

I am getting this error:

Couldn't find preset "env" relative to directory

I have jest in a package with babel, the babel dependencies are not installed, which is why I am getting this error, but the file I am testing is the source, and with the version of node that I'm running I don't need to compile, I only have babel in the project to ship the code I'm building as a postinstall script on lesser-versions of node then authored.

How can I shut off jest from forcing babel dependencies from being installed?

Now I'm getting

TypeError: Cannot read property 'loose' of undefined (While processing preset: "/Users/thomas/Project/node_modules/@babel/preset-env/lib/index.js")

Most helpful comment

Could I just use this:

{
  "jest": {
    "transform": {}
  }
}

All 6 comments

Jest will use babel anyways - it's how we do coverage.

There are many issues and SO posts containing information on how to turn of the normal transform - please use search.

Is https://github.com/babel/babel-jest going to be migrated to babel 7?

I currently have duplicates :(

{
  "scripts": {
    "test": "jest"
  },
  "babel": {
    "presets": [
      [
        "@babel/preset-env",
        {
          "targets": {
            "node": "current"
          },
          "shippedProposals": true
        }
      ]
    ]
  },
  "devDependencies": {
    "@babel/cli": "^7.0.0-beta.40",
    "@babel/core": "^7.0.0-beta.40",
    "@babel/preset-env": "^7.0.0-beta.40",
    "babel-core": "^7.0.0-bridge.0",
    "babel-jest": "^22.4.1",
    "jest": "^22.4.2"
  }
}

At some point, yes. But not until it's out of beta, I'd say 馃檪

Could I just use this:

{
  "jest": {
    "transform": {}
  }
}

Yes

Could I just use this:

{
  "jest": {
    "transform": {}
  }
}

Thanks. I have playwright e2e tests which used the default jest configuration. However I recently added a vue-jest unit/integration tests which needed babel.

Was this page helpful?
0 / 5 - 0 ratings