如何在柏树中只运行集成测试



我使用柏树进行组件和e2e测试。两个测试都在同一个文件夹中,用于e2e测试的.test.e2e.js和用于组件测试的.ttest.ct.ts。当我运行组件测试时,我只想测试.test.ct.ts文件,而测试e2e只测试.test.e2e.ts文件。它适用于组件测试,柏树只测试.test.ct.ts文件,但当我运行e2e测试时,柏树也测试.test.cht.ts,这会导致测试失败。

{
"baseUrl": "http://localhost:8080/",
"fixturesFolder": "test/cypress/fixtures",
"integrationFolder": "test/cypress/tests/",
"pluginsFile": "test/cypress/plugins/index.ts",
"screenshotsFolder": "test/cypress/screenshots",
"supportFile": "test/cypress/support/index.ts",
"videosFolder": "test/cypress/videos",
"video": false,
"component": {
"componentFolder": "test/cypress/tests/",
"testFiles": ["**/*.test.ct.ts","**/*.test.ct.js"],
"supportFile": "test/cypress/support/component.ts"
}
}

这是我的柏树配置文件。对于组件测试,我可以配置文件夹和文件,我尝试过集成,但没有成功。我使用的是柏树9.7.0

这是我尝试的配置

{
"baseUrl": "http://localhost:8080/",
"fixturesFolder": "test/cypress/fixtures",
"integration": {
"integrationFolder": "test/cypress/tests/",
"testFiles": ["**/*.test.e2e.ts","**/*.test.e2e.js"]
},
"pluginsFile": "test/cypress/plugins/index.ts",
"screenshotsFolder": "test/cypress/screenshots",
"supportFile": "test/cypress/support/index.ts",
"videosFolder": "test/cypress/videos",
"video": false,
"component": {
"componentFolder": "test/cypress/tests/",
"testFiles": ["**/*.test.ct.ts","**/*.test.ct.js"],
"supportFile": "test/cypress/support/component.ts"
}
}

有什么想法吗?

根据文档,Cypress配置定义的是e2e对象,而不是integration对象。

你可以试试e2e:

{
"baseUrl": "http://localhost:8080/",
"fixturesFolder": "test/cypress/fixtures",
"e2e": {
"integrationFolder": "test/cypress/tests/",
"testFiles": ["**/*.test.e2e.ts","**/*.test.e2e.js"]
},
"pluginsFile": "test/cypress/plugins/index.ts",
"screenshotsFolder": "test/cypress/screenshots",
"supportFile": "test/cypress/support/index.ts",
"videosFolder": "test/cypress/videos",
"video": false,
"component": {
"componentFolder": "test/cypress/tests/",
"testFiles": ["**/*.test.ct.ts","**/*.test.ct.js"],
"supportFile": "test/cypress/support/component.ts"
}
}

有几个选项可以用来制作一个只运行e2e或cypress run组件测试的脚本。最简单的方法是使用--spec选项并将文件夹路径传递给e2e测试。package.json文件


[
"scripts": {
"e2e": "cypress run --spec 'test/cypress/tests/*.test.e2e.js'"
}
]

最新更新