lundi 31 octobre 2016

jest unexpected reserved word import

I've seen plenty of other people with this issue and I've tried the fixes for them, but I can't seem to see why mine isn't working. I've followed the redux test page instructions and the babel Jest getting started page.

My app runs perfectly fine, but I get this error when trying to test it with Jest:

/home/ansah/Projects/amrit/webapp/src/server/server.js:6
import express  from 'express';
^^^^^^

SyntaxError: Unexpected reserved word

It seems that it needs transpiling first, which I do with babel when actually running the app. But it doesn't seem to work with testing. I added a .babelrc:

{
  "presets": [
    "es2015",
    "react"
  ]
}

Here's my package.json

{
  "name": "null",
  "version": "1.0.0",
  "description": "null",
  "repository": "none",
  "scripts": {
    "build": "browserify src/client/scripts/*.jsx -d -o src/client/app.js",
    "test": "npm run test-back && npm run test-front",
    "test:watch": "npm test -- --watch",
    "test-front": "jest",
    "test-back": "mocha"
  },
  "browserify": {
    "transform": [
      "babelify"
    ]
  },
  "babel": {
    "presets": [
      "es2015",
      "react"
    ]
  },
  "jest": {
    "scriptPreprocessor": "./node_modules/babel-jest",
    "testFileExtensions": ["es6", "js"],
    "moduleFileExtensions": ["js", "json", "es6"]
  },
  "dependencies": {
    "body-parser": "^1.15.2",
    "crypto": "0.0.3",
    "express": "^4.14.0",
    "jquery": "^3.0.0",
    "json-fs-store": "^1.0.0",
    "mkdirp": "^0.5.1",
    "moment": "^2.14.1",
    "path": "^0.12.7",
    "react": "^15.1.0",
    "react-dom": "^15.1.0",
    "react-modal": "^1.4.0",
    "react-redux": "^4.4.5",
    "redux": "^3.6.0",
    "request": "^2.72.0",
    "shelljs": "^0.7.0",
    "solr-client": "^0.6.0",
    "winston": "^2.2.0"
  },
  "devDependencies": {
    "babel-jest": "^13.2.2",
    "babel-preset-es2015": "^6.5.0",
    "babel-preset-react": "^6.5.0",
    "babelify": "^7.2.0",
    "browserify": "^13.0.0",
    "chai": "^3.5.0",
    "chai-http": "^3.0.0",
    "eslint": "^2.1.0",
    "eslint-plugin-react": "^3.16.1",
    "jake": "^8.0.12",
    "jest": "^16.0.2",
    "jest-cli": "^13.0.0",
    "jsdom": "^9.2.1",
    "json-fs-store": "^1.0.0",
    "mocha": "^2.5.3",
    "mocha-jsdom": "^1.1.0",
    "react-addons-test-utils": "^15.2.0",
    "shortid": "^2.2.6",
    "sinon": "^1.17.4"
  }
}

Which also has the ES2015 presets in it under 'babel'.

My server.js is in this format:

(function() {
    "use strict";

    // Express
    const express = require('express');
    const app = express();
    const path = require('path');
    ...

    app.use('/', express.static(path.join(__dirname, '../client')));
    app.get('/search', require('./routes/search.js'));
    ...

    module.exports = app;

}());

Thanks for any help

Aucun commentaire:

Enregistrer un commentaire