cypress-mochawesome-reporter icon indicating copy to clipboard operation
cypress-mochawesome-reporter copied to clipboard

After migration of cypress and cypress-mochawesome-reporter, a reporter after:run event occurs

Open ToBeKedge opened this issue 1 year ago • 5 comments

Environment

  • OS: Red Hat Enterprise Linux release 8.4 and Windows 10
  • Node: 14.16.0 and 16.15.1
  • cypress-mochawesome-reporter: 3.2.0
  • cypress: 10.3.1

What happened?

After migration of cypress (from 9.2.1 to 10.3.1) and cypress-mochawesome-reporter (from 2.3.0 to 3.2.0), I get this error An error was thrown in your plugins file while executing the handler for the after:run event.

image

When I try the previous version, all is working fine but with last version, I don't understand how to fix this issue. And I get this issue on my both environment.

Config file

cypress.config.ts

import { defineConfig } from 'cypress';

export default defineConfig({
  // Global
  includeShadowDom: true,
  reporter: 'cypress-mochawesome-reporter',
  reporterOptions: {
    reportDir: 'projects/switchboard-editor-app/cypress/report',
    charts: true,
    html: true,
    json: true,
    embeddedScreenshots: true,
    inlineAssets: true,
    debug: true
  },
  retries: {
    runMode: 2,
    openMode: 0
  },
  // Timeouts
  defaultCommandTimeout: 15000,
  // Folders / Files
  fixturesFolder: 'projects/switchboard-editor-app/cypress/fixtures',
  // Screenshots
  screenshotsFolder: 'projects/switchboard-editor-app/cypress/screenshots',
  // Videos
  videosFolder: 'projects/switchboard-editor-app/cypress/videos',
  video: false,
  // Viewport
  viewportWidth: 1280,
  viewportHeight: 1024,
  // e2e
  e2e: {
    baseUrl: 'http://localhost:4200/',
    supportFile: 'projects/switchboard-editor-app/cypress/support/index.ts',
    specPattern: 'projects/switchboard-editor-app/cypress/integration/*.ts',
    // eslint-disable-next-line @typescript-eslint/no-unused-vars
    setupNodeEvents: (on: Cypress.PluginEvents, config) => {
      require('cypress-mochawesome-reporter/plugin')(on);

      on(
        'before:browser:launch',
        (browser = {} as Cypress.Browser, launchOptions) => {
          if (browser.family === 'chromium') {
            const addIfNotPresent = (args: string[], arg: string): void => {
              const index = args.indexOf(arg);
              if (index < 0) {
                args.push(arg);
              }
            };

            const removeIfPresent = (args: string[], arg: string): void => {
              const index = args.indexOf(arg);
              if (index > -1) {
                args.splice(index, 1);
              }
            };

            removeIfPresent(launchOptions.args, '--disable-gpu');
            addIfNotPresent(launchOptions.args, '--headless');
            addIfNotPresent(launchOptions.args, '--use-gl=desktop');
            addIfNotPresent(launchOptions.args, '--ignore-gpu-blocklist');
            console.log(launchOptions.args);
          }
          return launchOptions;
        }
      );
    }
  }
});

Relevant log output

cypress-mochawesome-reporter.log

Anything else?

No response

ToBeKedge avatar Aug 01 '22 09:08 ToBeKedge

I'm having the same issue. Any idea on how to fix this?

override after:run
Start generate report process
Read and merge jsons from "reports\.jsons"
Screenshots folder "C:\xxxxxxx\top-level\cypress\reports\screenshots" not found, nothing to copy
An error was thrown in your plugins file while executing the handler for the after:run event.

The error we received was:

Error: Pattern reports\.jsons/*.json matched no report files
    at C:\xxxxxxx\top-level\cypress\node_modules\mochawesome-merge\lib\index.js:14:11
    at Array.map (<anonymous>)
    at C:\xxxxxxx\top-level\cypress\node_modules\mochawesome-merge\lib\utils.js:3:46
    at merge (C:\xxxxxxx\top-level\cypress\node_modules\mochawesome-merge\lib\index.js:82:17)
    at mergeAndCreate (C:\xxxxxxx\top-level\cypress\node_modules\cypress-mochawesome-reporter\lib\generateReport.js:12:24)
    at generateReport (C:\xxxxxxx\top-level\cypress\node_modules\cypress-mochawesome-reporter\lib\generateReport.js:56:20)
    at afterRunHook (C:\xxxxxxx\top-level\cypress\node_modules\cypress-mochawesome-reporter\lib\index.js:35:9)
    at Object.handler (C:\xxxxxxx\top-level\cypress\cypress.config.js:24:15)
    at invoke (C:\Users\P93003672-la\AppData\Local\Cypress\Cache\10.3.0\Cypress\resources\app\node_modules\@packages\server\lib\plugins\child\run_plugins.js:43:18)
    at C:\Users\P93003672-la\AppData\Local\Cypress\Cache\10.3.0\Cypress\resources\app\node_modules\@packages\server\lib\plugins\util.js:59:14

enniob avatar Aug 03 '22 22:08 enniob

Please create a repo with the problem and steps to reproduce the issue so I can have a look.

Thanks.

LironEr avatar Aug 05 '22 08:08 LironEr

Hi @LironEr

I have made 2 tests

In that case, the generation of the report working fine

In that case, the generation of the report failed

In summary: I think it is due to the folder configuration and the reporter doesn't really support any other folder than the default one (and it works previous version of cypress and reporter).

ToBeKedge avatar Aug 05 '22 10:08 ToBeKedge

Based on the second test, I made a third test: I moved the cypress.config.ts to the workspace root and everything works. So is it a problem of the reporter or of cypress itself?

ToBeKedge avatar Aug 05 '22 13:08 ToBeKedge

Just released a fix, can you please verify it works?

npm i --save-dev [email protected]

Thank you 👍

LironEr avatar Aug 06 '22 07:08 LironEr

Hi @LironEr I have just test the fix and it seems it is working fine! Thanks a lot for your work!

ToBeKedge avatar Aug 08 '22 09:08 ToBeKedge

Hi @LironEr thanks for the fix.

enniob avatar Aug 08 '22 14:08 enniob

Released in v3.2.1

Thank you for the detailed issue, really helped me to understand the problem and how to solve it (:

LironEr avatar Aug 10 '22 19:08 LironEr