I am adding another ES6 + mocha + babel setup answer here, current as of June 19 (see Dates in the answer / comments). --compiler flag is --compiler , and the version I use is not available even with the --no-deprecation flag, see this
Please note that I will not include all relevant snippets from the linked pages, because none of them led me to a clean test build based on the latest versions of mocha and babel; this answer should include the steps that led me to a successful test build.
Following the instructions here, and in this answer , and here , I tried to install what turned out to be the minimum latest version using npm install :
$ npm install --save-dev mocha $ npm install --save-dev @babel/preset-env
And I configured the mocha call in package.json like this:
"scripts": { "test": "mocha --compilers js:@babel/register" }
This led to errors:
× ERROR: --compilers is DEPRECATED and no longer supported.
As above, --no-deprecation did not help, please follow the link above. So, following the instructions from here, I configured package.json:
"scripts": { "test": "mocha --require js:@babel/register" }
And he began to see errors when looking for babel modules, such as:
× ERROR: Cannot find module '@babel/register'
At this point, I started installing babel packages until I was able to progress. I believe the full installation is something like:
$ npm install --save-dev @babel/preset-env @babel/register @babel/core
The latest change was to update the mocha call in package.json by removing the js: prefix js: something like this:
"scripts": { "test": "mocha --require @babel/register" }
I can’t answer why it was necessary: if someone can answer this question, please leave a comment and I will supplement my answer with more detailed information.
The last thing I did was create .babelrc in the project directory with the contents:
{"presets": ["@ babel / preset-env"]}
I can’t remember what this caused, but I believe it was because Mocha kept complaining that he did not recognize the import keyword in my test.js. As above, if someone can answer this question, please leave a comment and I will update my answer with more details.