What is jest-changed-files?
The jest-changed-files npm package is a utility that allows you to determine which files have changed in a git or hg (Mercurial) repository. It is often used in testing environments, particularly with Jest, to identify which tests need to be run based on the changes made to the codebase.
What are jest-changed-files's main functionalities?
Getting changed files from a Git repository
This feature allows you to get a list of files that have changed since the last commit in a Git repository. The 'lastCommit' option specifies that only changes from the last commit should be considered.
const { getChangedFilesForRoots } = require('jest-changed-files');
(async () => {
const changedFiles = await getChangedFilesForRoots(['./'], { lastCommit: true });
console.log(changedFiles.changedFiles);
})();
Getting changed files from a Mercurial repository
This feature is similar to the previous one but is used for Mercurial repositories. The 'withAncestor' option can be used to find changes that have occurred since the last common ancestor of the current head and the default branch.
const { getChangedFilesForRoots } = require('jest-changed-files');
(async () => {
const changedFiles = await getChangedFilesForRoots(['./'], { withAncestor: true });
console.log(changedFiles.changedFiles);
})();
Other packages similar to jest-changed-files
git-diff-apply
The git-diff-apply package provides functionality to apply the changes between two commits, branches, or tags. It is similar to jest-changed-files in that it deals with changes in a repository, but it focuses on applying changes rather than just listing them.
node-diff3
node-diff3 is a package for three-way file merging. It compares the differences between files, which can be related to the functionality of jest-changed-files, but it goes further by attempting to merge these differences automatically.
simple-git
simple-git is a light-weight interface for running git commands in any node.js application. It can be used to get a list of changed files, similar to jest-changed-files, but it also provides a full range of commands to manage Git repositories programmatically.