Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error in auto merge using Cypress flag --config-file #134

Open
notfounnd opened this issue Oct 27, 2022 · 5 comments
Open

Error in auto merge using Cypress flag --config-file #134

notfounnd opened this issue Oct 27, 2022 · 5 comments

Comments

@notfounnd
Copy link

Hi everyone.

I'm migrating my project to Cypress 10 and when I setup the project to use a custom config file I get the following error:

Auto merge: plugin is not installed. Use reporterOptions settings for calculation.
Configuration property not set! Neither for cypress <= 9 nor cypress >= 10
Error: Configuration property not set! Neither for cypress <= 9 nor cypress >= 10
    at getTotalSpecs (C:\Projetos\poc\cypress-10\new-test-e2e-architecture-example\node_modules\@reportportal\agent-js-cypress\lib\utils.js:251:11)
    at Function.calcTotalLaunches (C:\Projetos\poc\cypress-10\new-test-e2e-architecture-example\node_modules\@reportportal\agent-js-cypress\lib\cypressReporter.js:194:39)
    at Runner.<anonymous> (C:\Projetos\poc\cypress-10\new-test-e2e-architecture-example\node_modules\@reportportal\agent-js-cypress\lib\cypressReporter.js:147:23)
    at Runner.emit (node:events:539:35)
    at Runner.emit (node:domain:475:12)
    at Reporter.emit (C:\Users\junior\AppData\Local\Cypress\Cache\10.10.0\Cypress\resources\app\packages\server\lib\reporter.js:362:46)
    at Object.onMocha (C:\Users\junior\AppData\Local\Cypress\Cache\10.10.0\Cypress\resources\app\packages\server\lib\project-base.js:272:34)
    at Socket.<anonymous> (C:\Users\junior\AppData\Local\Cypress\Cache\10.10.0\Cypress\resources\app\packages\server\lib\socket-base.js:260:40)
    at Socket.emit (node:events:527:28)
    at Socket.emit (node:domain:475:12)
    at Socket.emitUntyped (C:\Users\junior\AppData\Local\Cypress\Cache\10.10.0\Cypress\resources\app\packages\socket\node_modules\socket.io\dist\typed-events.js:69:22)
    at C:\Users\junior\AppData\Local\Cypress\Cache\10.10.0\Cypress\resources\app\packages\socket\node_modules\socket.io\dist\socket.js:428:39
    at processTicksAndRejections (node:internal/process/task_queues:78:11)

In my custom config file I get the general configs from cypress.config.js and merge it with custom configs from my test.config.js.

When I not set the custom config file, it works ok.

Project settings:

  • cypress 10.10.0
  • @reportportal/agent-js-cypress 5.1.0
  • cypress-multi-reporters 1.6.1
  • mochawesome 7.1.3
  • cypress-grep 3.0.3
  • defu 6.1.0

Package scritp:

"cy:run": "env CYPRESS_grepTags=@debug,@example yarn cypress run --config-file ./cypress/environments/test.config.js"

I also tryed without the cypress-grep and I getted the same error.

cypress.config.js

/// <reference types="cypress" />

const { defineConfig } = require('cypress')

const registerReportPortalPlugin = require('@reportportal/agent-js-cypress/lib/plugin')

module.exports = defineConfig({
  e2e: {
    setupNodeEvents (on, config) {
      // setup cypress-grep plugin
      // https://github.com/cypress-io/cypress-grep
      require('cypress-grep/src/plugin')(config)

      // setup report portal plugin
      // https://github.com/reportportal/agent-js-cypress
      return registerReportPortalPlugin(on, config)
    },
    chromeWebSecurity: false,
    defaultCommandTimeout: 20000,
    viewportWidth: 1366,
    viewportHeight: 768,
    screenshotsFolder: 'cypress/reports/screenshots',
    videosFolder: 'cypress/reports/videos',
    video: false,
    env: {
      grepOmitFiltered: true,
      anotherEnvParam: 'test2',
      newEnvParam: 'test3',
      base: {
        test1: 1,
        test2: 2
      }
    },
    reporter: 'cypress-multi-reporters',
    reporterOptions: {
      reporterEnabled: ['mochawesome', '@reportportal/agent-js-cypress'],
      mochawesomeReporterOptions: {
        reportDir: './cypress/reports/mocha',
        quite: true,
        overwrite: false,
        html: false,
        json: true
      },
      reportportalAgentJsCypressReporterOptions: {
        endpoint: 'https://my-reportportal-url.com/api/v1',
        token: 'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX',
        launch: 'LAUNCH_NAME_EXAMPLE',
        project: 'my_demo_project',
        description: 'DESCRIPTION_LAUNCH_EXAMPLE',
        autoMerge: true,
        restClientConfig: {
          timeout: 300000
        },
        attributes: [
          { value: 'e2e' },
          { value: 'default' }
        ]
      }
    }
  }
})

test.config.js

/// <reference types="cypress" />

const { defineConfig } = require('cypress')
const { defu } = require('defu')

const defaultConfig = require('../../cypress.config')

// setup environment config file
// https://github.com/cypress-io/cypress/discussions/22517
module.exports = defineConfig(
  defu({
    e2e: {
      setupNodeEvents (on, config) {
        // implement node event listeners here
      },
      chromeWebSecurity: false,
      env: {
        someEnvParam: 'test1'
      }
    }
  },
  defaultConfig)
)
@notfounnd
Copy link
Author

I think I made it works, but I had to re-cofigure the registerReportPortalPlugin() in custom env file.

The initial setup on base config file (cypress.config.js) not persisted.

Looking anothers plugins it not seens a default way to manage plugins when the project uses custom config files, the configs persisting from the base config file.

@notfounnd
Copy link
Author

I found other issue about this error.

It also happen when the first spec file to be executed by Cypress start without tests or it just has one test.

@luizwurlitzer2
Copy link

luizwurlitzer2 commented Jul 21, 2023

Hi @notfounnd do you still have the custom env file which you mentioned? i'm facing the same error.

@notfounnd
Copy link
Author

Hi @notfounnd do you still have the custom env file which you mentioned? i'm facing the same error.

You can check below a complete example. If you copy this, pay attention about the dependencies.

run command example

yarn cypress run --config-file ./cypress/environments/debug.config.js

cypress.config.js (base config file - location: ./)

/// <reference types="cypress" />

const { defineConfig } = require('cypress')

const registerReportPortalPlugin = require('@reportportal/agent-js-cypress/lib/plugin')

const defaultConfig = {
  e2e: {
    setupNodeEvents (on, config) {
      // setup @cypress/grep plugin
      // https://github.com/cypress-io/cypress/tree/develop/npm/grep
      require('@cypress/grep/src/plugin')(config)

      // setup report portal plugin
      // https://github.com/reportportal/agent-js-cypress
      return registerReportPortalPlugin(on, config)
    },
    chromeWebSecurity: false,
    defaultCommandTimeout: 45000,
    requestTimeout: 45000,
    responseTimeout: 45000,
    viewportWidth: 1366,
    viewportHeight: 768,
    screenshotsFolder: 'cypress/reports/screenshots',
    videosFolder: 'cypress/reports/videos',
    video: false,
    retries: {
      runMode: 2,
      openMode: 0
    },
    env: {
      grepFilterSpecs: true,
      grepOmitFiltered: true,
      hideXhr: false
    },
    reporter: 'cypress-multi-reporters',
    reporterOptions: {
      reporterEnabled: ['mochawesome'],
      mochawesomeReporterOptions: {
        reportDir: './cypress/reports/mocha',
        quite: true,
        overwrite: false,
        html: false,
        json: true
      }
    }
  }
}

module.exports = defineConfig(defaultConfig)

test.config.js (env config file - location: ./cypress/environments)

/// <reference types="cypress" />

const { defineConfig } = require('cypress')
const { defu } = require('defu') // yarn add -D defu
const { setupReportPortalConfig } = require('../../helpers/setup-report-portal')

const registerReportPortalPlugin = require('@reportportal/agent-js-cypress/lib/plugin')

// setup environment config file
// https://github.com/cypress-io/cypress/discussions/22517
const defaultConfig = require('../../cypress.config')

const environmentConfig = {
  e2e: {
    setupNodeEvents (on, config) {
      // implement node event listeners here
      return registerReportPortalPlugin(on, config)
    },
    baseUrl: 'https://example.cypress.io/',
    env: {
      environment: 'debug',
      exampleUrl: 'https://swapi.dev/',
      serviceUrl: 'https://swapi.dev/api/',
      exampleKey: 'Key Value',
      customValue: 5000
    },
    reporterOptions: {
      reporterEnabled: ['@reportportal/agent-js-cypress'],
      reportportalAgentJsCypressReporterOptions: {
        endpoint: 'https://reportportal.xxxxxxxxxxxxxxxxx.com/api/v1',
        token: 'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX',
        launch: 'LAUNCH_NAME_EXAMPLE',
        project: 'demo_project',
        description: 'DESCRIPTION_LAUNCH_EXAMPLE',
        autoMerge: true,
        restClientConfig: {
          timeout: 300000
        },
        attributes: [
          { value: 'e2e' },
          { value: 'default' }
        ]
      }
    }
  }
}

// setup report portal configuration
// this is a helper used to setup RP configuration
// firstly you can remove this and use hard code setup on this file
const setupConfig = setupReportPortalConfig(environmentConfig)

console.log('-----------------------------------')
console.log('setup configuration:')
console.log('+ %s', setupConfig.e2e.env.environment)
console.log('-----------------------------------')

module.exports = defineConfig(defu(setupConfig, defaultConfig))

@luizwurlitzer2
Copy link

it helped a lot, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants