1

All tests are running absolutely fine with jest for React component from command line. But the moment I run the test using WebStorm (i.e. run as) I am getting following errors.

Test suite failed to run

({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){var _extends=Object.assign||function(a){for(var b,c=1;c<arguments.length;c++)for(var d in b=arguments[c],b)Object.prototype.hasOwnProperty.call(b,d)&&(a[d]=b[d]);return a};function _objectWithoutProperties(a,b){var c={};for(var d in a)0<=b.indexOf(d)||Object.prototype.hasOwnProperty.call(a,d)&&(c[d]=a[d]);return c}import React,{Component}from'react';import PropTypes from'prop-types';import cx from'classnames';import style from'./input.css';export default class Input extends Component{static get NORMAL(){return'normal'}static get UNDERLINE(){return'underline'}render(){const a=this.props,{className:b,inputStyle:c}=a,d=_objectWithoutProperties(a,['className','inputStyle']),e=cx([`body-small pad-05r`],{[`bdr-rad4 ${style.defInp}`]:c===Input.NORMAL,[`text-center ${style.bottomBdr}`]:c===Inpu

SyntaxError: Unexpected token import

  at ScriptTransformer._transformAndBuildScript (node_modules/jest-runtime/build/ScriptTransformer.js:289:17)
  at Object.<anonymous> (src/components/input/index.jsx:3:14)
  at Object.<anonymous> (src/components/input/__tests__/input.test.js:3:14)

Kindly help

LazyOne
  • 158,824
  • 45
  • 388
  • 391
mmeraj
  • 11
  • 2
  • must be a configuration issue. See https://stackoverflow.com/questions/41725796/jest-test-suite-failed-to-run-syntaxerror-unexpected-token-import for some hints. If this doesn't help, please share a sample project that can be used to recreate it – lena Feb 26 '18 at 10:09
  • Thanks LazyOne, the above mentioned did not solve my problem. As I early mentioned The problem I see only incase if I run the test with Webstorm (run as) , but work fine when I execute with cli. The problem is coming only in case of @import css inside css – mmeraj Mar 20 '18 at 09:13
  • Just found the issue, while running jest test we need to provide .jest.config.json explicitly in the webstorm jest configuration, by default it does not pick .jest.config.json. please follow the link to configure jest in webstorm https://www.jetbrains.com/help/webstorm/jest.html – mmeraj Mar 20 '18 at 09:54

1 Answers1

0

Sorry for delay answer. Finally I found the solution. The problem was webstorm was not able to identity default .jest.config.json. I have passed .jest.config.json as jest option param --config .jest.config.json

qiAlex
  • 4,290
  • 2
  • 19
  • 35
mmeraj
  • 11
  • 2