michaelleeallen / mocha-junit-reporter

A JUnit XML reporter for mocha.
MIT License
144 stars 153 forks source link

Uncaught TypeError: Cannot read properties of undefined (reading 'length') #205

Open Pverma96 opened 6 months ago

Pverma96 commented 6 months ago

i am using mocha-multi-reporters in my mocha tests and generating mochawesome and mocha-junit-reports. When using --parallel flag, mocha-junit-reporter throws error:

Uncaught error outside test suite: Uncaught TypeError: Cannot read properties of undefined (reading 'length') at isInvalidSuite (node_modules/mocha-junit-reporter/index.js:155:62) at MochaJUnitReporter._onSuiteBegin (node_modules/mocha-junit-reporter/index.js:232:10) at MochaJUnitReporter. (node_modules/mocha-junit-reporter/index.js:239:17) at ParallelBufferedRunner.emit (node:events:530:35) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async Promise.allSettled (index 0)

command used to run the tests is:

./node_modules/mocha/bin/mocha.js --config .mocharc.cjs --parallel --reporter mocha-multi-reporters --reporter-options configFile=reporter-config.json --require mochawesome/register --exit test/*/.spec.js

below is the reporter config file:

{ "reporterEnabled": "mochawesome, mocha-junit-reporter", "mochawesomeReporterOptions": { "reportDir": "results/mochawesome", "overwrite": false, "html": true, "json": true, "toConsole": true, "consoleReporter": "spec" }, "mochaJunitReporterReporterOptions": { "mochaFile": "results/junit/test-results.xml"

}

noticed that if i remove "--require mochawesome/register" flag, i get same error as defined in #178

Version: "mochawesome": "^7.1.3", "mocha-junit-reporter": "2.2.0", "mocha-multi-reporters": "^1.5.1" "mocha": "^10.4.0",

chris-strudel commented 4 months ago

I'm trying to run tests in parallel as well and getting the a similar issue:

C:\Users\jsmith\git\myProject\node_modules\mocha-junit-reporter\index.js:217 return testsuites[testsuites.length - 1].testsuite; ^ TypeError: Cannot read properties of undefined (reading 'testsuite') at lastSuite (C:\Users\jsmith\git\myProject\node_modules\mocha-junit-reporter\index.js:217:46) at MochaJUnitReporter. (C:\Users\jsmith\git\myProject\node_modules\mocha-junit-reporter\index.js:262:5) at ParallelBufferedRunner.emit (node:events:531:35) at ParallelBufferedRunner.emit (node:domain:488:12) at ParallelBufferedRunner.Runner.fail (C:\Users\jsmith\git\myProject\node_modules\mocha\lib\runner.js:464:8) at ParallelBufferedRunner.Runner._uncaught (C:\Users\jsmith\git\myProject\node_modules\mocha\lib\runner.js:994:12) at C:\Users\jsmith\git\myProject\node_modules\mocha\lib\nodejs\parallel-buffered-runner.js:340:18 at Array.forEach () at C:\Users\jsmith\git\myProject\node_modules\mocha\lib\nodejs\parallel-buffered-runner.js:333:12 at processTicksAndRejections (node:internal/process/task_queues:95:5)

I followed the documentation and set up my mocha config as follows:

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' } };

After running in debug I noticed, and maybe I'm wrong, but the mochaFile name is never changed.

mocha:runner reporterOptions: { mocha:runner '[object Object]': true, mocha:runner mochaFile: 'test-results.xml', <------------------ mocha:runner attachments: false, mocha:runner antMode: false, mocha:runner jenkinsMode: false, mocha:runner properties: null, mocha:runner toConsole: false, mocha:runner rootSuiteTitle: 'Root Suite', mocha:runner testsuitesTitle: 'Mocha Tests', mocha:runner suiteTitleSeparatedBy: ' '

I tried updating my mocha config and changing the name to something random but the debugger always shows the mochaFile as 'test-results.xml'. I don't know that this is the issue but this is what I found.

I'm completely blocked. Has anyone figured this out?