vitest-affected weekly downloads statistics
By craigvandotcom · npm · Testing
Intelligent test selection for Vitest — run only the tests affected by your changes
vitest-affected has 215 recorded weekly downloads on npm, an increase of 109% over the past 30 days, ranking #2468 of 3,247 tracked listings.
About vitest-affected
vitest-affected
Run only the tests affected by your changes. Zero config, runtime dependency tracking, ~5ms selection overhead.
Full suite: 2,771 tests | 152s
vitest-affected: 22 tests | 3.1s (98% reduction)
Why
Test more often, not just faster.
If you're running AI coding agents — or multiple agents in parallel — each one needs to verify its changes with tests. On a large codebase, running the full suite after every change is either painfully slow or impossible (machine melts). So you skip tests, and bugs slip through.
vitest-affected makes it practical to test after every single change. Each agent runs ~20 tests in seconds instead of 2,771 tests in minutes. You get continuous verification without overloading your machine.
It works by using Vitest's own runtime import data to build an exact reverse dependency map, diffing it against git, and walking the graph to find exactly which tests are impacted. If you change a utility buried three imports deep, only the tests that transitively depend on it will run.
If anything fails — git error, corrupt cache, incomplete graph — it falls back to the full suite with a warning. It never silently skips tests.
Features
- Runtime dependency tracking — uses Vitest's
importDurationsfor exact, real-world dependency data - Transitive dependency tracking — BFS reverse-walk catches changes buried deep in the import chain
- ~5ms selection overhead — delta-parse only changed files, load cached reverse map, BFS select
- Persistent cache — reverse dependency map saved to
.vitest-affected/graph.json, survives CI runs - Self-healing — cache updates after every run via runtime reporter; stale edges automatically pruned
- Config-change detection —
package.json,tsconfig.json,vitest.config.*, lockfile changes trigger full suite - Safe by default — any failure falls back to full suite, deleted files handled as BFS seeds
- Silent-starvation heartbeats — a completed run that collects zero dependency edges, or a selective run that ran a test it didn't select, is flagged loudly (the failure mode that silently no-op'd the plugin for weeks is now observable)
- Shadow mode — run the full pipeline without mutating
include, so a single CI run yields ground truth and the would-be selection — the basis for CI divergence monitoring - Explain trail — ask why any test is (or isn't) selected, via the
explainoption or thevitest-affected-explainCLI - Observability — optional JSON-line stats log for every run
Install
npm install -D vitest-affected
Setup
// vitest.config.ts
import { defineConfig } from 'vitest/config';
import { vitestAffected } from 'vitest-affected';
export default defineConfig({
plugins: [vitestAffected()],
test: {
include: ['tests/**/*.test.ts'],
},
});
That's it. On your next vitest run, only affected tests execute.
How It Works
First run (no cache):
→ Full suite runs
→ Runtime reporter captures importDurations from each test
→ Reverse dependency map saved to .vitest-affected/graph.json
Subsequent runs (cache hit):
git diff → changed files ~2ms
load cached reverse map ~1ms
delta-parse changed files for new imports (oxc) ~5ms
BFS on reverse map → affected test files ~1ms
mutate config.include → Vitest runs only those ───→ 3 tests instead of 300
→ Runtime reporter updates cache for next run
- First run — no cache exists, so the full suite runs. A runtime reporter captures every module each test imports via
importDurations, building an exact reverse dependency map. This is saved to disk. - Subsequent runs — the cached reverse map is loaded (~1ms). Git diff identifies changed files. A fast delta-parse with oxc-parser checks changed files for new imports not yet in the cache (~5ms for 1-5 files). BFS walks the reverse map to find affected tests.
- After every run — the runtime reporter updates the cache with fresh dependency data. Stale edges (removed imports) are automatically pruned via per-test overwrite.
Options
vitestAffected({
// Compare against a specific git ref (default: auto-detect HEAD)
ref: 'main',
// Bypass git diff — provide changed file paths directly
changedFiles: ['/absolute/path/to/changed-file.ts'],
// Fall back to full suite if affected ratio exceeds this (0-1, default: none)
threshold: 0.8,
// Print diagnostic info about graph building and test selection
verbose: true,
// When true, allow 0 affected tests (skip entire suite). Default: false (runs full suite)
allowNoTests: false,
// Enable dependency graph caching to disk (default: true)
cache: true,
// Append JSON-line stats after each run for observability
statsFile: '.vitest-affected/stats.jsonl',
// Extra path prefixes or regexes to ignore from changed-file analysis,
// on top of built-in defaults
ignoreChangedFiles: ['legacy/', /^scripts\/.*\.sh$/],
// Override the default code-extension allowlist
// Default: .ts, .tsx, .js, .jsx, .mts, .cts, .mjs, .cjs, .json
includeChangedExtensions: ['.ts', '.tsx', '.svelte'],
// When true, do not filter caller-provided `changedFiles`
// Default: false (filter still applies — callers shouldn't reimplement policy)
respectProvidedChangedFiles: false,…
Description from the npm listing.
- vitest
- test-selection
- test-impact-analysis
- dependency-graph
- affected-tests
- vitest-plugin
README badge
Show your rank in a README or on your website. The badge updates automatically.
Charts
Images: 30d · 1y · all time · 1600×900 dark
Adoption over time
7/30/90-day growth
Ranking history
Listing placement
Listing placement
Filled points are observed values; hollow points come from Internet Archive snapshots of the listing page. Dashed segments span periods with no observations — values between points are not interpolated.
Each band is one page of 20. Weekly downloads on a linear scale. Placement is projected from weekly downloads, so it can differ from the marketplace's own sort order. Hover a dot to see the listing.
Recent observations
Full history (170)Similar npm Testing plugins
All 20 vitest-affected alternativesData source
Weekly downloads (trailing 7 complete days) come from the official npm downloads API. Downloads include CI and mirrors and are not equivalent to installs or users. npm publishes no ratings.
Listing: https://www.npmjs.com/package/vitest-affected. First seen Oct 16, 2026; last successful collection Dec 6, 2026. See the methodology.