LironEr / cypress-mochawesome-reporter

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

The task 'generateReport' was not handled in the setupNodeEvents method. #129

Closed uhlstefa closed 1 year ago

uhlstefa commented 1 year ago

Environment

- OS: Windows 10
- Node: v14.17.4

package.json:
"devDependencies": {
    "cross-env": "^7.0.3",
    "cypress": "^12.2.0",
    "cypress-grep": "^3.0.3",
    "dotenv": "^16.0.3",
    "mochawesome": "^7.1.3",
    "cypress-iframe": "^1.0.1",
    "cypress-visual-regression": "2.1.0",
    "cypress-mochawesome-reporter": "^3.2.3"
  }

What happened?

When my test fails it doesn't generate report, as the task is not registered.

Config file

cypress.config.js:

require("dotenv").config({ path: `.env${process.env.ENV_CONFIG}` });
const { defineConfig } = require("cypress");
const { beforeRunHook, afterRunHook } = require('cypress-mochawesome-reporter/lib');
const getCompareSnapshotsPlugin = require('cypress-visual-regression/dist/plugin');

module.exports = defineConfig({
  projectId: "vwviug",
  modifyObstructiveCode: true,
  chromeWebSecurity: false,

  defaultCommandTimeout: 8000,
  pageLoadTimeout: 30000,
  execTimeout: 60000,
  requestTimeout: 15000,
  responseTimeout: 15000,

  reporter: 'cypress-mochawesome-reporter',
  reporterOptions: {
    charts: true,
    reportPageTitle: 'design-system-report',
    embeddedScreenshots: true,
    inlineAssets: true,
    saveAllAttempts: false,
  },

  viewportWidth: 1000,
  viewportHeight: 600,
  waitForAnimation: true,

  retries: {
    runMode: 1,
  },
  env: {
    screenshotsFolder: './cypress/snapshots/actual',
    trashAssetsBeforeRuns: true,
    video: false
  },
  e2e: {
    setupNodeEvents(on, config) {
      // config.baseUrl = process.env.URL;
      config.env.url = process.env.URL;
      config.env.environment = process.env.ENVIRONMENT;
      config.env.username = process.env.USERNAME;
      config.env.password = process.env.PASSWORD;
      config.env.emailId = process.env.EMAIL_ID;
      getCompareSnapshotsPlugin(on, config);
      console.log(`Tests are running on ${config.env.environment} environment`);
      require('cypress-mochawesome-reporter/plugin')(on);
      require("cypress-grep/src/plugin")(config);

      on('before:run', async (details) => {
        console.log('override before:run');
        await beforeRunHook(details);
      });
      on('after:run', async () => {
        console.log('override after:run');
        await afterRunHook();
      });
      return config;
    },
    specPattern: "cypress/e2e/*.cy.js",
    supportFile: "cypress/support/e2e.js",
  },
});

e2e.js:
import "./commands";
import 'cypress-iframe';
import 'cypress-mochawesome-reporter/register';
import registerCypressGrep from "cypress-grep";
registerCypressGrep();

// Alternatively you can use CommonJS syntax:
require('./commands')
after(() => {
  cy.task('generateReport')
})

Cypress.on("uncaught:exception", (err, runnable) => {
  // returning false here prevents Cypress from
  // failing the test
  return false;
});

Relevant log output

cy.task('generateReport') failed with the following error:

The task 'generateReport' was not handled in the setupNodeEvents method. The following tasks are registered: compareSnapshotsPlugin, moveSnapshot, updateSnapshot

Fix this in your setupNodeEvents method here:

C:\dev\oneshop-wlfe\cypress-tests\cypress.config.js

Anything else?

No response