Jest: Jest fails when not using Babel

Created on 3 Oct 2016  ·  3Comments  ·  Source: facebook/jest

Even the simplest project, as described in the _Getting Started_ guide now fails.

Create the sample project (sum.js and sum.spec.js) and then try to run Jest, it fails with Couldn't find preset "es2015" relative to directory "/Users/ianp/Projects". Or check out this gist: https://gist.github.com/0e44151b16718ebc83bb25efb68a9395 .

In the debug configuration (below) I can see that it is setting usesBabelJest to true, although I'm not sure why that should be the base as I'm not using Babel in my project. I've tried adding usesBabelTest: false to package.json but that made no difference. I can also see that the preset seems to be null in the configuration, which seems odd given the error message 🤔

jest version = 16.0.0
test framework = jasmine2
config = {
  "rootDir": "/Users/ianp/Projects/0e44151b16718ebc83bb25efb68a9395",
  "name": "-Users-ianp-Projects-0e44151b16718ebc83bb25efb68a9395",
  "setupFiles": [],
  "testRunner": "/Users/ianp/Projects/0e44151b16718ebc83bb25efb68a9395/node_modules/jest-jasmine2/build/index.js",
  "scriptPreprocessor": "/Users/ianp/Projects/0e44151b16718ebc83bb25efb68a9395/node_modules/babel-jest/build/index.js",
  "usesBabelJest": true,
  "automock": false,
  "bail": false,
  "browser": false,
  "cacheDirectory": "/var/folders/5p/qfkdcjcj343gnxdn0cy8_6l40000gn/T/jest",
  "clearMocks": false,
  "coveragePathIgnorePatterns": [
    "/node_modules/"
  ],
  "coverageReporters": [
    "json",
    "text",
    "lcov",
    "clover"
  ],
  "globals": {},
  "haste": {
    "providesModuleNodeModules": []
  },
  "mocksPattern": "__mocks__",
  "moduleDirectories": [
    "node_modules"
  ],
  "moduleFileExtensions": [
    "js",
    "json",
    "jsx",
    "node"
  ],
  "moduleNameMapper": {},
  "modulePathIgnorePatterns": [],
  "noStackTrace": false,
  "notify": false,
  "preset": null,
  "preprocessorIgnorePatterns": [
    "/node_modules/"
  ],
  "resetModules": false,
  "testEnvironment": "jest-environment-jsdom",
  "testPathDirs": [
    "/Users/ianp/Projects/0e44151b16718ebc83bb25efb68a9395"
  ],
  "testPathIgnorePatterns": [
    "/node_modules/"
  ],
  "testRegex": "(/__tests__/.*|\\.(test|spec))\\.jsx?$",
  "testURL": "about:blank",
  "timers": "real",
  "useStderr": false,
  "verbose": null,
  "watch": false,
  "cache": true,
  "watchman": true,
  "testcheckOptions": {
    "times": 100,
    "maxSize": 200
  }
}

Most helpful comment

The preset must be coming from a .babelrc somewhere in your tree. If it's there, Jest will currently automatically use it.

All 3 comments

The preset must be coming from a .babelrc somewhere in your tree. If it's there, Jest will currently automatically use it.

To fix:

  • Remove .babelrc
  • Install the ES2015 preset

Doh! there was a .babelrc file in a parent directory, not sure how that got there 😖

Thanks for the hint!

Was this page helpful?
0 / 5 - 0 ratings