The easiest way to run Mocha tests written in ES6 is compiling them on-the-fly using Mocha --require @babel/register
option (see https://github.com/mochajs/mocha/wiki/compilers-deprecation#what-should-i-use-instead-then). Of course, you need to make sure to install the corresponding modules and set up the .babelrc
accordingly
package.json:
"dependencies": {
"@babel/cli": "^7.7.4",
"@babel/core": "^7.7.4",
"@babel/preset-env": "^7.7.4",
"@babel/register": "^7.7.4",
...
}
.babelrc:
{
"presets": [
[
"@babel/preset-env"
]
]
}
See also https://dev.to/bnorbertjs/my-nodejs-setup-mocha–chai-babel7-es6-43ei