jestjs / jest

Delightful JavaScript Testing.
https://jestjs.io
MIT License
44.2k stars 6.46k forks source link

babel-jest configuration is not working #3649

Closed yussinsharp closed 7 years ago

yussinsharp commented 7 years ago

Do you want to request a feature or report a bug?

Bug.

What is the current behavior?

The babel-jest plugin is not being recognized and so running jest fails with

/Users/sharp/carecru/carecru/tests/__tests__/reducers/apiRequests.js:2
    import reducer, {
    ^^^^^^
    SyntaxError: Unexpected token import

      at ScriptTransformer._transformAndBuildScript (node_modules/jest-runtime/build/ScriptTransformer.js:289:17)

If the current behavior is a bug, please provide the steps to reproduce and either a repl.it demo through https://repl.it/languages/jest or a minimal repository on GitHub that we can yarn install and yarn test.

Running npm test with

package.json

{
  "name": "carecru",
  "version": "0.0.0",
  "engines": {
    "node": "~6.10.3",
    "npm": "~3.10.10"
  },
  "private": true,
  "scripts": {
    "test": "jest",
  },
  "dependencies": {
    "async": "0.2.9",
    "attr-accept": "^1.0.3",
    "autoprefixer": "^6.3.1",
    "autoprefixer-core": "5.1.8",
    "axios": "^0.9.1",
    "babel-core": "^6.24.1",
    "babel-eslint": "^7.2.3",
    "babel-loader": "^7.0.0",
    "babel-plugin-syntax-dynamic-import": "^6.18.0",
    "babel-plugin-transform-es2015-modules-commonjs": "^6.24.1",
    "babel-polyfill": "^6.23.0",
    "babel-preset-env": "^1.4.0",
    "babel-preset-react": "^6.24.1",
    "babel-preset-stage-2": "^6.24.1",
    "basic-auth-connect": "^1.0.0",
    "bcrypt": "^0.8.7",
    "body-parser": "^1.14.2",
    "bootstrap": "^4.0.0-alpha.4",
    "bootstrap-loader": "^2.0.0",
    "bootstrap-sass": "^3.3.6",
    "bundle-loader": "^0.5.5",
    "chalk": "^1.1.1",
    "chart.js": "^2.3.0",
    "cheerio": "~0.19.0",
    "classnames": "^2.2.3",
    "cleave.js": "^0.7.15",
    "compression": "^1.6.0",
    "consolidate": "~0.12.1",
    "cookie-parser": "^1.4.1",
    "cors": "^2.8.1",
    "crypto": "0.0.3",
    "crypto-token": "^1.0.1",
    "css-loader": "^0.28.1",
    "csurf": "^1.9.0",
    "dompurify": "^0.8.6",
    "draft-js": "^0.8.0",
    "ejs": "^2.5.2",
    "ejs-loader": "^0.3.0",
    "event-emitter": "^0.3.4",
    "express": "^4.12.3",
    "express-handlebars": "^3.0.0",
    "express-jwt": "^5.1.0",
    "express-session": "^1.13.0",
    "express-session-rethinkdb": "^0.4.1",
    "express-subdomain": "^1.0.5",
    "extract-text-webpack-plugin": "^2.1.0",
    "faker": "^4.1.0",
    "file-loader": "^0.11.1",
    "flexboxgrid": "^6.3.1",
    "font-awesome": "^4.7.0",
    "globalize": "^1.1.2",
    "handlebars": "~4.0.5",
    "helmet": "^1.1.0",
    "history": "^4.6.1",
    "immutability-helper": "^2.0.0",
    "immutable": "^4.0.0-rc.2",
    "imports-loader": "^0.7.1",
    "interval-arithmetic-eval": "^0.4.3",
    "isomorphic-style-loader": "^2.0.0",
    "jsdom": "^7.2.2",
    "jsonwebtoken": "^7.2.1",
    "jwt-decode": "^2.1.0",
    "keycode": "^2.1.6",
    "knox": "^0.9.2",
    "kue": "^0.11.2",
    "lodash": "^4.4.0",
    "logrocket": "^0.4.2",
    "mandrill-api": "^1.0.45",
    "mathjs": "^2.7.0",
    "md5": "^2.2.0",
    "method-override": "^2.3.5",
    "mime": "~1.2.11",
    "moment": "2.17.1",
    "moment-duration-format": "^1.3.0",
    "moment-range": "^3.0.1",
    "multer": "^1.1.0",
    "node-cron": "^1.1.2",
    "node-sass": "^4.5.2",
    "node-uuid": "~1.4.1",
    "nodemon": "^1.11.0",
    "normalize.css": "^5.0.0",
    "normalizr": "^3.1.0",
    "passport": "~0.3.0",
    "passport-http": "^0.3.0",
    "passport-local": "^1.0.0",
    "pluralize": "^1.2.1",
    "postcss-cssnext": "^2.10.0",
    "postcss-loader": "^1.3.3",
    "prop-types": "^15.5.9",
    "raw-loader": "^0.5.1",
    "rc-slider": "^7.0.3",
    "rc-tooltip": "^3.4.2",
    "react": "^15.4.2",
    "react-addons-css-transition-group": "^15.3.2",
    "react-addons-transition-group": "^15.3.2",
    "react-addons-update": "^15.3.1",
    "react-autosuggest": "^9.0.1",
    "react-big-calendar": "^0.11.0",
    "react-bootstrap": "^0.28.5",
    "react-chartjs-2": "^1.5.0",
    "react-click-outside": "^2.2.0",
    "react-color": "^2.2.2",
    "react-css-themr": "^1.3.0",
    "react-day-picker": "^5.2.0",
    "react-dd-menu": "^2.0.0",
    "react-dnd": "^2.1.4",
    "react-dnd-html5-backend": "^2.1.2",
    "react-dom": "^15.3.2",
    "react-dropzone": "^3.5.3",
    "react-event-listener": "^0.2.1",
    "react-flexbox-grid": "^0.10.2",
    "react-height": "^2.1.0",
    "react-hot-loader": "^3.0.0-beta.7",
    "react-immutable-proptypes": "^2.1.0",
    "react-infinite-scroller": "^1.0.6",
    "react-inline-css": "^2.3.0",
    "react-loader": "^2.4.0",
    "react-popover": "^0.4.4",
    "react-portal": "^2.1.0",
    "react-rangeslider": "^2.0.1",
    "react-redux": "^4.4.5",
    "react-redux-custom-store": "^1.0.0",
    "react-router-dom": "^4.1.1",
    "react-router-redux": "^5.0.0-alpha.6",
    "react-select": "^1.0.0-rc.3",
    "react-textarea-autosize": "^4.3.0",
    "react-timeago": "^3.1.2",
    "react-toggle": "^3.0.0",
    "recompose": "^0.20.2",
    "redux": "^3.4.0",
    "redux-actions": "^0.9.1",
    "redux-batch-middleware": "^0.2.0",
    "redux-batched-actions": "^0.1.5",
    "redux-form": "^6.6.3",
    "redux-saga": "^0.11.0",
    "redux-thunk": "^2.0.1",
    "reselect": "^2.5.3",
    "resolve-url-loader": "^2.0.2",
    "rethinkdb": "^2.3.3",
    "rethinkdb-job-queue": "^2.1.0",
    "rimraf": "^2.5.1",
    "s3": "^4.4.0",
    "sass-loader": "^6.0.3",
    "serve-favicon": "^2.3.0",
    "socket.io": "^1.5.1",
    "socket.io-redis": "^4.0.0",
    "socketio-jwt": "^4.5.0",
    "style-loader": "^0.17.0",
    "styled-components": "^1.4.4",
    "supertest": "^2.0.0",
    "thinky": "^2.3.8",
    "twilio": "^2.11.1",
    "uglify-js": "~2.6.0",
    "url-loader": "^0.5.8",
    "uuid": "^2.0.3",
    "webpack": "^2.4.1",
    "webpack-dev-server": "^2.4.5",
    "webpack-merge": "^4.1.0",
    "yargs": "^4.2.0",
    "zxcvbn": "^4.4.2"
  },
  "devDependencies": {
    "@kadira/storybook": "^2.35.3",
    "@kadira/storybook-addon-knobs": "^1.7.1",
    "babel-jest": "^20.0.3",
    "chai": "^3.5.0",
    "eslint": "^3.5.0",
    "eslint-config-airbnb": "^11.1.0",
    "eslint-plugin-import": "^1.15.0",
    "eslint-plugin-jsx-a11y": "^2.2.2",
    "eslint-plugin-react": "^6.2.2",
    "foreman": "^2.0.0",
    "jest": "^20.0.1",
    "material-design-icons": "^2.2.3",
    "mocha": "^3.3.0",
    "nodemon": "^1.10.2",
    "pretty-bytes": "^4.0.2",
    "react-addons-perf": "^15.2.1",
    "sinon": "^1.15.3"
  }
}

.babelrc

{
  "presets": [
    ["env", { "modules": false }],
    "stage-2",
    "react"
  ],
  "plugins": [
    "syntax-dynamic-import",
    "react-hot-loader/babel"
  ]
}

Not pasting the source code as I feel it's irrelevant. It's complaining about the import statement at the top of a certain test file. Hope this information is enough :)

What is the expected behavior?

I am expecting it to properly load my babel config so I can test all of my ES6 code. I am suspecting that it is because of my babel-core packages being installed as dependencies and not devDependencies but that doesn't seem right... (we have that so we can manage builds with postinstalls on NODE_ENV=production environments like Heroku)

yussinsharp commented 7 years ago

And just to be clear ahead of time, I have already re-installed node_modules and ran jest with no-cache.

curioussavage commented 7 years ago

Did you try without "modules": false ?

yussinsharp commented 7 years ago

Yes. Same error.

curioussavage commented 7 years ago

I don't thnk the stage-2 preset covers imports you should use the es2015 preset too.

cpojer commented 7 years ago

This is not a help forum. Try running Jest once with --no-cache and make sure to upgrade to the latest version of Jest.

yussinsharp commented 7 years ago

@curioussavage Thanks!

github-actions[bot] commented 3 years ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.