Skip to content

Commit bacab7b

Browse files
committed
chore: transform our tests from ESM to CJS to make them understandable by Jest
Previously, tests that use "import" were failing: [ERROR] ● Test suite failed to run [ERROR] [ERROR] Jest encountered an unexpected token [ERROR] [ERROR] This usually means that you are trying to import a file which Jest cannot parse, e.g. it's not plain JavaScript. [ERROR] [ERROR] By default, if Jest sees a Babel config, it will use that to transform your files, ignoring "node_modules". [ERROR] [ERROR] Here's what you can do: [ERROR] • If you are trying to use ECMAScript Modules, see https://jestjs.io/docs/en/ecmascript-modules for how to enable it. [ERROR] • To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config. [ERROR] • If you need a custom transformation specify a "transform" option in your config. [ERROR] • If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config option. [ERROR] [ERROR] You'll find more details and examples of these config options in the docs: [ERROR] https://jestjs.io/docs/en/configuration.html [ERROR] [ERROR] Details: [ERROR] [ERROR] /Users/coder/git/mystamps/src/main/frontend/src/components/AddCommentForm.test.js:1 [ERROR] ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import { render, screen } from '@testing-library/react'; [ERROR] ^ [ERROR] [ERROR] SyntaxError: Unexpected token { [ERROR] [ERROR] at Runtime.createScriptFromCode (node_modules/jest-runtime/build/index.js:1350:14) See also: https://github.com/ActuallyACat/jest-esm-transformer Part of #1484
1 parent 2b547d9 commit bacab7b

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

src/main/frontend/jest.config.js

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
module.exports = {
33
// https://jestjs.io/docs/en/configuration#watchman-boolean
44
"watchman": false,
5+
// required to use ECMAScript Modules (ESM)
6+
// @todo #1484 Find a better way to use ESM with Jest and replace jest-esm-transformer
7+
"transform": {
8+
"\\.js$": "jest-esm-transformer"
9+
},
510
// See: https://github.com/facebook/jest/issues/5064#issuecomment-401451361
611
// @todo #1484 Remove usage of jest-standard-reporter once facebook/jest#5064 is resolved
712
"reporters": [ "jest-standard-reporter" ]

src/main/frontend/package-lock.json

+10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main/frontend/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"babel-jest": "~26.6.3",
3838
"babel-loader": "~8.1.0",
3939
"jest": "~26.6.3",
40+
"jest-esm-transformer": "~1.0.0",
4041
"jest-standard-reporter": "~2.0.0",
4142
"react": "~16.8.6",
4243
"react-dom": "~16.8.6",

0 commit comments

Comments
 (0)