A module used internally by Jest to check which files have changed since you last committed in git, hg, or sapling repositories.
npx @tessl/cli install tessl/npm-jest-changed-files@30.0.0Jest Changed Files is a utility module used internally by Jest to check which files have changed since the last commit in git, mercurial (hg), or sapling (sl) repositories. It provides file change detection functionality to enable Jest's ability to run tests only for changed code, significantly improving test performance in large codebases.
npm install jest-changed-filesimport { getChangedFilesForRoots, findRepos } from "jest-changed-files";
import type { ChangedFiles, ChangedFilesPromise } from "jest-changed-files";For CommonJS:
const { getChangedFilesForRoots, findRepos } = require("jest-changed-files");import { getChangedFilesForRoots } from "jest-changed-files";
// Get changed files since last commit
const result = await getChangedFilesForRoots(["/path/to/project"], {
lastCommit: true,
withAncestor: false,
});
console.log(result.changedFiles); // Set of changed file paths
console.log(result.repos.git); // Set of git repository pathsAnalyzes version control repositories to identify changed files based on various criteria. Supports git, mercurial (hg), and sapling (sl) repositories with configurable commit range detection.
/**
* Get the list of files and repos that have changed since the last commit or specified reference
* @param roots - Array of string paths (typically Jest roots configuration)
* @param options - Configuration options for change detection
* @returns Promise resolving to object with changedFiles and repos information
*/
function getChangedFilesForRoots(
roots: Array<string>,
options: {
/** Check only the last commit for changes */
lastCommit?: boolean;
/** Include ancestor commit in comparison (uses HEAD^ for git) */
withAncestor?: boolean;
/** Compare changes since specified commit, branch, or tag */
changedSince?: string;
}
): Promise<ChangedFiles>;Usage Examples:
import { getChangedFilesForRoots } from "jest-changed-files";
// Check changes since last commit
const lastCommitChanges = await getChangedFilesForRoots(["/path/to/test"], {
lastCommit: true,
withAncestor: false,
});
// Check changes since specific branch/commit
const branchChanges = await getChangedFilesForRoots(["/path/to/test"], {
changedSince: "main",
});
// Check changes with ancestor comparison
const ancestorChanges = await getChangedFilesForRoots(["/path/to/test"], {
withAncestor: true,
});Discovers version control repositories (git, mercurial, sapling) within specified root directories using concurrent scanning with resource limiting.
/**
* Discover git, hg, and sapling repositories within specified root directories
* @param roots - Array of directory paths to search for repositories
* @returns Promise resolving to object containing Sets of repository paths by VCS type
*/
function findRepos(roots: Array<string>): Promise<{
/** Set of git repository paths */
git: Set<string>;
/** Set of mercurial repository paths */
hg: Set<string>;
/** Set of sapling repository paths */
sl: Set<string>;
}>;Usage Example:
import { findRepos } from "jest-changed-files";
const repos = await findRepos(["/path/to/search", "/another/path"]);
console.log(repos.git); // Set<string> of git repository paths
console.log(repos.hg); // Set<string> of mercurial repository paths
console.log(repos.sl); // Set<string> of sapling repository pathsinterface ChangedFiles {
/** Repository information organized by VCS type */
repos: {
/** Set of git repository paths */
git: Set<string>;
/** Set of mercurial repository paths */
hg: Set<string>;
/** Set of sapling repository paths */
sl: Set<string>;
};
/** Set of absolute file paths that have changed */
changedFiles: Set<string>;
}
type ChangedFilesPromise = Promise<ChangedFiles>;