FAQ / @knapsack-pro/cypress / Knapsack Pro Cypress common problems

I'm getting an error when I run Cypress with the --project option

If you use the --project option in Cypress to run tests only from a specified directory like this:

$(npm bin)/knapsack-pro-cypress --project subdirectory

It can lead to a problem when the CI build is rerun with test files cached on the Knapsack Pro API side when you use the environment variable KNAPSACK_PRO_FIXED_QUEUE_SPLIT=true. The recorded test file paths (cached test files) will be relative to the subdirectory instead of the root project directory. When you subsequently retry the CI build, @knapsack-pro/cypress will try to run the test files with paths relative to the subdirectory, even though you are invoking the $(npm bin)/knapsack-pro-cypress command outside of the subdirectory. This can lead to a bug described in the issue.

You need to tell @knapsack-pro/cypress (and not just the Cypress process) which test files should be run.

We recommend using an environment variable KNAPSACK_PRO_TEST_FILE_PATTERN to define a pattern for test files that should be run. Please read this to understand how to define a valid KNAPSACK_PRO_TEST_FILE_PATTERN.

For example, you could run tests from subdirectory this way:

export KNAPSACK_PRO_TEST_FILE_PATTERN="subdirectory/cypress/integration/**/*.{js,jsx,coffee,cjsx}"
$(npm bin)/knapsack-pro-cypress

When you still want to use --project option

If for any reason you need to use the --project option, you could achieve that in the following way. Add a command in your package.json that will enter the subdirectory and execute @knapsack-pro/cypress from it.

  "scripts": {
    "knapsack-pro-cypress-for-subdirectory": "cd subdirectory && knapsack-pro-cypress"

then run it from your CI:

$ npm run knapsack-pro-cypress-for-subdirectory

This way, when you rerun the CI build the above command will run @knapsack-pro/cypress from inside of subdirectory so that the recorded test files during the first CI build run can be loaded properly.

# Knapsack Pro Cypress common problems
See questions outside of this category

  • I'm getting an error when I run Cypress with the --project option

Start using Knapsack Pro

Sign up and speed up your tests.