When running mocha tests in single node project, I have simply added -r ems to the script test command. This works nicely; ems makes sure I can use es6 modules.
However, our tests are being run by a little bit more sophisticated test runner, and I dont know how to configure it to use ems
Here is the code:
const path = require('path');
const process = require('process');
const Mocha = require('mocha');
const R = require('ramda');
require('./setup/mocha.setup');
const all = require('./all');
const runner = require('./lib/runner');
async function runningMochaHere ({ grep, invert, reporter }) { // eslint-disable-line max-statements
let testCount = 0;
try {
const mocha = new Mocha();
if (grep) {
mocha.reporter(reporter || 'spec');
mocha.grep(grep);
if (invert) mocha.invert();
} else {
mocha.reporter(reporter || 'dot');
mocha.grep(/@slow/).invert();
}
const mochaMainPattern = 'test/mocha.main.js';
const mochaMainList = await all.globbing(mochaMainPattern);
if (mochaMainList.length === 1) {
const mochaMainPath = path.join(process.cwd(), mochaMainList[0]);
require(mochaMainPath);
}
const testFiles = await all.globbing('src/**/*.test.js');
mocha.files.push.apply(mocha.files, testFiles);
const failureCount = await new Promise(resolve => {
const mochaRunner = mocha.run(resolve);
mochaRunner.on(Mocha.Runner.constants.EVENT_TEST_PASS, () => ++testCount);
});
if (failureCount > 0) throw new Error('mocha failed');
return testCount;
} catch (err) {
console.log(err);
throw err;
}
}
When the tests are being run by this code, I get the usual syntax error as I did from es6 modules before I installed ems:
import { Container as AdminDashboard } from '../page/admin/dashboard'; ^ SyntaxError: Unexpected token {
I tried looking at https://mochajs.org/api/mocha, but I can't find anything about adding those kinds of options. Any ideas?