DEV Community

Olen Daelhousen
Olen Daelhousen

Posted on

Setup to Test ES Modules with Jest 27.4.5 and Node 14.16.0 on Windows

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"
  },
Enter fullscreen mode Exit fullscreen mode

jest.config.mjs

  testEnvironment: "jest-environment-node",
  transform: {},
Enter fullscreen mode Exit fullscreen mode

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)