LironEr / cypress-mochawesome-reporter

Zero config Mochawesome reporter for Cypress with screenshots and videos
MIT License
159 stars 49 forks source link

Upgrade to Cypress 10.2.0 breaks report generator #88

Closed msesun closed 2 years ago

msesun commented 2 years ago

Environment

- OS: MacOS Monterrey
- Node: 14.18.1
- cypress-mochawesome-reporter: 3.1.0
- cypress: 10.2.0

What happened?

We have been using Cypress version 9.7.0 with the cypress-mochawesome-reporter and everything is working great.

When upgrading Cypress to 10.2.0, the reporter is now unable to find our reports folder to run the merge feature and create the index.html report.

The Cypress tests run successfully, the screenshots and mochawesome*.json files all generate correctly and are put in the right place. It's just when the final step of generating the html report where there is a failure.

Are there configuration updates needed for the cypress-mochawesome-reporter with the new version of Cypress?

Config file

import { defineConfig } from 'cypress';

export default defineConfig({
  viewportWidth: 1200,
  viewportHeight: 900,
  chromeWebSecurity: false,
  defaultCommandTimeout: 10000,
  pageLoadTimeout: 100000,
  reporter: 'cypress-mochawesome-reporter',
  retries: {
    runMode: 2,
    openMode: 0,
  },
  reporterOptions: {
    reportDir: 'cypress/reports',
    charts: true,
    reportPageTitle: 'Dev Test Suite',
    embeddedScreenshots: true,
    inlineAssets: true,
  },
  video: false,
  screenshotsFolder: 'cypress/screenshots',
  watchForFileChanges: false,
  e2e: {
    setupNodeEvents(on, config) {
      // eslint-disable-next-line @typescript-eslint/no-var-requires
      require('cypress-mochawesome-reporter/plugin')(on);
    },
    baseUrl: 'https://cdn-app-dev.drcedirect.com/',
  },
});

Relevant log output

Start generate report process
Read and merge jsons from "cypress/reports/.jsons"
options { files: [ 'cypress/reports/.jsons/*.json' ] }
An error was thrown in your plugins file while executing the handler for the after:run event.

The error we received was:

Error: Pattern cypress/reports/.jsons/*.json matched no report files
    at ui/node_modules/mochawesome-merge/lib/index.js:15:11
    at Array.map (<anonymous>)
    at ui/node_modules/mochawesome-merge/lib/utils.js:3:46
    at merge (ui/node_modules/mochawesome-merge/lib/index.js:84:17)
    at mergeAndCreate (ui/node_modules/cypress-mochawesome-reporter/lib/generateReport.js:12:24)
    at generateReport (ui/node_modules/cypress-mochawesome-reporter/lib/generateReport.js:56:20)
    at afterRunHook (ui/node_modules/cypress-mochawesome-reporter/lib/index.js:35:9)
    at Object.handler (ui/node_modules/cypress-mochawesome-reporter/plugin.js:9:11)
    at invoke (/Users/e/Library/Caches/Cypress/10.2.0/Cypress.app/Contents/Resources/app/packages/server/lib/plugins/child/run_plugins.js:43:18)
    at /Users/e/Library/Caches/Cypress/10.2.0/Cypress.app/Contents/Resources/app/packages/server/lib/plugins/util.js:59:14
    at tryCatcher (/Users/e/Library/Caches/Cypress/10.2.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/bluebird/js/release/util.js:16:23)
    at Function.Promise.attempt.Promise.try (/Users/e/Library/Caches/Cypress/10.2.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/bluebird/js/release/method.js:39:29)
    at Object.wrapChildPromise (/Users/e/Library/Caches/Cypress/10.2.0/Cypress.app/Contents/Resources/app/packages/server/lib/plugins/util.js:58:23)
    at RunPlugins.execute (/Users/e/Library/Caches/Cypress/10.2.0/Cypress.app/Contents/Resources/app/packages/server/lib/plugins/child/run_plugins.js:158:21)
    at EventEmitter.<anonymous> (/Users/e/Library/Caches/Cypress/10.2.0/Cypress.app/Contents/Resources/app/packages/server/lib/plugins/child/run_plugins.js:257:12)
    at EventEmitter.emit (events.js:400:28)
    at EventEmitter.emit (domain.js:475:12)
    at process.<anonymous> (/Users/e/Library/Caches/Cypress/10.2.0/Cypress.app/Contents/Resources/app/packages/server/lib/plugins/util.js:33:22)
    at process.emit (events.js:400:28)
    at process.emit (domain.js:475:12)
    at process.emit.sharedData.processEmitHook.installedValue [as emit] (/Users/e/Library/Caches/Cypress/10.2.0/Cypress.app/Contents/Resources/app/node_modules/@cspotcode/source-map-support/source-map-support.js:613:40)
    at emit (internal/child_process.js:912:12)
    at processTicksAndRejections (internal/process/task_queues.js:83:21)

Anything else?

No response

richardhendricksen commented 2 years ago

Same issue here, upgraded from Cypress 9.7 to 10.3.0 and getting the same stacktrace:

Start generate report process
Read and merge jsons from "cypress\report\.jsons"
An error was thrown in your plugins file while executing the handler for the after:run event.

The error we received was:

Error: Pattern cypress\report\.jsons/*.json matched no report files
    at mycode\node_modules\mochawesome-merge\lib\index.js:14:11

Used the configuration as shown in the Readme.

The issue seems to be that the cwd is the cypress config directory, so when its looking for the json files relative from this directory it wont work. A workaround that works for me is to edit the reportDir that is passed to the beforeRunHook, to make it relative to the config directory. The afterRunHook can stay the same:

    setupNodeEvents(on, config) {
      on('before:run', async (details) => {
        let newDetails = {...details};
        newDetails.config.reporterOptions.reportDir= '../report';
        await beforeRunHook(newDetails);
      });

      on('after:run', async () => {
        await afterRunHook();
      });
    },
LironEr commented 2 years ago

@richardhendricksen can you please describe your folder structure?

something like:

package.json
cypress.config.js
cypress/
  e2e/
    test.cy.js
  reports/
    html/
      index.html

It would help me understand the issue

@msesun is the solution @richardhendricksen wrote solves your issue?

richardhendricksen commented 2 years ago

@LironEr My folder structure is almost as you described, only I have multiple config files for specific OTAP environments and I put those in a separate subdirectory:

cypress/
  config/
    local.config.ts
    dev.config.ts
    test.config.ts
  e2e/
    *.cy.ts files
  report/
    html/
      index.html
LukasLewandowski commented 2 years ago

Hi, I have the same issue :/ any luck with downgrading cypress or mochawesome-reporter or something?

So this workaround should point to the same "reports" dir where reporter is creating reports?

let newDetails = {...details};
newDetails.config.reporterOptions.reportDir= '../report';
LukasLewandowski commented 2 years ago

I got it resolved and that not an issue with Cypress or mochawesome-reporter versions, I had an mistake in configuration.

msesun commented 2 years ago

@LironEr Yes, adding the before hook @richardhendricksen shared to change the reports directory solves the issue. Thank you both!

This is still a workaround, and I'm curious what changed, but sounds like maybe it's a Cypress issue not a cypress-mochawesome-reporter issue.

dovh-me commented 2 years ago

I think the issue is due to Cypress 10 having the plugins executed from the config file directly while in previous versions we were just defining the path to the plugins file in the config.

I had the same issue and got it fixed by this. Thanks @richardhendricksen

Same issue here, upgraded from Cypress 9.7 to 10.3.0 and getting the same stacktrace:

Start generate report process
Read and merge jsons from "cypress\report\.jsons"
An error was thrown in your plugins file while executing the handler for the after:run event.

The error we received was:

Error: Pattern cypress\report\.jsons/*.json matched no report files
    at mycode\node_modules\mochawesome-merge\lib\index.js:14:11

Used the configuration as shown in the Readme.

The issue seems to be that the cwd is the cypress config directory, so when its looking for the json files relative from this directory it wont work. A workaround that works for me is to edit the reportDir that is passed to the beforeRunHook, to make it relative to the config directory. The afterRunHook can stay the same:

    setupNodeEvents(on, config) {
      on('before:run', async (details) => {
        let newDetails = {...details};
        newDetails.config.reporterOptions.reportDir= '../report';
        await beforeRunHook(newDetails);
      });

      on('after:run', async () => {
        await afterRunHook();
      });
    },
LironEr commented 2 years ago

It might be related to a fix I released https://github.com/LironEr/cypress-mochawesome-reporter/issues/95#issuecomment-1207170180

I will release an official version in a few days.

msesun commented 2 years ago

@LironEr Thanks!