Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
mthaak opened this issue Nov 20, 2022 · 13 comments
Open

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

mthaak opened this issue Nov 20, 2022 · 13 comments

Comments

@mthaak
Copy link

mthaak commented Nov 20, 2022

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
Copy link

yuritoledo commented Feb 27, 2023

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

@Nuxij
Copy link

Nuxij commented May 11, 2023

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

@yuritoledo
Copy link

To give up :(

@cl-fl
Copy link

cl-fl commented May 11, 2023

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

@zjkipping
Copy link
Contributor

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
Copy link

AM1988 commented Jan 12, 2024

Hi there.

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

@kirrg001
Copy link

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
Copy link

kirrg001 commented Feb 6, 2024

@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
Copy link

AM1988 commented Feb 6, 2024

reproducible also when running tests with --parallel flag

@kirrg001
Copy link

kirrg001 commented Feb 6, 2024

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

@skuethe
Copy link

skuethe commented Jul 24, 2024

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
Copy link

chris-strudel commented Jul 25, 2024

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
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants