Knapsack Pro

Check out the new docs for the updated documentation.

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

How to run Jest tests locally with Knapsack Pro?

You can run Jest tests using @knapsack-pro/jest on your local machine instead of the CI environment. Running tests locally can be useful if you need to quickly test your configuration before running changes on the CI server.

Create a bash script bin/knapsack_pro_jest with the following content:


#!/bin/bash

# The CI build ID must have the same value if you would like to simulate running tests on 2 parallel nodes. You could set the value manually.
# Alternatively, you can use openssl to generate a unique CI build ID. This way running the bash script would simulate running a new CI build.
export CI_BUILD_ID=$(openssl rand -base64 32)

KNAPSACK_PRO_TEST_SUITE_TOKEN_JEST=your_API_token \
KNAPSACK_PRO_TEST_FILE_PATTERN="{**/__tests__/**/*.js?(x),**/?(*.)(spec|test).js?(x)}"
KNAPSACK_PRO_LOG_LEVEL=info \
KNAPSACK_PRO_CI_NODE_BUILD_ID=$CI_BUILD_ID \
KNAPSACK_PRO_CI_NODE_TOTAL=${2:-2} \
KNAPSACK_PRO_CI_NODE_INDEX=${1:-0} \
$(npm bin)/knapsack-pro-jest --runInBand

Then run the following command locally to simulate running tests on the parallel node with index 0 (it's the 1st node out of 2). Note index starts from 0.

bin/knapsack_pro_jest 0 2

Simulate running tests on the node with index 1 (it's the 2nd node out of 2).

bin/knapsack_pro_jest 1 2

Start using Knapsack Pro

Sign up and speed up your tests.