Find test files impacted by code changes using static dependency analysis.
A userland implementation of predictive test selection for Node.js test runner.
# Run only impacted tests
node --test $(git diff --name-only main | npx impacted)
# Works with any test runner
vitest $(git diff --name-only main | npx impacted)
jest $(git diff --name-only main | npx impacted)
# Custom test pattern
git diff --name-only main | npx impacted -p "src/**/*.spec.js"- uses: sozua/impacted@v1
id: impacted
with:
pattern: '**/*.test.js'
- name: Run impacted tests
if: steps.impacted.outputs.has-impacted == 'true'
run: node --test ${{ steps.impacted.outputs.files }}See action.yml for all inputs and outputs.
import { findImpacted } from 'impacted';
const tests = await findImpacted({
changedFiles: ['src/utils.js'],
testFiles: 'test/**/*.test.js',
cacheFile: '.impacted-cache.json', // optional
});Builds a dependency graph from your test files, inverts it, and walks from changed files to find impacted tests.
src/utils.js (changed)
↓ imported by
src/parser.js
↓ imported by
test/parser.test.js (impacted)
- JavaScript only (
.js,.mjs,.cjs,.jsx) — no TypeScript yet - Static analysis only — dynamic
require(variable)not supported - Local files only —
node_moduleschanges won't trigger tests
- Node.js >= 18
MIT