cypress run all files in folder

hljs.highlightAll();

Cypress Run All Files in Folder

If you are using Cypress, you may want to run all the test files in a certain folder. There are a few ways to do this.

Using the Cypress Command Line Interface (CLI)

The easiest way to run all test files in a folder is to use the Cypress CLI. In your terminal, navigate to your project directory and enter the following command:

cypress run --spec "cypress/integration/folder/*.js"

This command will run all the JavaScript files in the "folder" directory inside the "integration" directory. You can replace "folder" with the name of your folder.

Using a Custom Script in package.json

If you prefer to use a custom script in your package.json file, you can add the following script:

{
  "scripts": {
    "test:folder": "cypress run --spec \"cypress/integration/folder/*.js\""
  }
}

You can replace "folder" with the name of your folder. Then, to run all the test files in that folder, you can simply enter the following command in your terminal:

npm run test:folder

Using a Plugin

Finally, you can also use a plugin to run all the test files in a folder. One such plugin is cypress-select-tests. To use this plugin, you need to install it:

npm install --save-dev cypress-select-tests

Then, in your cypress/plugins/index.js file, add the following code:

const selectTestsWithGlob = require('cypress-select-tests/glob')

module.exports = (on, config) => {
  on('file:preprocessor', selectTestsWithGlob(config))
}

This code will allow you to use glob patterns to select which tests to run. For example, to run all the tests in the "folder" directory, you can enter the following command:

cypress run --env TESTS_FILE_PATTERN="**/folder/*.spec.js"

Subscribe to The Poor Coder | Algorithm Solutions

Don’t miss out on the latest issues. Sign up now to get access to the library of members-only issues.
[email protected]
Subscribe