Skip to content

About

Test impact analysis engine - dependency graph, git diff parsing, affected test detection, minimal execution plans. Run only the tests that matter. TypeScript/Node.js + Docker + GitHub Actions CI.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Test Impact Analyzer

CI Pipeline TypeScript Node.js Docker Jest License: MIT

Test impact analysis engine - maps source code dependencies to test files, detects which tests are affected by a git diff, and produces a minimal test execution plan. Run only what matters.

Features

  • Dependency Graph Builder - Parse imports/requires to build source-to-test mapping
  • Git Diff Analysis - Parse changed files from any git diff (PR, commit, branch comparison)
  • Transitive Impact - Follow the dependency chain to find all affected tests
  • Execution Plan - Output minimal test paths for Jest, Playwright, or any runner
  • Reduction Metrics - Calculate percentage of tests saved vs. running everything
  • Circular Import Safety - Handles circular dependencies without infinite loops

How It Works

+---------------+     +-----------------+     +----------------------+     +----------------+
|   Git Diff    |---->|  Changed Files  |---->|  Dependency Graph    |---->|   Affected     |
|   (input)     |     |  (parsed)       |     |  Lookup (BFS)        |     |   Tests        |
+---------------+     +-----------------+     +----------------------+     +--------+-------+
                                                                                    |
                                                                                    v
                                                                           +----------------+
                                                                           |  Execution     |
                                                                           |  Plan          |
                                                                           +----------------+

Flow:

  1. Parse git diff output (--name-status format) to extract changed files
  2. Look up each changed file in the dependency graph
  3. Traverse importedBy edges (BFS) to find all transitive dependents
  4. Filter results to only test files
  5. Produce a minimal execution plan with reduction metrics

Programmatic Usage

import { buildDependencyGraph, FileContent } from './graph';
import { parseDiffOutput } from './diff';
import { analyzeImpact } from './impact';

// 1. Parse your git diff
const diffOutput = 'M\tsrc/utils/helpers.ts\nA\tsrc/services/new-service.ts';
const diff = parseDiffOutput(diffOutput);

// 2. Build dependency graph from your source files
const files: FileContent[] = [
  { filePath: 'src/utils/helpers.ts', content: '...' },
  { filePath: 'src/services/user.ts', content: "import { x } from '../utils/helpers';" },
  { filePath: 'tests/user.test.ts', content: "import { svc } from '../src/services/user';" },
];
const graph = buildDependencyGraph(files);

// 3. Analyze impact
const allTests = ['tests/user.test.ts', 'tests/other.test.ts'];
const result = analyzeImpact(diff.all, graph, allTests);

console.log(result);
// {
//   changedFiles: ['src/utils/helpers.ts', 'src/services/new-service.ts'],
//   affectedTests: ['tests/user.test.ts'],
//   totalTests: 2,
//   impactedTests: 1,
//   reductionPercent: 50,
//   executionPlan: ['--testPathPattern="tests/user.test.ts"']
// }

Dependency Graph

The dependency graph builder parses TypeScript/JavaScript files for import relationships:

Supported patterns:

  • ES Modules: import { x } from './module'
  • CommonJS: const x = require('./module')
  • Re-exports: export { x } from './module'

How it works:

  1. Regex-based parsing extracts import paths from each file
  2. Relative paths are resolved to normalized file paths
  3. Bidirectional edges are created (imports and importedBy)
  4. The graph supports BFS traversal for transitive dependency lookup

Git Diff Parsing

Parses the output of git diff --name-status:

Input:

M       src/services/auth.ts
A       src/services/oauth.ts
D       src/legacy/old-auth.ts
R100    src/utils/old.ts    src/utils/new.ts

Output:

{
  "added": ["src/services/oauth.ts", "src/utils/new.ts"],
  "modified": ["src/services/auth.ts"],
  "deleted": ["src/legacy/old-auth.ts"],
  "all": ["src/services/oauth.ts", "src/utils/new.ts", "src/services/auth.ts", "src/legacy/old-auth.ts"]
}

Impact Analysis

Given a codebase with 200 test files, here is a typical scenario:

Changed Files:  3 (src/auth/token.ts, src/auth/validate.ts, src/utils/crypto.ts)
Total Tests:    200
Affected Tests: 12
Reduction:      94%

Execution Plan:
  --testPathPattern="tests/auth/token.test.ts"
  --testPathPattern="tests/auth/validate.test.ts"
  --testPathPattern="tests/auth/integration.test.ts"
  ... (9 more)

Instead of running all 200 tests, you run only 12 - saving 94% of CI time.

API Endpoints

Method Endpoint Description
GET /api/health Service health check

Health Check Response

{
  "status": "healthy",
  "service": "test-impact-analyzer",
  "version": "1.0.0",
  "uptime": 123.456,
  "timestamp": "2026-01-15T10:30:00.000Z"
}

Configuration

Variable Default Description
PORT 3007 Server port
NODE_ENV development Environment (development/production)
LOG_LEVEL info Winston log level

CI/CD Pipeline

The GitHub Actions pipeline runs on every push and PR to main, master, and develop:

  1. Lint and Type Check - ESLint + TypeScript compiler validation
  2. Unit Tests - Jest with coverage reporting
  3. Docker Build - Multi-stage build + health check verification

Docker

# Build the image
docker build -t test-impact-analyzer .

# Run the container
docker run -p 3007:3007 test-impact-analyzer

# Or use docker-compose
docker-compose up

Author

Darrius Jones

License

MIT - 2026 Darrius Jones

See LICENSE for details.

About

Test impact analysis engine - dependency graph, git diff parsing, affected test detection, minimal execution plans. Run only the tests that matter. TypeScript/Node.js + Docker + GitHub Actions CI.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages