mercredi 16 août 2017

SyntaxError: Unexpected token

I am trying to configure my application for testing. I am using jest. However, I get an error when I run my test. It looks like path to my AboutDialog component is failing to transpile.

   zach@zach-VirtualBox:~/Documents/Code/fcc-for-good/meeting-for-good$ npm run test

> meeting-for-good@1.0.12 test /home/zach/Documents/Code/fcc-for-good/meeting-for-good
> cross-env NODE_ENV=test jest

 FAIL  __tests__/test.js
  ● Test suite failed to run

    /home/zach/Documents/Code/fcc-for-good/meeting-for-good/client/components/AboutDialog/about-dialog.css:1
    ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){.AboutDialog {
                                                                                             ^

    SyntaxError: Unexpected token .

      at ScriptTransformer._transformAndBuildScript (node_modules/jest-runtime/build/ScriptTransformer.js:289:17)
      at Object.<anonymous> (client/components/AboutDialog/AboutDialog.js:7:20)
      at Object.<anonymous> (__tests__/test.js:2:20)

Test Suites: 1 failed, 1 total
Tests:       0 total
Snapshots:   0 total
Time:        8.204s
Ran all test suites.

I am trying to import my AboutDialog component to my test.

import React from 'react';
import Dialog from 'material-ui/Dialog';
import FlatButton from 'material-ui/FlatButton';
import cssModules from 'react-css-modules';

import PropTypes from 'prop-types';
import styles from './about-dialog.css';

const inlineStyles = {
  modal: { content: { width: '630px', maxWidth: '630px' }, bodyStyle: { paddingTop: 10, fontSize: '25px' } },
};

const AboutDialog = (props) => {
  const { cbOpenModal, openModal } = props;
  const actions = [
    <FlatButton label="close" primary onTouchTap={() => cbOpenModal()} />,
  ];
  return (
    <Dialog
      contentStyle={inlineStyles.modal.content}
      bodyStyle={inlineStyles.modal.bodyStyle}
      actions={actions}
      modal
      styleName="AboutDialog"
      open={openModal}
    >
      <h1 styleName="titleStyle">Meeting for Good</h1>
      <h6 styleName="versionStyle">Version {process.env.versionNumber}</h6>
      <h4 styleName="descStyle">THE BEST MEETING COORDINATION APP</h4>
      <h6>Created by campers from <a href="http://ift.tt/1EODLCw">FreeCodeCamp</a></h6>
      <h6><a href="http://ift.tt/2r4IQaI"> License and GitHub Repository</a></h6>
    </Dialog>
  );
};

AboutDialog.propTypes = {
  cbOpenModal: PropTypes.func.isRequired,
  openModal: PropTypes.bool.isRequired,
};

export default cssModules(AboutDialog, styles);

My test. If I remove the AboutDialog import from my test , the test suite runs.

    import React from 'react';
    import AboutDialog from '../client/components/AboutDialog/AboutDialog';
    import { shallow } from 'enzyme';

    describe('Test', () => {
        it('should test', () => {  

      });

});

My .babelrc file.

    {
  "presets": ["react", "es2015", "stage-1"],
  "plugins": [
    "transform-decorators-legacy",
    "react-hot-loader/babel",
    ["transform-runtime", { "polyfill": false, "regenerator": true }]
  ],
  "env": {
    "development": {
      "presets": [
        "react-hmre"
      ]
    }
  }  
}

My package.json

{
  "name": "meeting-for-good",
  "version": "1.0.12",
  "description": "Schedule events with ease!",
  "homepage": "http://ift.tt/2wb5XD0",
  "main": "index.js",
  "scripts": {
    "clean": "rimraf build",
    "build:server": "babel -d ./build ./server -s",
    "build:client": "cross-env NODE_ENV=production babel-node ./tools/build.js",
    "build": "npm run clean && npm run copy && npm run build:server && npm run build:client",
    "start": " node ./build/app.js",
    "copy": "node tools/copy.js",
    "serve": "npm run clean && npm run copy && npm run build:server && npm run dev",
    "dev": "cross-env NODE_ENV=development node -r dotenv/config ./build/app.js",
    "test": "cross-env NODE_ENV=test jest",
    "heroku-postbuild": "npm run build",
    "postinstall": "node tools/postInstall.js"
  },
  "repository": {
    "type": "git",
    "url": "git+http://ift.tt/2x55m1S"
  },
  "author": "Jean Philip de Rogatis <jrogatis@rogatis.eti.br>",
  "contributors": [
    {
      "name": "Aniruddh Agarwal",
      "email": "aaniruddh99@gmail.com"
    },
    {
      "name": "Bob Sutton",
      "email": "anischyros@gmail.com"
    }
  ],
  "license": "MIT",
  "bugs": {
    "url": "http://ift.tt/2wbmI0u"
  },
  "engines": {
    "node": "^8.0.0",
    "npm": "^5.0.0"
  },
  "dependencies": {
    "autobind-decorator": "^2.1.0",
    "babel-cli": "^6.22.2",
    "babel-core": "^6.22.1",
    "babel-eslint": "^7.2.1",
    "babel-loader": "^7.1.1",
    "babel-plugin-react-transform": "^2.0.2",
    "babel-plugin-transform-decorators-legacy": "^1.3.4",
    "babel-plugin-transform-runtime": "^6.22.0",
    "babel-preset-es2015": "^6.22.0",
    "babel-preset-react": "^6.22.0",
    "babel-preset-react-hmre": "^1.1.1",
    "babel-preset-stage-1": "^6.22.0",
    "babel-runtime": "^6.25.0",
    "bluebird": "^3.5.0",
    "body-parser": "^1.17.2",
    "chai": "^4.1.0",
    "chalk": "^2.0.1",
    "chroma-js": "^1.3.3",
    "chunk-manifest-webpack2-plugin": "^1.0.1",
    "clipboard": "^1.6.1",
    "compression": "^1.7.0",
    "connect-flash": "^0.1.1",
    "connect-mongo": "^1.3.2",
    "cookie-parser": "^1.4.3",
    "copy-webpack-plugin": "^4.0.1",
    "cpy-cli": "^1.0.1",
    "cross-env": "^5.0.1",
    "css-loader": "^0.28.1",
    "cssnano": "^3.10.0",
    "dialog-polyfill": "^0.4.6",
    "dotenv": "^4.0.0",
    "ejs": "^2.5.5",
    "email-templates": "^2.5.6",
    "es6-promise": "^4.1.1",
    "express": "^4.15.3",
    "express-session": "^1.15.4",
    "express-sessions": "^1.0.6",
    "extract-text-webpack-plugin": "^2.1.0",
    "fast-json-patch": "^2.0.4",
    "favicons-webpack-plugin": "0.0.7",
    "file-loader": "^0.11.1",
    "google-calendar": "^1.3.2",
    "html-loader": "^0.4.4",
    "html-webpack-plugin": "^2.29.0",
    "image-webpack-loader": "^3.3.1",
    "immutable": "^3.8.1",
    "isomorphic-fetch": "^2.2.1",
    "jstimezonedetect": "^1.0.6",
    "lodash": "^4.17.2",
    "material-ui": "^0.18.5",
    "mocha": "^3.4.2",
    "moment": "^2.18.1",
    "moment-range": "^3.0.3",
    "mongoose": "^4.11.3",
    "morgan": "^1.8.2",
    "nodemailer": "^4.0.1",
    "nodemailer-ses-transport": "^1.5.0",
    "nprogress": "^0.2.0",
    "offline-plugin": "^4.8.3",
    "opbeat": "^4.14.2",
    "optimize-css-assets-webpack-plugin": "^2.0.0",
    "passport": "^0.3.2",
    "passport-facebook": "^2.1.1",
    "passport-google-oauth": "^1.0.0",
    "passport-oauth2-refresh": "^1.0.0",
    "pngquant-bin": "^3.1.1",
    "prop-types": "^15.5.10",
    "react": "^15.6.0",
    "react-addons-update": "^15.5.2",
    "react-css-modules": "^4.3.0",
    "react-day-picker": "^5.5.1",
    "react-dom": "^15.6.0",
    "react-ga": "^2.2.0",
    "react-hot-loader": "^3.0.0-beta.7",
    "react-infinite": "^0.11.0",
    "react-input-range": "^1.2.1",
    "react-masonry-component": "^5.0.3",
    "react-moment-proptypes": "^1.4.0",
    "react-notification-system": "^0.2.14",
    "react-router": "^3.0.2",
    "react-tap-event-plugin": "^2.0.1",
    "react-tooltip": "^3.3.0",
    "react-transform-hmr": "^1.0.4",
    "request": "^2.81.0",
    "rimraf": "^2.6.1",
    "shelljs": "^0.7.7",
    "style-loader": "^0.18.1",
    "url-loader": "^0.5.7",
    "webpack": "^2.7.0",
    "webpack-assets-manifest": "^0.7.0",
    "webpack-bundle-analyzer": "^2.8.3",
    "webpack-config": "^7.0.0",
    "write-file-webpack-plugin": "^4.0.0",
    "yargs": "^8.0.1"
  },
  "devDependencies": {
    "babel-jest": "^20.0.3",
    "babel-preset-jest": "^20.0.3",
    "enzyme": "^2.9.1",
    "eslint": "^3.19.0",
    "eslint-config-airbnb": "^15.0.0",
    "eslint-friendly-formatter": "^3.0.0",
    "eslint-loader": "^1.8.0",
    "eslint-plugin-import": "^2.7.0",
    "eslint-plugin-jsx-a11y": "^5.1.0",
    "eslint-plugin-react": "^7.0.1",
    "jest": "^20.0.4",
    "jest-css-modules": "^1.1.0",
    "react-dom": "^15.6.1",
    "react-test-renderer": "^15.6.1",
    "regenerator-runtime": "^0.10.5",
    "webpack-dev-middleware": "^1.11.0",
    "webpack-dev-server": "^2.5.1",
    "webpack-hot-middleware": "^2.18.2"
  },
  "jest": {
    "transform": {
      ".*": "<rootDir>/node_modules/babel-jest"
    }
  }
}

Aucun commentaire:

Enregistrer un commentaire