For a side project I'm working on, I decided to try out ECMAScript (ES) Modules, because the latest versions of Node now support them and the latest browsers do too. Sadly, I quickly discovered that my favorite testing framework, Jest, requires a bit of configuration to work with them and the support is experimental. As such, this post is mostly a reminder to my future self in case I need to do this again, but possibly others may find it useful.
I made the following changes and/or additions to package.json and jest.config.mjs:
package.json
"scripts": {
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js"
},
jest.config.mjs
testEnvironment: "jest-environment-node",
transform: {},
Those were the only changes I needed to make to successfully test ES Modules with Jest 27, Node 14, and Windows 10.
Top comments (0)