FAQ / @knapsack-pro/cypress / Knapsack Pro Cypress specific questions

How to run tests only from a specific directory in Cypress? Define your test files pattern with KNAPSACK_PRO_TEST_FILE_PATTERN

It is Knapsack Pro responsibility to decide what test files should be run. It means you need to tell Knapsack Pro where to look for your test files on your disk if you keep them in the non-default directory (cypress/integration is a default directory, if you use a different one please read this documentation).

Knapsack Pro does not know and does not care about test file patterns provided to your Cypress test runner as CLI argument or in any of your Cypress config files. It works like that because Knapsack Pro needs to know about all existing test files on your disk before it can decide what test files should be run. It means Knapsack Pro needs to know about your test files before you even start running Cypress - because of that we can't use a pattern from Cypress config file or pattern provided as CLI argument to Cypress itself.

By default Knapsack Pro looks for test files on the disk matching default directory structure like this KNAPSACK_PRO_TEST_FILE_PATTERN="cypress/integration/**/*.{js,jsx,coffee,cjsx}".

You can override this pattern if you set environment variable KNAPSACK_PRO_TEST_FILE_PATTERN on your own (you must use a valid node-glob pattern - read next section!).

Defining your own KNAPSACK_PRO_TEST_FILE_PATTERN might be helpful when you keep your test files in a different directory structure than most users do.


How KNAPSACK_PRO_TEST_FILE_PATTERN works and why it uses node-glob pattern structure?

KNAPSACK_PRO_TEST_FILE_PATTERN pattern is a different type of pattern than a pattern that you are familiar with when working with Cypress. Because of that you cannot copy & paste pattern from Cypress config file to KNAPSACK_PRO_TEST_FILE_PATTERN!

KnapsackPro uses node-glob npm package and its pattern structure to detect test files on the disk.

IMPORTANT: You must learn how to define node-glob pattern to set a valid pattern in KNAPSACK_PRO_TEST_FILE_PATTERN! Learn how node-glob pattern works. We suggest using https://globster.xyz to test what files would match. Often the mistake is that people copy & paste the existing Cypress pattern from your Cypress config file to KNAPSACK_PRO_TEST_FILE_PATTERN and this won't work!


How to set a few directories with test files in KNAPSACK_PRO_TEST_FILE_PATTERN?

If you want to use a few patterns you can provide them comma separated and inside of {}. Do it this way KNAPSACK_PRO_TEST_FILE_PATTERN="{pattern_1,pattern_2}".


Important to understand about KNAPSACK_PRO_TEST_FILE_PATTERN

It is important to understand that KNAPSACK_PRO_TEST_FILE_PATTERN is looking for test files inside of the same directory where you run Knapsack Pro command $(npm bin)/knapsack-pro-cypress. For instance:

  • /home/user/project <- this is a directory with the source code of your project
  • /home/user/project/cypress/integration <- this directory contains all your Cypress test files

When you use above directory structure and you run $(npm bin)/knapsack-pro-cypress inside of the directory /home/user/project then pattern KNAPSACK_PRO_TEST_FILE_PATTERN="cypress/integration/**/*.{js,jsx,coffee,cjsx}" should find all your test files inside of /home/user/project/cypress/integration directory.

If you keep test files in a different folder please adjust KNAPSACK_PRO_TEST_FILE_PATTERN to your directory structure. Remember to provide a valid node-glob pattern!

# Knapsack Pro Cypress specific questions
See questions outside of this category

Start using Knapsack Pro

Sign up and speed up your tests.