Supported technologies: ES modules

Note that if you are using Babel or TypeScript and are compiling your ES modules to CommonJs, then the documentation section below is not relevant to you.

Wallaby supports native ECMAScript Modules in relevant versions of node.js, if your testing framework supports them.

Jest

Jest supports ES modules, however the support is still in its early stages. Jest also uses the vm API (https://nodejs.org/api/vm.html) and currently the ESM parts of this API is still flagged in node (--experimental-vm-modules).

To run automatically configured Jest with Wallaby and ES modules, you will either need to add wallaby section that sets the required node flag to your package.json file:

package.json

{
  ...
  "wallaby": {
    "autoDetect": true,
    "env": {
      "params": {
        "runner": "--experimental-vm-modules"
      }
    }
  }
}

or to create and use a small wallaby.js configuration file:

wallaby.js

export default function () {
  return {
    autoDetect: true,
    env: {
      params: {
        runner: '--experimental-vm-modules'
      }
    }
  };
};

Note that the config file has to be ES module if your package.json has the "type": "module" setting.

If you are using Jest with manual configuration file, you will need to add the above described env.params.runner setting to your wallaby config file.

Mocha

Mocha supports ES modules, however watch does not support ES module test files, so Wallaby needs to be configured to reflect the limitation and to restart its worker processes between test runs:

module.exports = function () {
  return {
    files: [
      'package.json',   // IMPORTANT
      ...
    ],

    tests: [
      ...
    ],

    env: {
      type: 'node'
    },

    workers: { restart: true }  // IMPORTANT
  };
};