47

When I install and run cypress, it scaffolds a cypress/ folder in the root of my project.

The problem is that all other test related data is stored in the test/ folder. Is there an easy way to move it to test/cypress and configure cypress to look there?

Gleb Kostyunin
  • 3,743
  • 2
  • 19
  • 36

4 Answers4

64

Cypress has a few configuration options to specify custom folder structure.

For that you will need to have cypress.json file in the root of your project and specify the following structure there for cypress to properly pick up the files in test/cypress/:

{
  "fixturesFolder": "test/cypress/fixtures",
  "integrationFolder": "test/cypress/integration",
  "pluginsFile": "test/cypress/plugins/index.js",
  "screenshotsFolder": "test/cypress/screenshots",
  "videosFolder": "test/cypress/videos",
  "downloadsFolder": "test/cypress/downloads",
  "supportFile": "test/cypress/support/index.js"
}

More info in the cypress docs.

karuhanga
  • 3,010
  • 1
  • 27
  • 30
Gleb Kostyunin
  • 3,743
  • 2
  • 19
  • 36
22

If you want to directly specify from the command line which one to launch, you can use the project flag:

cypress open --project test

That's particularly useful if you have a monorepo with multiple cypress folders to test different apps.

project option direct link

example repo with usage

cypress run cli documentation

SgtPooki
  • 11,012
  • 5
  • 37
  • 46
maxime1992
  • 22,502
  • 10
  • 80
  • 121
  • 1
    Nice and clean! – Daan Jan 08 '20 at 14:45
  • 2
    Just a note, for me `cypress open --project test` had the expected result of running/placing the cypress tests in the `test/cypress` folder. When I ran the command as provided in this answer, it created additional tests at `test/cypress/cypress`. – totalhack Sep 22 '20 at 19:37
  • This should be the accepted answer, since nobody wants to configure every possible cypress folder in the config just because the main path is different from the default one. – Krisztián Balla Apr 06 '22 at 07:16
2

If you are looking to move your Cypress "installation" directory which is being created when executing cypress open or cypress run, I suggest to follow this steps:

1) Run cypress with --project <directory> flag where directory is where you would like cypress to be installed. In my case I chose test directory:

cypress open --project test

2) Cypress should now create its startup directory in /test/cypress folder. Add your cypress.json file directly under /test (!) directory. If you are using TypeScript, you can add your tsconfig.json file there too.

3) In your cypress.json you can relatively configure your tests subdirectories. My file is:

{
  "projectId": "XXXXXX",
  "fixturesFolder": "cypress/fixtures",
  "integrationFolder": "ui",
  "screenshotsFolder": "cypress/screenshots",
  "videosFolder": "cypress/videos"
}

which means that my tests are under /test/ui directory and the rest within /cypress. I keep only fixtures, plugins, screenshots, videos, support dirs and the rest removed.

Works without issues. I hope that helps.

Greg Wozniak
  • 5,209
  • 3
  • 26
  • 29
0

Cypress tests have the following file structure.

cypress ├── fixtures │   └── example.json ├── integration │   └── example_spec.js ├── plugins │   └── index.js └── support ├── commands.js └── index.js | |__ cypress.json

You have to move this file structure to /test/. By default cypress.json points to the immediate cypress folder.

Otherwise, You can define the configuration in cypress.json file as @GlebKost mentioned in above answer.