Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cypress: Import tests into "./cypress/integration" from multiple npm dependencies?

Tags:

cypress

I have a very large Cypress-based test suite, cy_tests_A_B_monolith, and the number of tests in ./cypress/integration folder is substantial.

I wish to partition these integration tests into their own npm module, and make them dependencies of a more manageable Cypress test suite.

  • From cy_tests_A_B_monolith
  • To cy_tests_A_B_manageable + dependencies cy_test_A + cy_test_B

Rough draft below. Uncertain how to import ./cypress/integration/*** tests to be a dependency into another Cypress test suite.

Much appreciated for suggestions, Thank you.


Rough Draft:

FROM monolith

Many integration tests + src custom commands...

npm cy_tests_A_B_monolith

├── cypress
│   ├── integration
│   │   ├── A
│   │   └── B
│   └── support
│       └── specs
│           ├── A
│           └── B
├── src
│   ├── A
│   |   └── commands
│   └── B
│       └── commands

TO...

Partitioning monolith into a manageable test suite by maintaining subset of /cypress/integration of monolith test suite

npm cy_tests_A_B_manageable

├── cypress
│   ├── integration
│   │   ├── A << dependency imported cy_test_A ./cypress/integration/A
│   │   └── B << dependency imported cy_test_B ./cypress/integration/B

npm cy_test_A

├── cypress
│   ├── integration
│   │   └── A
│   └── support
│       └── specs
│           └── A
├── src
│   └── A
│       └── commands

npm cy_test_B

├── cypress
│   ├── integration
│   │   └── B
│   └── support
│       └── specs
│           └── B
├── src
│   └── B
│       └── commands
like image 835
Jeff Tanner Avatar asked Oct 25 '25 04:10

Jeff Tanner


1 Answers

It's a little bit funky, but you can us the Module API in cy_tests_A_B_manageable to drive tests from other projects

/scripts/run-cypress.js

const cypress = require('cypress')

const testProjects = ['../cy_test_A', '../cy_test_B']

testProjects.forEach(project => {

  cypress.run({
    reporter: 'junit',
    browser: 'chrome',
    project,                // can specify the project root here
    config: {
      video: false,
    },
    env: {
      login_url: '/login',
      products_url: '/products',
    },
  })
})

With cypress open it opens multiple runners, not ideal...

But can use cypress.open(...) with this folder setup

cypress-multi-project
  - cy_test_A
  - cy_test_B
  - cypress-run-other-project

cypress-multi-project/cypress.json

{
  "integrationFolder": "./",
  "testFiles": "**/*.spec.js"    // must uniquely suffix integration tests
}

cypress-multi-project/cypress-run-other-project/scripts/run-cypress.js

const cypress = require('cypress')

cypress.open({
  reporter: 'junit',
  browser: 'chrome',
  project: '..',      // project is parent folder
  config: {
    video: true,
  },
  env: {
    login_url: '/login',
    products_url: '/products',
  },
})

enter image description here

like image 123
Fody Avatar answered Oct 28 '25 05:10

Fody