LironEr / cypress-mochawesome-reporter

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

Cypress is not defined #92

Closed selfagency closed 2 years ago

selfagency commented 2 years ago

Environment

- OS: Ubuntu 20
- Node: 16.13.2
- cypress-mochawesome-reporter: latest
- cypress: 10

What happened?

Cypress fails to run after loading require('cypress-mochawesome-reporter/plugin')(on).

Config file

import {defineConfig} from 'cypress';

const configuration = {
  chromeWebSecurity: false,
  defaultCommandTimeout: 30000,
  execTimeout: 60000,
  reporter: 'cypress-mochawesome-reporter',
  retries: {
    runMode: 2,
  },
  screenshotOnRunFailure: false,
  taskTimeout: 60000,
  video: false,
  viewportWidth: 1280,
};

export default defineConfig({
  ...configuration,
  e2e: {
    baseUrl: 'http://localhost:3000',
    env: {
      API_BASE_URL: 'http://localhost:8080',
    },
    setupNodeEvents(on, config) {
      require('cypress-mochawesome-reporter/plugin')(on);
      return require('./cypress/plugins/index.ts').default(on, config);
    },
  },
});

Relevant log output

Your configFile is invalid: /home/runner/work/unstoppable-domains-website/unstoppable-domains-website/e2e/cypress.config.ts

It threw an error when required, check the stack trace below:

ReferenceError: Cypress is not defined
    at Object.<anonymous> (/home/runner/work/unstoppable-domains-website/unstoppable-domains-website/node_modules/cypress-mochawesome-reporter/register.js:4:27)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Object.require.extensions.<computed> [as .js] (/home/runner/.cache/Cypress/10.3.1/Cypress/resources/app/node_modules/ts-node/src/index.ts:1445:43)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (/home/runner/work/unstoppable-domains-website/unstoppable-domains-website/e2e/cypress.config.ts:2:1)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)
    at Module.m._compile (/home/runner/.cache/Cypress/10.3.1/Cypress/resources/app/node_modules/ts-node/src/index.ts:1455:23)
    at Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Object.require.extensions.<computed> [as .ts] (/home/runner/.cache/Cypress/10.3.1/Cypress/resources/app/node_modules/ts-node/src/index.ts:1458:12)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at loadFile (/home/runner/.cache/Cypress/10.3.1/Cypress/resources/app/node_modules/@packages/server/lib/plugins/child/run_require_async_child.js:89:14)
    at EventEmitter.<anonymous> (/home/runner/.cache/Cypress/10.3.1/Cypress/resources/app/node_modules/@packages/server/lib/plugins/child/run_require_async_child.js:116:38)
    at EventEmitter.emit (node:events:390:28)
    at EventEmitter.emit (node:domain:475:12)
    at process.<anonymous> (/home/runner/.cache/Cypress/10.3.1/Cypress/resources/app/node_modules/@packages/server/lib/plugins/util.js:33:22)

Anything else?

support/e2e.ts

import 'cypress-mochawesome-reporter/register';
import './commands';

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

beforeEach(() => {
  // firebase uses indexDB to store logged in users.
  void cy.clearIndexedDb();
  cy.clearLocalStorage();
  cy.clearCookies();
  cy.task('db:seed');
});
selfagency commented 2 years ago

never mind, it's because i included import 'cypress-mochawesome-reporter' in the config file by accident