Skip to content
the poor coder

cypress run all files in folder

Poor Man
Published
Reading time
1 min read
On this page

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:

Bash
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:

JSON
{
  "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:

Bash
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:

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

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

JavaScript
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:

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

Keep going

2023

how to sort an array

How to Sort an Array If you have an array and you want to order its elements in a specific way, you need to use a sorting algorithm. There are several sorting algorithms available, but two of the most commonly used are…

javascript2 min read
2023

jquery mobile or desktop

jQuery Mobile or Desktop? As a web developer, I have had some experience with both jQuery Mobile and jQuery Desktop. Both frameworks have their pros and cons, and which one to use really depends on the specific project…

javascript1 min read
2023

node.js folder structure

Node.js Folder Structure If you are new to Node.js, it can be daunting to create a folder structure that will work for your project. The structure you choose will depend on the size and complexity of your project. Here…

javascript1 min read
ESC