FAQ / @knapsack-pro/jest / Knapsack Pro Jest specific questions

How to run tests only from specific directory in Jest?

You can modify a default test file pattern KNAPSACK_PRO_TEST_FILE_PATTERN="{**/__tests__/**/*.js?(x),**/?(*.)(spec|test).js?(x)}". Set KNAPSACK_PRO_TEST_FILE_PATTERN environment variable and change pattern to match your directory with test files. The pattern uses glob pattern. It is not regexp.


The default pattern KNAPSACK_PRO_TEST_FILE_PATTERN="{**/__tests__/**/*.js?(x),**/?(*.)(spec|test).js?(x)}" in @knapsack-pro/jest matches a few directories {pattern1,pattern2}. If your tests are in single directory don't use {}. Instead, if you want to use single pattern then you can do KNAPSACK_PRO_TEST_FILE_PATTERN="__tests__/**/*.test.js".


Note @knapsack-pro/jest by default rejects tests inside of node_modules directory. If your pattern set by KNAPSACK_PRO_TEST_FILE_PATTERN matches test file paths within node_modules then those test file paths won't be run.

If you want to use a few patterns you can do it as shown above KNAPSACK_PRO_TEST_FILE_PATTERN="{pattern_1,pattern_2}".

You can also exclude tests for Jest and please note @knapsack-pro/jest rejects patterns from Jest config file.

Start using Knapsack Pro

Sign up and speed up your tests.