testingcypresscypress-component-test-runnercypress-configuration

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


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?


Solution

  • 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.