Overview
Every CI run of a Jest suite starts from zero and runs every test, even when a change only touches a few files. The @useblacksmith/jest plugin uses dependency tracking to run only the tests affected since the last successful run. It is one wrapper injest.config.js, with no workflow change.
The plugin is in early beta. Options and the cache format may change between releases.
How it works
Each run records the modules and files every test file depends on, throughimport, require, and fs. The next run compares the checkout against that record and runs only the test files that reach a changed file. A test file with no record, or with a test that failed last time, always runs.
On Blacksmith runners, Blacksmith transparently stores this record from run to run, with no extra workflow steps.
Install the plugin
The plugin requires Jest 29 or newer and Node 22.15 or newer.jest now runs the affected selection.
Projects
Inline project objects inprojects are wrapped with the rest of the config. A project given as a path needs the plugin’s runtime in its own config:
Running locally
The same selection applies locally: a run reruns what changed on disk since the last successful run, committed or not. Watch mode is left to Jest.Options
Options are the second argument ofwithBlacksmith.
Limitations
The plugin sets Jest’sruntime and testSequencer and adds a reporter. A config that sets runtime or testSequencer itself is refused, and --reporters on the command line stops the record from updating.
What a test reaches over the network, such as a database or a mock server, is not tracked; declare the files behind it with the dependencies option.
A package changed in place at the same version, such as with patch-package or a git dependency, is not seen as changed.
A run with coverage runs every test.
Verify the selection
The plugin logs every decision with a[blacksmith] prefix in the job output: which records were restored, how many test files are affected, and why each one runs. The first run on a repository has no record and runs everything; compare the test step’s duration across later runs.
A run after a change to one source file restores the record, runs only the test file that depends on it, and saves a new record:
No tests found, exiting with code 0 and the step passes.