I am using a fairly basic site setup with react-create-app and then importing as the documentation suggests:
import * as am4core from '@amcharts/amcharts4/core'
There is no problem at all whilst using the charts, however when I run them in the test environment they fail with the below error.
Details:
/var/www/management/node/node_modules/@amcharts/amcharts4/core.js:8
export { System, system } from "./.internal/core/System";
^^^^^^
SyntaxError: Unexpected token 'export'
2 | import React from 'react'
3 | import PropTypes from 'prop-types'
> 4 | import * as am4core from '@amcharts/amcharts4/core'
| ^
5 | import * as am4maps from '@amcharts/amcharts4/maps'
6 | import am4geodata_worldLow from '@amcharts/amcharts4-geodata/worldLow'
7 |
at ScriptTransformer._transformAndBuildScript (node_modules/@jest/transform/build/ScriptTransformer.js:537:17)
at ScriptTransformer.transform (node_modules/@jest/transform/build/ScriptTransformer.js:579:25)
at Object.<anonymous> (src/digitalAssetManager/Overview/components/ProvenanceChart/index.js:4:1)
Versions
- amcharts4: v4.8.1
- react-scripts: v3.3.0
ProvenanceChart/index.js
/* eslint-disable no-unused-vars */
import React from 'react'
import * as am4core from '@amcharts/amcharts4/core'
import * as am4maps from '@amcharts/amcharts4/maps'
import am4geodata_worldLow from '@amcharts/amcharts4-geodata/worldLow'
import am4themes_animated from '@amcharts/amcharts4/themes/animated'
import { theme } from 'config/theme'
am4core.useTheme(am4themes_animated)
class ProvenanceChart extends React.Component {
I do not believe I am doing anything outwardly different from a standard stack.
Test in question:
it('should render', () => {
expect(renderer.create(getComponent()).toJSON()).toMatchSnapshot()
})
Project jest.config.js
module.exports = {
"roots": [
"<rootDir>/node/src"
],
"moduleFileExtensions": [
"js",
"jsx",
"json",
"node"
],
"verbose": true,
"testEnvironment": 'node',
"testURL": 'http://localhost:3000',
"setupFiles": ["jest-canvas-mock"],
"setupTestFrameworkScriptFile": "<rootDir>/src/setupTests.js"
//// setup file
//import { configure } from 'enzyme';
//import 'jest-canvas-mock';
//import Adapter from 'enzyme-adapter-react-16';
//configure({ adapter: new Adapter() });
}
Then finally ran with npm test