赛普拉斯:父包运行其 cypress/integration 测试及其依赖项 cypress/integration 测试
Cypress: parent package runs its cypress/integration test and its dependencies cypress/integration tests
问题:父 Cypress npm 项目 import/add/run Cypress 是否可以测试其依赖项 Cypress npm 项目?
问题的回答是 link 有效,将一个单一的 Cypress 测试包分解为多个 Cypress 测试包并使用 Module API。但是,我不得不重新考虑我的问题。我没有解决的是 npm cypress 包之间存在依赖关系(自定义命令)。
示例:
- npm package
cy_test_A
依赖于 npm package cy_test_B
自定义命令,
- npm package
cy_test_B
依赖于 npm package cy_test_C
自定义命令。
这些软件包中的每一个都有用于规范的 cypress 集成和用于自定义命令的 src:
cy_test_***
├── cypress
│ ├── integration
│ │ └── tests
│ └── support
│ └── specs
├── src
│ └── commands
Cypress 集成测试可以从其依赖项中导入吗?当我执行测试 运行 时,我想看到一个组合测试,包括 dependencies' cypress tests + parent's cypress test .
npm package cy_test_A
依赖于 npm package cy_test_B
中的自定义命令,用于cy_test_A
赛普拉斯集成测试。在构建 npm 包 cy_test_B
时,它在提交到 npm 存储库之前有自己的 cypress 集成测试。 我想要 cy_test_A
到 运行 它自己的 cypress 集成测试但是 cypress 集成测试它的依赖性 cy_test_B
也是。
├── 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**
│ └── ***
│ └── ***
想法?谢谢
不确定是否所有的 t's 都交叉了,但是可以使用索引文件来整理所有自定义命令而无需物理移动它们。
/cypress/support/commands-index.js
require('../../cy_test_A/src/commands')
require('../../cy_test_B/src/commands')
然后将 supportFile
指定为该索引文件。
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',
},
})
但是现在,/cy_test_A/cypress/support/index.js
中发生的任何其他事情都将被忽略(例如 add-on 库),所以也许 commands-index.js
需要
require('../../cy_test_A/cypress/support')
require('../../cy_test_B/cypress/support')
你可以检查哪些命令已经加载了这个(在规范中)
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
})
问题:父 Cypress npm 项目 import/add/run Cypress 是否可以测试其依赖项 Cypress npm 项目?
问题的回答是 link 有效,将一个单一的 Cypress 测试包分解为多个 Cypress 测试包并使用 Module API。但是,我不得不重新考虑我的问题。我没有解决的是 npm cypress 包之间存在依赖关系(自定义命令)。
示例:
- npm package
cy_test_A
依赖于 npm packagecy_test_B
自定义命令, - npm package
cy_test_B
依赖于 npm packagecy_test_C
自定义命令。
这些软件包中的每一个都有用于规范的 cypress 集成和用于自定义命令的 src:
cy_test_***
├── cypress
│ ├── integration
│ │ └── tests
│ └── support
│ └── specs
├── src
│ └── commands
Cypress 集成测试可以从其依赖项中导入吗?当我执行测试 运行 时,我想看到一个组合测试,包括 dependencies' cypress tests + parent's cypress test .
npm package cy_test_A
依赖于 npm package cy_test_B
中的自定义命令,用于cy_test_A
赛普拉斯集成测试。在构建 npm 包 cy_test_B
时,它在提交到 npm 存储库之前有自己的 cypress 集成测试。 我想要 cy_test_A
到 运行 它自己的 cypress 集成测试但是 cypress 集成测试它的依赖性 cy_test_B
也是。
├── 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**
│ └── ***
│ └── ***
想法?谢谢
不确定是否所有的 t's 都交叉了,但是可以使用索引文件来整理所有自定义命令而无需物理移动它们。
/cypress/support/commands-index.js
require('../../cy_test_A/src/commands')
require('../../cy_test_B/src/commands')
然后将 supportFile
指定为该索引文件。
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',
},
})
但是现在,/cy_test_A/cypress/support/index.js
中发生的任何其他事情都将被忽略(例如 add-on 库),所以也许 commands-index.js
需要
require('../../cy_test_A/cypress/support')
require('../../cy_test_B/cypress/support')
你可以检查哪些命令已经加载了这个(在规范中)
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
})