Home > Enterprise >  How to make Cypress use test files located outside of default integration folder?
How to make Cypress use test files located outside of default integration folder?

Time:04-11

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 located across several folders.

Is is possible to have cypress test files in different folders and appear in the GUI test runner?

CodePudding user response:

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

CodePudding user response:

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.

  • Related