Can someone please help me to fix this error I get when I am running
npm run test
Error –
FAIL src/client/AdaptiveCardsDesigner/AdaptiveCardsDesigner.test.js
● Test suite failed to run
Jest encountered an unexpected token
This usually means that you are trying to import a file which Jest cannot parse, e.g. it's not plain JavaScript.
By default, if Jest sees a Babel config, it will use that to transform your files, ignoring "node_modules".
Here's what you can do:
• If you are trying to use ECMAScript Modules, see https://jestjs.io/docs/en/ecmascript-modules for how to enable it.
• To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config.
• If you need a custom transformation specify a "transform" option in your config.
• If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config option.
You'll find more details and examples of these config options in the docs:
https://jestjs.io/docs/en/configuration.html
Details:
/Users/node_modules/swiper/swiper.esm.js:13
export { default as Swiper, default } from './core/core.js';
^^^^^^
SyntaxError: Unexpected token 'export'
at Runtime.createScriptFromCode (node_modules/jest-runtime/build/index.js:1350:14)
at Object.<anonymous> (node_modules/adaptivecards/src/carousel.ts:26:1)
FAIL src/client/AdaptiveCardsDesigner/container.test.js
● Test suite failed to run
Jest encountered an unexpected token
This usually means that you are trying to import a file which Jest cannot parse, e.g. it's not plain JavaScript.
By default, if Jest sees a Babel config, it will use that to transform your files, ignoring "node_modules".
Here's what you can do:
• If you are trying to use ECMAScript Modules, see https://jestjs.io/docs/en/ecmascript-modules for how to enable it.
• To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config.
• If you need a custom transformation specify a "transform" option in your config.
• If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config option.
You'll find more details and examples of these config options in the docs:
https://jestjs.io/docs/en/configuration.html
Details:
/Users/node_modules/swiper/swiper.esm.js:13
export { default as Swiper, default } from './core/core.js';
^^^^^^
SyntaxError: Unexpected token 'export'
at Runtime.createScriptFromCode (node_modules/jest-runtime/build/index.js:1350:14)
at Object.<anonymous> (node_modules/adaptivecards/src/carousel.ts:26:1)
Test Suites: 2 failed, 1 passed, 3 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: 1.441 s
Ran all test suites matching /src/client/AdaptiveCardsDesigner/i.
My package.json file with –
“moduleNameMapper”: {
“.(jpg|jpeg|png|svg|gif|mp4)$”: “/mocks/fileMock.js”,
“^.+.(css|scss)$”: “/node_modules/identity-obj-proxy”,
“monaco-editor”: “/node_modules/react-monaco-editor”
},
I also tried to add transformIgnorePatterns
as suggested in error,
but error is not going,
"transformIgnorePatterns": [
"node_modules/adaptivecards"
]
My jest config –
"jest": {
"testURL": "",
"setupFiles": [
"./.jest/requestAnimationFrameShim.js",
"./.jest/jestsetup.js",
"jest-localstorage-mock"
],
"roots": [
"<rootDir>/src/server/libs",
"<rootDir>/src/client",
"<rootDir>/__mocks__"
],
"verbose": true,
"collectCoverageFrom": [
"**/src/client/**/*.{js,jsx}",
"!**/node_modules/**"
],
"coverageDirectory": "coverage/client",
"coverageThreshold": {
"global": {
"statements": 99.36,
"branches": 99.87,
"functions": 99.22,
"lines": 99.33
}
},
"globals": {
"__DEVELOPMENT__": false,
"__DEVTOOLS__": false,
"__CLIENT__": true,
"__SERVER__": false,
"__INITIAL_STATE__": {}
},
"moduleNameMapper": {
"\.(jpg|jpeg|png|svg|gif|mp4)$": "<rootDir>/__mocks__/fileMock.js",
"^.+\.(css|scss)$": "<rootDir>/node_modules/identity-obj-proxy",
"monaco-editor": "<rootDir>/node_modules/react-monaco-editor"
},
"snapshotSerializers": [
"enzyme-to-json/serializer",
"jest-serializer-html"
]
},
Can someone help ?