apexcharts / react-apexcharts

📊 React Component for ApexCharts
https://apexcharts.com
MIT License
1.31k stars 158 forks source link

Failing Jest test #27

Closed youssef-md closed 5 years ago

youssef-md commented 5 years ago

🐛 Bug Report

react-apexcharts in the version 1.1.0 is failing the Jest tests

To Reproduce

$ npm i react-apexcharts@1.1.0

Expected behavior

Is expected to fail all tests of the components that are related directly or not with the component that is importing Chart from react-apexcharts, even using enzyme's shallow, for an isolated component rendering for testing.

FAIL
 ● Test suite failed to run
<test_path>/node_modules/react-apexcharts/dist/react-apexcharts.min.js:1

    ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import ApexCharts from"apexcharts";import React,{Component}from"react";import PropTypes from"prop-types";var _extends=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var s in r)Object.prototype.hasOwnProperty.call(r,s)&&(t[s]=r[s])}return t};function _objectWithoutProperties(t,e){var r={};for(var s in t)e.indexOf(s)>=0||Object.prototype.hasOwnProperty.call(t,s)&&(r[s]=t[s]);return r}class Charts extends Component{constructor(t){super(t),React.createRef?this.chartRef=React.createRef():this.setRef=(t=>this.chartRef=t),this.chart=null}render(){const t=_objectWithoutProperties(this.props,["type","width","height","series","options"]);return React.createElement("div",_extends({ref:React.createRef?this.chartRef:this.setRef},t))}componentDidMount(){const t=React.createRef?this.

    SyntaxError: Unexpected token import

@RochaCarla

bernardofd commented 5 years ago

This seems to be the exact same error I got, and it seems that it was caused by the new build tool that changed in v1.1.0. The dist file broke my app (which uses Meteor + Webpack) because the minified version uses import and failed with an Uncaught SyntaxError: Unexpected identifier error when trying to load apexcharts.

So far I've downgraded this library to version v1.0.10 to make things work again, but spent a lot of time tracking this issue down. If I'm able, I may try to change the main setting in the package.json file to the iife version to see if this issue is fixed (at least in my build system).

Shouldn't it be the default version, @junedchhipa?

junedchhipa commented 5 years ago

I will compare what are the differences in the new build file and the previous build file. iife version was created for users who want to inject React-Apexcharts directly into browser.

As the new bundle is causing issues, I will revert back to the previous build system (gulp) for default imports if things don't work out in the new rollup plugin.

junedchhipa commented 5 years ago

After trying different build configs in rollup, I eventually reverted to gulp for the primary bundle file.

Let me know if v.1.2.0 fixes these issues