8

In the cypress.config.js , I'm trying to register tasks / plug in events and set my env configuration exactly as documented on their guide.

However, when trying to use "on" inside setupNodeEvents I'm getting the error in the title about needing to register it.

Also, to note when passing both arguments (on, config), the config file does not pick up the env variable. Only when I put config first or config by itself, do the env variables pass.

Also, my tasks are properly coded inside the test classes. I know this because they work just fine for previous versions of cypress 9 but I can share them if someone thinks that's where the

/// <reference types="cypress" />
const { defineConfig } = require('cypress');

module.exports = defineConfig({
  e2e: {
    setupNodeEvents(on,config) {
      
      if (config.env == undefined) {
        return {
          baseUrl: "intentionally blank",
          env: {
            env: "test",
            schedulerBaseUrl: "intentionally blank",
            signInUrl: "intentionally blank",
            enableAccessibility: true,
            takeScreenShot: false,
            suites: "",
          },
        };
      }
      else if (config.env == 'development') {
        return {
          baseUrl: "https://blank.blank.com:blank",
          env: {
            environment: "development",
            schedulerBaseUrl: "intentionally blank",
            signInUrl: "intentionally blank",
            enableAccessibility: false,
            takeScreenShot: false
          },
        }
      }
      
      on('task', {
        log(message) {
          console.log(message)
          return null
        },
        table(message) {
          console.table(message)
          return null
        }
      })

      on('before:browser:launch', (browser, launchOptions) => {
        if (browser.name === 'chrome' && browser.isHeadless) {
          launchOptions.args.push('--disable-gpu');
          launchOptions.args.push('--disable-dev-shm-usage');
          launchOptions.args.push('use-fake-device-for-media-stream');
          return launchOptions;
        }
      });
    },
    chromeWebSecurity: false,
    screenshotOnRunFailure: false,
    trashAssetsBeforeRuns: true,
    numTestsKeptInMemory: 0,
    video: true,
    videoCompression: false,
    enableAccessibility: false,
    takeScreenShot: false,
    defaultCommandTimeout: 10000,
    execTimeout: 500000,
    pageLoadTimeout: 500000,
    retries: {
      runMode: 1,
      openMode: 0
    },
    blockHosts: [
      "*intentionally blank"
    ],
    redirectionLimit: 199,
    projectId: "intentionally blank",
  }
})
require('@applitools/eyes-cypress')(module);
K.A.
  • 81
  • 1
  • 3

1 Answers1

5

I have had a similar issue, but for me it was the migration from Cypress 9.x.x to Cypress 10.+ while having some tasks and environmental variable overrides declared in the previous location, which was module.exports = (on, config) => {...} code block within ~/cypress/plugins/index.js file. I tried migrating, yet I was running into some issues, yours included. I came up with kind of a hacky way to keep it all in index.js and within cypress.config.js file I simply require the whole exported index.js module like this:

setupNodeEvents(on, config) {
  return require('./cypress/plugins/index.js')(on, config)
},

Hope this helps.