赛普拉斯:将测试从多个 npm 依赖项导入“./cypress/integration”?

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

我有一个非常大的基于 Cypress 的测试套件,cy_tests_A_B_monolith,测试数量在 ./cypress/integration 文件夹很大。

我希望将这些集成测试划分到它们自己的 npm 模块中,并使它们成为更易于管理的 Cypress 测试套件的依赖项。

草稿如下。不确定如何将 ./cypress/integration/*** 测试导入到另一个 Cypress 测试套件中。

非常感谢您的建议,谢谢。


草稿:

来自单体

许多集成测试 + src 自定义命令...

npm cy_tests_A_B_monolith

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

至...

通过维护整体测试套件 /cypress/integration 的子集将整体划分为可管理的测试套件

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

有点古怪,但您可以使用 cy_tests_A_B_manageable 中的 Module API 来驱动其他项目的测试

/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',
    },
  })
})

使用 cypress open 它会打开多个跑步者,不理想...

但可以使用 cypress.open(...) 此文件夹设置

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',
  },
})