michaelleeallen / mocha-junit-reporter

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

Cannot read properties of undefined (reading 'testsuite') #178

Open mthaak opened 1 year ago

mthaak commented 1 year ago

I am running mocha-junit-reporter using Cypress. However, sporadically (6 out of 100 times) it fails with this stack-trace:

Cannot read properties of undefined (reading 'testsuite')
TypeError: Cannot read properties of undefined (reading 'testsuite')
    at lastSuite (/home/circleci/.cache/Cypress/10.11.0/Cypress/resources/app/node_modules/mocha-junit-reporter/index.js:217:46)
    at MochaJUnitReporter.<anonymous> (/home/circleci/.cache/Cypress/10.11.0/Cypress/resources/app/node_modules/mocha-junit-reporter/index.js:258:5)
    at Runner.emit (node:events:539:35)
    at Runner.emit (node:domain:475:12)
    at Reporter.emit (/home/circleci/.cache/Cypress/10.11.0/Cypress/resources/app/packages/server/lib/reporter.js:354:46)
    at Object.onMocha (/home/circleci/.cache/Cypress/10.11.0/Cypress/resources/app/packages/server/lib/project-base.js:273:34)
    at Socket.<anonymous> (/home/circleci/.cache/Cypress/10.11.0/Cypress/resources/app/packages/server/lib/socket-base.js:259:40)
    at Socket.emit (node:events:527:28)
    at Socket.emit (node:domain:475:12)
    at Socket.emitUntyped (/home/circleci/.cache/Cypress/10.11.0/Cypress/resources/app/packages/socket/node_modules/socket.io/dist/typed-events.js:69:22)
    at /home/circleci/.cache/Cypress/10.11.0/Cypress/resources/app/packages/socket/node_modules/socket.io/dist/socket.js:428:39
    at processTicksAndRejections (node:internal/process/task_queues:78:11)

While running this command: yarn exec cypress run --component --reporter=junit --reporter-options="mochaFile=/tmp/test-reports/test-output-components.xml,toConsole=true"

yuritoledo commented 1 year ago

@michaelleeallen could you take a look at this? Look at least 5 dudes with this problem :(

Nuxij commented 1 year ago

I have just hit this issue too is there any fix?

yuritoledo commented 1 year ago

To give up :(

cl-fl commented 1 year ago

@Nuxij switching from reporter: 'mocha-junit-reporter' to reporter: 'junit' fixed the issue for me so maybe worth a try? 🤷

zjkipping commented 1 year ago

Switching the reporter isn't a "fix", you are just using an entirely different system... From my side we didn't start experiencing this error until we started adding the [suitName] to the mochaFile output name config. This variable just needs to be escaped if it doesn't exist instead of crashing everything...

AM1988 commented 10 months ago

Hi there.

Still having this issue with "mocha-junit-reporter": "2.2.1", using it together with mocha-multi-reporters.

kirrg001 commented 9 months ago

Same here. The issue comes and goes. Any workarounds?

"node_modules/mocha-junit-reporter": { "version": "2.2.1" "node_modules/mocha-multi-reporters": { "version": "1.5.1",

kirrg001 commented 9 months ago

@clayreimann Hi ✋ How can we help to get this bug fixed? Do you have any guess why this is happening randomly? I can create a pull request.

AM1988 commented 9 months ago

reproducible also when running tests with --parallel flag

kirrg001 commented 9 months ago

I am also experiencing this problem a lot since we run parallel processes.

skuethe commented 3 months ago

I had the same problem and could not figure out why it was failing - there where no other error messages.
After a lot of testing I added a --reporter=list parameter and surprisingly got more output as to what was going on.
In my case a "port already in use" error which was just hidden by mocha before (without the --reporter parameter).

Maybe this helps others to debug further.

chris-strudel commented 3 months ago

I'm getting the same issue. Completely blocked until this is resolved.

my mocha config: 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' } };

Getting this error:

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 noticed that when running mocha in debug:

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: ' ' mocha:runner },

No matter what I change the name of the file to in my config (mochaFile: './test-results/chris-is-silly.xml') the debugger always shows the mochaFile as 'test-results.xml'. No idea if that's related or helpful.

techreagan commented 1 month ago

I had the same problem and could not figure out why it was failing - there where no other error messages. After a lot of testing I added a --reporter=list parameter and surprisingly got more output as to what was going on. In my case a "port already in use" error which was just hidden by mocha before (without the --reporter parameter).

Maybe this helps others to debug further.

This helped, thanks.