如何让 Cypress 使用位于默认集成文件夹之外的测试文件?

发布于 2025-01-20 06:05:55 字数 626 浏览 4 评论 0原文

我正在尝试将我的**。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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

猫九 2025-01-27 06:05:55

在配置文件 cypress.json 中,添加(例如)

{
  ...
  "integrationFolder": ".",
  "testFiles": ["cypress/integration/**/*.spec.js", "src/**/*.test.js"]
}

integrationFolder: "." 指定开始扫描测试文件的项目根目录。

但请注意,可以在 node_modules 中获取测试,因此请使用 testFiles 选项中的位置数组来指示包含项目有效测试的文件夹。

In the configuration file cypress.json, add (for example)

{
  ...
  "integrationFolder": ".",
  "testFiles": ["cypress/integration/**/*.spec.js", "src/**/*.test.js"]
}

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 the testFiles option to indicate folders that have valid tests for your project.

只有一腔孤勇 2025-01-27 06:05:55

在 v13.3.0(可能从版本 10+ 开始)中,配置位于存储库根目录中的 cypress.config.js 中。

添加了 specPattern 行后,应该适合您:

const { defineConfig } = require("cypress");

module.exports = defineConfig({
  component: {
    setupNodeEvents(on, config) {
      // implement node event listeners here
    },
    specPattern: '**/*.spec.js',
  },
});

整个存储库(包括子目录)中的任何文件(带有扩展名 .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:

const { defineConfig } = require("cypress");

module.exports = defineConfig({
  component: {
    setupNodeEvents(on, config) {
      // implement node event listeners here
    },
    specPattern: '**/*.spec.js',
  },
});

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 )

原谅我要高飞 2025-01-27 06:05:55

为什么不删除集成文件夹中的示例测试/文件夹并放入您的呢?

integration
 ├── product
 |   ├── product.js
 |   ├── product.spec.js
 ├── user
 |   ├── user.js
 |   ├── user.spec.js

Why not delete the example tests/folder inside the integration folder and put yours instead?

integration
 ├── product
 |   ├── product.js
 |   ├── product.spec.js
 ├── user
 |   ├── user.js
 |   ├── user.spec.js
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文