cypress: "TypeError: testcase.testcase[0]._attr.time.toFixed is not a function" error happens often in CI pipeline
Current behavior
Getting below errors when running Cypress tests in CircleCI. This issues happens randomly, not able to reproduce on local environment.
TypeError: testcase.testcase[0]._attr.time.toFixed is not a function
at /home/circleci/.cache/Cypress/8.4.1/Cypress/resources/app/packages/server/node_modules/mocha-junit-reporter/index.js:411:73
at Array.forEach (<anonymous>:null:null)
at /home/circleci/.cache/Cypress/8.4.1/Cypress/resources/app/packages/server/node_modules/mocha-junit-reporter/index.js:405:12
at Array.forEach (<anonymous>:null:null)
at MochaJUnitReporter.getXml (/home/circleci/.cache/Cypress/8.4.1/Cypress/resources/app/packages/server/node_modules/mocha-junit-reporter/index.js:392:14)
at MochaJUnitReporter.flush (/home/circleci/.cache/Cypress/8.4.1/Cypress/resources/app/packages/server/node_modules/mocha-junit-reporter/index.js:370:20)
at MochaJUnitReporter.<anonymous> (/home/circleci/.cache/Cypress/8.4.1/Cypress/resources/app/packages/server/node_modules/mocha-junit-reporter/index.js:247:10)
at Runner.emit (events.js:315:20)
at Reporter.emit (/home/circleci/.cache/Cypress/8.4.1/Cypress/resources/app/packages/server/lib/reporter.js:333:46)
at ProjectBase.<anonymous> (/home/circleci/.cache/Cypress/8.4.1/Cypress/resources/app/packages/server/lib/project-base.js:455:34)
at Generator.next (<anonymous>:null:null)
at /home/circleci/.cache/Cypress/8.4.1/Cypress/resources/app/packages/server/node_modules/tslib/tslib.js:117:75
at new Promise (<anonymous>:null:null)
at Object.__awaiter (/home/circleci/.cache/Cypress/8.4.1/Cypress/resources/app/packages/server/node_modules/tslib/tslib.js:113:16)
at Object.onMocha (/home/circleci/.cache/Cypress/8.4.1/Cypress/resources/app/packages/server/lib/project-base.js:448:51)
at Socket.<anonymous> (/home/circleci/.cache/Cypress/8.4.1/Cypress/resources/app/packages/server/lib/socket-base.js:213:40)
at Socket.emit (events.js:315:20)
at Socket.emitUntyped (/home/circleci/.cache/Cypress/8.4.1/Cypress/resources/app/packages/socket/node_modules/socket.io/dist/typed-events.js:69:22)
at /home/circleci/.cache/Cypress/8.4.1/Cypress/resources/app/packages/socket/node_modules/socket.io/dist/socket.js:428:39
at processTicksAndRejections (internal/process/task_queues.js:75:11)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Exited with code exit status 1
CircleCI received exit code 1
Desired behavior
Cypress test run should be either pass or fail.
Test code to reproduce
Test code are saved in private repo, not able to share with Cypress team.
Cypress Version
8.4.1
Other
No response
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 5
- Comments: 32 (11 by maintainers)
@troygibb this should be included in next week’s release. Thanks @halfninja for getting this into the reporter!
Can not express how annoying this is, especially for repos with tests that take long to run just to fail like this.
Happens both on
8.3and9.1versionsAlright, builds are ready, for simplicity I am consolidating things in this comment so people don’t have to go digging around:
Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.
Here are the build install instructions per platform:
linux x64:
npm install https://cdn.cypress.io/beta/npm/10.10.1/linux-x64/martnoonan/mocha-junit-reporter-bump-b6331ca237a6ed6c708c51193f5f10605b45b3e0/cypress.tgzlinux arm64:
npm install https://cdn.cypress.io/beta/npm/10.10.1/linux-arm64/martnoonan/mocha-junit-reporter-bump-b6331ca237a6ed6c708c51193f5f10605b45b3e0/cypress.tgzdarwin x64:
npm install https://cdn.cypress.io/beta/npm/10.10.1/darwin-x64/martnoonan/mocha-junit-reporter-bump-b6331ca237a6ed6c708c51193f5f10605b45b3e0/cypress.tgzwin32 x64:
npm install https://cdn.cypress.io/beta/npm/10.10.1/win32-x64/martnoonan/mocha-junit-reporter-bump-b6331ca237a6ed6c708c51193f5f10605b45b3e0/cypress.tgzPlease grab which ever one you need and let me know if this fixes the issue.
My apologies… I totally missed it in the server package 😦 PR has been raised to fix it.
@halfninja This issue can be fixed if you turn on the debugging mode in Cypress. I was trying to report this as a bug to Cypress, but the issue is gone whenever I turn on the debugging mode.
Should be fixed in mocha-junit-reporter 2.1.0
https://github.com/michaelleeallen/mocha-junit-reporter/pull/172#issuecomment-1262450532
We’ve seen this in 9.5.2 - it just happened once, with no code changes, and then passed after that. Feels like a bug in mocha-junit-reporter - in various places it assigns
._attr.timeto a number or a string, so seems almost inevitable that sometimes it might try to call.toFixedon a string. Maybe worth raising this bug (or a PR) in that project to look at splitting those attrs into two or at least doing a typeof check.