adamgruber / mochawesome

A Gorgeous HTML/CSS Reporter for Mocha.js
https://gitter.im/mochawesome/general
MIT License
1.06k stars 160 forks source link

Generate report after spec.js fails #361

Closed dawidk09 closed 2 years ago

dawidk09 commented 2 years ago

**Describe the bug

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 report is generated.

// example.js

describe('test', () => {
    it('test1', () => {

    cy.wait(100) 
    })

    it('test2', () => {

        cy.wait(100) 
        })

           /*   it('test3', () => {

             cy.contains("Sorry, something went wrong").should('exist')
        })     
      */   

})

when test3 is uncommented:

npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! cypress-tests@1.0.0 scripts-chrome: cypress run --browser chrome --config-file config.json 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\dk\AppData\Roaming\npm-cache_logs\2021-10-29T11_13_56_823Z-debug.log

cypress-tests@1.0.0 posttest-chrome C:\Users\dk\Cypress npm run combine-reports-chrome && npm run generate-report-chrome && @powershell -NoProfile -ExecutionPolicy Unrestricted -Command ./posttest-chrome.ps1

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

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

✓ Reports saved: C:\Users\dk\Cypress\cypress\reports\current\chrome\mochareports\report.html Archiving report .. Archiving complete

cypress-tests@1.0.0 posttest-chrome C:\Users\dk\Cypress npm run combine-reports-chrome && npm run generate-report-chrome && @powershell -NoProfile -ExecutionPolicy Unrestricted -Command ./posttest-chrome.ps1

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

ERROR: Failed to merge reports

Error: Pattern cypress/reports/current/mocha/.json matched no report files at C:\Users\dk\Cypress\node_modules\mochawesome-merge\lib\index.js:14:11 at Array.map () at C:\Users\dk\Cypress\node_modules\mochawesome-merge\lib\utils.js:3:46 at merge (C:\Users\dk\Cypress\node_modules\mochawesome-merge\lib\index.js:82:17) at Object. (C:\Users\dki\Cypress\node_modules\mochawesome-merge\bin\mochawesome-merge.js:32:1) at Module._compile (internal/modules/cjs/loader.js:1137:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10) at Module.load (internal/modules/cjs/loader.js:985:32) at Function.Module._load (internal/modules/cjs/loader.js:878:14) at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12) npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! cypress-tests@1.0.0 combine-reports-chrome: `mochawesome-merge cypress/reports/current/mocha/.json > cypress/reports/current/chrome/mochareports/report.json` npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the cypress-tests@1.0.0 combine-reports-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\dk\AppData\Roaming\npm-cache_logs\2021-10-29T11_13_59_516Z-debug.log npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! cypress-tests@1.0.0 posttest-chrome: npm run combine-reports-chrome && npm run generate-report-chrome && @powershell -NoProfile -ExecutionPolicy Unrestricted -Command ./posttest-chrome.ps1
npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the cypress-tests@1.0.0 posttest-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\dk\AppData\Roaming\npm-cache_logs\2021-10-29T11_13_59_535Z-debug.log

COMPLETE LOG

22 silly lifecycle cypress-tests@1.0.0~posttest-chrome: Returned: code: 1 signal: null 23 info lifecycle cypress-tests@1.0.0~posttest-chrome: Failed to exec posttest-chrome script 24 verbose stack Error: cypress-tests@1.0.0 posttest-chrome: npm run combine-reports-chrome && npm run generate-report-chrome && @powershell -NoProfile -ExecutionPolicy Unrestricted -Command ./posttest-chrome.ps1 24 verbose stack Exit status 1 24 verbose stack at EventEmitter. (C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\index.js:332:16) 24 verbose stack at EventEmitter.emit (events.js:315:20) 24 verbose stack at ChildProcess. (C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\lib\spawn.js:55:14) 24 verbose stack at ChildProcess.emit (events.js:315:20) 24 verbose stack at maybeClose (internal/child_process.js:1021:16) 24 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:286:5) 25 verbose pkgid cypress-tests@1.0.0 26 verbose cwd C:\Users\dk\Cypress 27 verbose Windows_NT 10.0.19043 28 verbose argv "C:\Program Files\nodejs\node.exe" "C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js" "run" "test-chrome" 29 verbose node v12.18.4 30 verbose npm v6.14.6 31 error code ELIFECYCLE 32 error errno 1 33 error cypress-tests@1.0.0 posttest-chrome: npm run combine-reports-chrome && npm run generate-report-chrome && @powershell -NoProfile -ExecutionPolicy Unrestricted -Command ./posttest-chrome.ps1 33 error Exit status 1 34 error Failed at the cypress-tests@1.0.0 posttest-chrome script. 34 error This is probably not a problem with npm. There is likely additional logging output above. 35 verbose exit [ 1, true ]

Code Reproduce

My script:

I am using powershell scripts to archive my reports.

//package.json

"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 && @powershell -NoProfile -ExecutionPolicy Unrestricted -Command ./posttest-chrome.ps1",
    "test-chrome": "npm run scripts-chrome || npm run posttest-chrome"
}

//posttest-chrome.ps1

Write-Host 'Archiving report ...'

# In the case of directories, forcing them does not clear out existing contents,
# it only suppresses the error message saying it's already created.
# This command will also create any intervening folders necessary,
# and the contents of those folders are also safe if they already exist. – John Neuhaus

$null = New-Item -ItemType Directory -Force -Path .\cypress\reports\archives\chrome

copy-item ".\cypress\videos" -destination ".\cypress\reports\current\chrome" -Recurse

copy-item ".\cypress\downloads" -destination ".\cypress\reports\current\chrome" -Recurse

$null = copy-item ".\cypress\reports\current\mocha" -destination ".\cypress\reports\current\chrome" -Recurse
$null =copy-item "cypress\reports\current\chrome" -destination "cypress\reports\archives\chrome" -Recurse

Rename-Item -Path "cypress\reports\archives\chrome\chrome" -NewName $(get-date -f yyyy-MM-dd-HH-mm-ss)

#Remove-Item ".\cypress\reports\current\mocha" -Recurse

Write-Host 'Archiving complete'

//pretest Write-Host '> checking if directory report/current exist'

$null = New-Item -ItemType Directory -Force -Path .\cypress\reports\current

//cypres.json

"env":{
"reporter": "cypress-multi-reporters",
    "reporterOptions": {
        "reporterEnabled": "mochawesome",
        "mochawesomeReporterOptions": {
            "reportDir": "cypress/reports/current/mocha",
            "quiet": true,
            "overwrite": false,
            "html": false,
            "json": true

        }
},

Environment (please complete the following information):