Skip to content
/ impacted Public

Static dependency analysis to find which tests are impacted by code changes.

Notifications You must be signed in to change notification settings

sozua/impacted

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

impacted

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.

npm version

Usage

# 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"

GitHub Action

- 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.

Programmatic API

import { findImpacted } from 'impacted';

const tests = await findImpacted({
  changedFiles: ['src/utils.js'],
  testFiles: 'test/**/*.test.js',
  cacheFile: '.impacted-cache.json', // optional
});

node:test run() integration

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

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.

Limitations

  • Static analysis only, dynamic require(variable) is not supported
  • Local files only, node_modules changes won't trigger tests
  • TypeScript support requires Node.js >= 22.7 (JS analysis works on Node.js >= 18)

Requirements

  • Node.js >= 18 (TypeScript support requires >= 22.7)

License

MIT