如何让 Cypress 使用位于默认集成文件夹之外的测试文件?
我正在尝试将我的**。spec.js
文件保留在需要进行测试的实际文件旁边测试的文件:
.
├── product
| ├── product.js
| ├── product.spec.js
├── user
| ├── user.js
| ├── user.spec.js
上述*。spec.js
文件>文件不要出现在赛普拉斯测试跑者窗口中,我找不到如何添加它们。
它仅显示./ cypress/Integration
文件夹的内容,其中包含Cypress包含的示例测试。
我知道您可以更改配置默认文件夹(cypress/Integrations
)用于测试,但我的*。spec.js
文件分布在几个不同的文件夹中。
是否可以在不同文件夹中放入柏树测试文件并出现在GUI测试跑者中?
I am trying to keep my **.spec.js
files for testing next to the actual files that need to be tested like such:
.
├── product
| ├── product.js
| ├── product.spec.js
├── user
| ├── user.js
| ├── user.spec.js
The above *.spec.js
files don't appear in the cypress test runner window and I can't find out how to add them.
It only the displays the contents of the ./cypress/integration
folder which contains the example tests included by cypress.
I know you can change the configuration of Cypress to look at a different default folder (other than cypress/integrations
) for tests but my *.spec.js
files are spread across several different folders.
Is is possible to have cypress test files in different folders and appear in the GUI test runner?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在配置文件 cypress.json 中,添加(例如)
integrationFolder: "."
指定开始扫描测试文件的项目根目录。但请注意,可以在
node_modules
中获取测试,因此请使用testFiles
选项中的位置数组来指示包含项目有效测试的文件夹。In the configuration file
cypress.json
, add (for example)integrationFolder: "."
designates the project root to start scan for test files.But be careful, can pick up tests in
node_modules
, so use an array of locations in thetestFiles
option to indicate folders that have valid tests for your project.在 v13.3.0(可能从版本 10+ 开始)中,配置位于存储库根目录中的 cypress.config.js 中。
添加了 specPattern 行后,应该适合您:
整个存储库(包括子目录)中的任何文件(带有扩展名 .spec.js)都应该匹配现在。
组件测试的官方文档:
https://docs.cypress.io/guides/references/配置#component
(我有类似的问题,但对于端到端测试,解决方案位于 QA/测试门户上:
https://sqa.stackexchange。 com/questions/52091/cypress-js-how-to-change-default-path-for-your-e2e-tests)
in v13.3.0 (and probably from version 10+), config is in the cypress.config.js, in the repo's root.
this, with added specPattern line, should work for you:
any file(s) in entire repo (including sub-direrctories), with extensions .spec.js, should match now.
official documentation for component tests:
https://docs.cypress.io/guides/references/configuration#component
( i had similar problem, but for end-2-end tests and solution is on the QA/Test portal:
https://sqa.stackexchange.com/questions/52091/cypress-js-how-to-change-default-path-for-your-e2e-tests )
为什么不删除集成文件夹中的示例测试/文件夹并放入您的呢?
Why not delete the example tests/folder inside the integration folder and put yours instead?