Here are the steps I took to run Jest with a test using ESM. The source files under test were also written using ESM.
-
Set my node version to 14.16.0
-
Install Jest:
npm i jest -D -
Add
"type": "module"topackage.json -
Update
testscript inpackage.json:"scripts": { "test": "node --experimental-vm-modules ./node_modules/.bin/jest" } -
Create a
jest.config.jsfile with the following content:export default { transform: {} } -
Have at least one test that could be found using the default
testMatch(mine was inside__tests__dir) -
Run tests:
npm test
There is a more complete example in the magic-comments-loader repository on GitHub.