YOU54F / cypress-plugins

A home for various Cypress Plugins

Home Page:https://cypress-plugins.saf.dev/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error: TypeError: Cannot read property 'split' of undefined

hanatakaruki opened this issue · comments

Hi!
I'm having issues running the execution part npx cypress-slack-reporter

/home/ubed/Documents/Playground/cypress-slack/node_modules/cypress-slack-reporter/bin/slack/slack-alert.js:167
        throw new Error(e);
              ^

Error: TypeError: Cannot read property 'split' of undefined
    at Object.exports.slackRunner (/home/ubed/Documents/Playground/cypress-slack/node_modules/cypress-slack-reporter/bin/slack/slack-alert.js:167:15)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

I already export the webhook
image

Steps performed

yarn add cypress-slack-reporter --dev
yarn add mochawesome --dev
yarn add mochawesome-merge --dev
yarn add mochawesome-report-generator --dev
yarn add cypress-multi-reporters --dev

Created Slack app and Webhook URL / Oauth
added code snippets for cypress.json and reporterOpts.json
after running test, I combine test report with this command
npx mochawesome-merge cypress/reports/mocha/mochawesome.json > mochareports/report.json
after that, I generate report with this command
npx marge mochareports/report.json -f report -o mochareports
and running cypress-slack-reporter
npx cypress-slack-reporter

System Info
Arch Linux
Cypress : 8.3.0
"cypress-slack-reporter": "^1.2.1",
"cypress-multi-reporters": "^1.5.0",
"mochawesome": "^6.2.2",
"mochawesome-merge": "^4.2.0",
"mochawesome-report-generator": "^5.2.0"

Can you help me to solve this problem?

@hanatakaruki have you been able to fix this?
I'm having the same challenge here

Got the same issue.

Hey dudes, you probably need to @ tag me otherwise I will miss notifications, thanks for the report. I haven't really looked at my OSS projects this year so apologies.

Have you guys tried dropping a version of cypress or the slack reporter, or possibly using nvm to change your node version?

my ci builds have been failing for ages, and last time I looked at cypress it was on v6 maybe, its on v9 now 😅

Will try and get some time this weekend, feel free to knock up and example here on my issues repo, it would help massively.

cheers @hanatakaruki @bankole175 @tbrek

Hi @YOU54F, any update on this issue? idk if it's hard to fix the issue of being able to run it in newer versions of cypress

Hey @HernanMinted

If you or someone can provide a reproducible example that would help, otherwise I'm pretty unlikely to sort it until I do a rewrite of the codebase, which is on my list along with the upload to the s3 feature, but probably not within the next couple of months.

I want to expand first class support for several CI providers as well, and have some recipe guides that I am looking to do as part of my FT job, so will be able to across them all.

@YOU54F Oh, I understand, the steps I did to get the issue, I run my tests, then run the report merge for Mochawesome, generate the output and consolidate the html, after all that is run and created, when I run the line for the slack report this issue that @hanatakaruki posted is shown. in the pipeline looks the passed status jobs are sending the message correctly,
steps:

  • yarn cy:run
  • mochawesome-merge cypress/report/mocha/*.json > cypress/report/output.json
  • marge cypress/report/output.json --reportDir cypress/report/final-report --inline
  • npx cypress-slack-reporter --report-dir 'cypress/report/output.json' --custom-url 'cypress/report/final-report' --ci-provider gitlab --vcs-provider none --verbose

Hmm, yeah I was going to ask if its only in certain scenarios, as we made a change to support difference webhook urls for failing/passing/build failing messages

https://github.com/YOU54F/cypress-slack-reporter/blob/master/src/slack/slack-alert.ts#L115-L126

the problem is going to stem here.

This is the logic for determining if its failed, passed or build error.

You could just tweak the report before triggering the build, to set up different failure conditions.

If you npm install it into a project, you can breakpoint, or add some console logging in the script file inside node_modules, to try and work out where its failing.

Sorry for the pain! I often think back to the original incarnation which was just a bash script and it worked perfectly well 😅

HI @YOU54F , paste the code lines you tagged, and got the message error of "SLACK_WEBHOOK_URL env var set"

 throw new Error(e);
    ^
Error: Error: no SLACK_WEBHOOK_URL env var set

looks somewhere since is breaking in different web hook urls I need to specify them, question is where 🤣

you export them to your shell

export SLACK_WEBHOOK_URL=https://hooks.slack.foo

where did you paste the code lines?

☝🏾

SLACK_WEBHOOK_URL is mandatory at the moment, even if you set separate values for each and all of the following

SLACK_WEBHOOK_FAILED_URL
SLACK_WEBHOOK_ERROR_URL
SLACK_WEBHOOK_PASSED_URL

the code I paste it in the slack-alert.js where it has the fail case
Captura de Pantalla 2022-04-26 a la(s) 13 24 04

the export then should be on my gitlab.yml file?
since I don't use shell )? 🤔

my gitlab.yml file looks like this:
Captura de Pantalla 2022-04-26 a la(s) 13 26 40

hmm, if you echo $SLACK_WEBHOOK_URL in your build step prior to running the reporter, what comes out?

@YOU54F, I did that and got the URL of the web hook, tho in my local I can't get the issue disappear:
` throw new Error(e);
^

Error: TypeError: Cannot read properties of undefined (reading 'split')
at Object.exports.slackRunner (/Users/hernanalonso/Documents/Gitlab/cypress-automation/node_modules/cypress-slack-reporter/bin/slack/slack-alert.js:167:15)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
error Command failed with exit code 1.`

leave it with me buddy and I'll get it sorted over the next week or so

I am going to support oauth2.0 integrations as well as incoming webhooks, and have a decent spike going last night.

Gotcha, thanks @YOU54F , just to let you know, in my gitlab is working. I'm working on trying to give a message just like your example looks like, (status of the job, status of how many passed, failed or skipped) but I only get to show "Total Passed: 1" 🤣 , maybe I'm doing something wrong with webhooking or configuration if you need to see what I have lmk

could you fire me over your test report? my email is in my profile if you don't want to share publicly.

pre merge and post merge ideally. Does it read the correct number of tests in GitLab?