Skip to content

Affected Tests in CI

codegraph affected traces import dependencies transitively to find which test files are affected by a set of changed source files — so CI can run only the relevant tests.

Terminal window
codegraph affected src/utils.ts src/api.ts # pass files as arguments
git diff --name-only | codegraph affected --stdin # pipe from git diff
codegraph affected src/auth.ts --filter "e2e/*" # custom test-file pattern
OptionDescriptionDefault
--stdinRead the file list from stdinfalse
-d, --depth <n>Max dependency traversal depth5
-f, --filter <glob>Custom glob to identify test filesauto-detect
-j, --jsonOutput as JSONfalse
-q, --quietOutput file paths onlyfalse
#!/usr/bin/env bash
AFFECTED=$(git diff --name-only HEAD | codegraph affected --stdin --quiet)
if [ -n "$AFFECTED" ]; then
npx vitest run $AFFECTED
fi