Find test files impacted by code changes. Takes a list of changed files, builds a dependency graph by statically analyzing imports, and returns only the tests that depend on what changed.
# Run only impacted tests (--since gets changed files from git diff)
node --test $(npx impacted --since main)
# Pipe changed files from stdin
node --test $(git diff --name-only main | npx impacted)
# Works with any test runner
vitest $(npx impacted --since main)
jest $(npx impacted --since main)
# Custom test pattern
npx impacted --since main -p "src/**/*.spec.js"
# Multiple patterns
npx impacted --since main -p "test/**/*.test.js" -p "test/**/*.spec.js"- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: sozua/impacted@v1
id: impacted
with:
pattern: '**/*.{test,spec}.{js,mjs,cjs,jsx,ts,mts,cts,tsx}' # default
- 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
});import { run } from 'node:test';
import { findImpacted } from 'impacted';
const files = await findImpacted({
changedFiles: ['src/utils.js'],
testFiles: 'test/**/*.test.js',
});
run({ files });See examples/05-node-test-run for a full working example.
TypeScript files (.ts, .mts, .cts, .tsx) are supported out of the box on Node.js >= 22.7. Type stripping is handled via node:module.stripTypeScriptTypes(), no additional dependencies required.
Follows Node.js core's TypeScript philosophy: explicit extensions, no tsconfig.json, no path aliases.
- Static analysis only, dynamic
require(variable)is not supported - Local files only,
node_moduleschanges won't trigger tests - TypeScript support requires Node.js >= 22.7 (JS analysis works on Node.js >= 18)
- Node.js >= 18 (TypeScript support requires >= 22.7)
MIT