I have some TypeScript/Axios based web service tests. Running non-parallel the mocha-junit-reporter works correctly. I followed the instructions on the mocha website to get my test suite to run in parallel but I keep getting an error.
I’m using:
"mocha": "^10.4.0",
"mocha-junit-reporter": "^2.2.1",
Here is how my .mocharc.js file is configured:
const mochaConfig = {
spec: ['./Axios/tests/**/*[sS]pec.ts'],
timeout: 6600000,
parallel: true,
jobs: 2,
require: ['tsconfig-paths/register', 'ts-node/register', './tests/mocha-test-hooks.ts'],
reporter: 'mocha-junit-reporter',
reporterOptions: {
mochaFile: './test-results/test-results.[hash].xml',
testsuitesTitle: true,
suiteTitleSeparatedBy: '.'
}
};
My mocha-test-hooks.ts is pretty simple. Nothing crazy going on there:
import 'dotenv/config';
import {apiInstances} from '../data';
export const mochaHooks = {
async beforeAll() {
apiInstances.setupClient();
},
};
My tests kick off and run correctly in parallel. When the test run has completed and the mocha-junit-reporter is trying to put it back together I get this error:
C:UsersjsmithgitmyProjectnode_modulesmocha-junit-reporterindex.js:217
return testsuites[testsuites.length - 1].testsuite;
^
TypeError: Cannot read properties of undefined (reading 'testsuite')
at lastSuite (C:UsersjsmithgitmyProjectnode_modulesmocha-junit-reporterindex.js:217:46)
at MochaJUnitReporter.<anonymous> (C:UsersjsmithgitmyProjectnode_modulesmocha-junit-reporterindex.js:262:5)
at ParallelBufferedRunner.emit (node:events:531:35)
at ParallelBufferedRunner.emit (node:domain:488:12)
at ParallelBufferedRunner.Runner.fail (C:UsersjsmithgitmyProjectnode_modulesmochalibrunner.js:464:8)
at ParallelBufferedRunner.Runner._uncaught (C:UsersjsmithgitmyProjectnode_modulesmochalibrunner.js:994:12)
at C:UsersjsmithgitmyProjectnode_modulesmochalibnodejsparallel-buffered-runner.js:340:18
at Array.forEach (<anonymous>)
at C:UsersjsmithgitmyProjectnode_modulesmochalibnodejsparallel-buffered-runner.js:333:12
at processTicksAndRejections (node:internal/process/task_queues:95:5)
This is my first attempt at running mocha in parallel so maybe I don’t have something configured correctly? Does anyone know how to resolve this issue? I have already scoured the internet to no avail.