0

When all spec.js files passes raport is generated and everything is okey. When just one or more of tests fails there is something weird going on. There is many warnings and errors but still report is generated. Also report seems to be generated twice (only on faill). Why?

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! cypress-tests@1.0.0 scripts-chrome: `cypress run --browser chrome`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the cypress-tests@1.0.0 scripts-chrome script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Dawid\AppData\Roaming\npm-cache\_logs\2021-11-02T07_12_01_140Z-debug.log

> cypress-tests@1.0.0 posttest-chrome E:\Cypress
> npm run combine-reports-chrome && npm run generate-report-chrome


> cypress-tests@1.0.0 combine-reports-chrome E:\Cypress
> mochawesome-merge cypress/reports/current/mocha/*.json > cypress/reports/current/chrome/mochareports/report.json


> cypress-tests@1.0.0 generate-report-chrome E:\Cypress
> marge cypress/reports/current/chrome/mochareports/report.json -f report -o cypress/reports/current/chrome/mochareports


✓ Reports saved:
E:\Cypress\cypress\reports\current\chrome\mochareports\report.html

> cypress-tests@1.0.0 posttest-chrome E:\Cypress
> npm run combine-reports-chrome && npm run generate-report-chrome


> cypress-tests@1.0.0 combine-reports-chrome E:\Cypress
> mochawesome-merge cypress/reports/current/mocha/*.json > cypress/reports/current/chrome/mochareports/report.json


> cypress-tests@1.0.0 generate-report-chrome E:\Cypress
> marge cypress/reports/current/chrome/mochareports/report.json -f report -o cypress/reports/current/chrome/mochareports


✓ Reports saved:
E:\Cypress\cypress\reports\current\chrome\mochareports\report.html
PS E:\Cypress> 

This is my code for generating reports

"scripts": {
    "clean:reports-chrome": "rmdir /S /Q cypress\\reports\\current && mkdir cypress\\reports\\current\\chrome\\mochareports",
    "pretest-chrome": "@powershell -NoProfile -ExecutionPolicy Unrestricted -Command ./pretest.ps1 && npm run clean:reports-chrome",
    "scripts-chrome": "cypress run --browser chrome",
    "combine-reports-chrome": "mochawesome-merge cypress/reports/current/mocha/*.json > cypress/reports/current/chrome/mochareports/report.json",
    "generate-report-chrome": "marge cypress/reports/current/chrome/mochareports/report.json -f report -o cypress/reports/current/chrome/mochareports",
    "posttest-chrome": "npm run combine-reports-chrome && npm run generate-report-chrome",
    "test-chrome": "npm run scripts-chrome  || npm run posttest-chrome",
dawidk09
  • 91
  • 10
  • It runs twice because of `|| npm run posttest-chrome`, which squashes the non-zero exit from scripts-chrome. – jonrsharpe Nov 02 '21 at 07:26
  • is it correct implementation? and do you know why these errors occurs? – dawidk09 Nov 02 '21 at 07:40
  • The errors at the top are from the test failing, which you should expect when the test fails. And no it's not the correct implementation, because you're exiting zero (which would mean e.g. CI builds passing when they should fail) and running the report generation twice. – jonrsharpe Nov 02 '21 at 07:43
  • could you tell me how to correct this? change || on && or how? – dawidk09 Nov 02 '21 at 07:52
  • Well && would only run if the test _passed_, so given the whole point was to generate the report when the test _failed_ that wouldn't really help. I'd usually do `a || (b && exit 1)` to preserve a non-zero exit code. – jonrsharpe Nov 02 '21 at 07:54
  • Thanks now the report is generated only once. My previous script was taken from https://dev.to/bushraalam/using-mochawesome-reporter-with-cypress-54pf. – dawidk09 Nov 02 '21 at 07:59
  • I forgot errors occurs second time after report is generated. Is this also cuz of failling spec? npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! cypress-tests@1.0.0 test-chrome: `npm run scripts-chrome || (npm run posttest-chrome && exit 1)` npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the cypress-tests@1.0.0 test-chrome script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above. – dawidk09 Nov 02 '21 at 08:26
  • That's what's _supposed_ to happen - your tests failed, so the NPM command fails. That was the whole point of including exit 1, to make sure that happened. – jonrsharpe Nov 02 '21 at 08:28
  • Sorry, Im just begginer with the automatic tests. I have never heard of exist 1. Could you explain to me more precisely how it works? Just to be clear I only wanted to know if test passed or not and i thought that errors means something with the reports is not ok. – dawidk09 Nov 02 '21 at 10:41
  • Try this method, it will work 100%, https://softans.com/using-mochawesome-reporter-with-cypress/ – GHULAM NABI Dec 28 '22 at 11:28

0 Answers0