Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cypress: parent package runs its cypress/integration test and its dependencies cypress/integration tests

Tags:

cypress

Question: Can a parent Cypress npm project import/add/run the Cypress tests of its dependencies Cypress npm projects?

The response from the question is this link works, breaking up a monolith Cypress test package into multiple Cypress test package and using Module API. However, I have had to rethink my question. What I did not address was that there are dependencies (custom commands) between npm cypress packages.

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

Example:

  • npm package cy_test_A has dependency on npm package cy_test_B custom commands,
  • npm package cy_test_B has dependency on npm package cy_test_C custom commands.

Each of these packages has cypress integration for specs and src for custom commands:

cy_test_***

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

Can Cypress integration tests be imported from its dependency? When I perform a test run, I want to see a combined tests including both the dependencies' cypress tests + the parent's cypress test.

npm package cy_test_A is dependent on custom commands within npm package cy_test_B, which are used in cy_test_A cypress integration tests. When building npm package cy_test_B, it has its own cypress integration tests before committing to npm repository. I want cy_test_A to run its own cypress integration tests but cypress integration tests of its dependency cy_test_B as well.

├── cypress
│   ├── integration
│   │   └── tests_A <<< Dependent on src/commands **cy_test_B**
│   │   └── tests_B <<< Imported cypress/integration/tests from **cy_test_B**
│   └── support
│       └── specs
├── src
│   └── commands
├── node_module
│   └── **cy_test_B**
│       └── ***
│       └── ***

Ideas? Thank you

like image 826
Jeff Tanner Avatar asked Oct 20 '25 05:10

Jeff Tanner


1 Answers

Not sure if all t's are crossed, but an index file can be used to collate all the custom commands without physically moving them.

/cypress/support/commands-index.js

require('../../cy_test_A/src/commands')
require('../../cy_test_B/src/commands')

Then specify the supportFile to be that index file.

const cypress = require('cypress')

cypress.open({
  reporter: 'junit',
  browser: 'chrome',
  project: '..',
  config: {
    supportFile: './cypress-run-other-project/support/commands-index.js',
    video: true,
  },
  env: {
    login_url: '/login',
    products_url: '/products',
  },
})

But now, whatever else is going on in /cy_test_A/cypress/support/index.js is ignored (for example add-on libraries), so maybe the commands-index.js needs to be

require('../../cy_test_A/cypress/support')
require('../../cy_test_B/cypress/support')

You can check what commands have been loaded with this (in the spec)

it('checks that both custom commands have bee loaded', () => {
  const commands = Cypress.Commands._commands
  expect(commands).to.have.property('checkA')  // command from cy_test_A
  expect(commands).to.have.property('checkB')  // command from cy_test_B
})
like image 52
Fody Avatar answered Oct 22 '25 03:10

Fody



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!