2

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?

volume one
  • 6,800
  • 13
  • 67
  • 146

2 Answers2

2

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.

Fody
  • 23,754
  • 3
  • 20
  • 37
-2

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
aldrine00
  • 51
  • 1
  • 9
  • 2
    The idea is the `spec.js` files should be together with the file to be tested. If they are in separate folders its hard to cross-reference. Some guidance here https://blog.risingstack.com/node-hero-node-js-project-structure-tutorial – volume one Apr 11 '22 at 11:33