Socket
Socket
Sign inDemoInstall

jest-changed-files

Package Overview
Dependencies
0
Maintainers
3
Versions
174
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    jest-changed-files

A module used internally by Jest to check which files have changed since you last committed in git or hg.


Version published
Weekly downloads
22M
decreased by-2.88%
Maintainers
3
Install size
6.39 kB
Created
Weekly downloads
 

Package description

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

Changelog

Source

jest 20.0.1

  • Add ansi-regex to pretty-format dependencies (#3498)
  • Fix <rootDir> replacement in testMatch and moduleDirectories (#3538)
  • Fix expect.hasAssertions() to throw when passed arguments (#3526)
  • Fix stack traces without proper error messages (#3513)
  • Fix support for custom extensions through haste packages (#3537)
  • Fix test contexts between test functions (#3506)

Readme

Source

jest-changed-files

A module used internally by Jest to check which files have changed since you last committed in git or hg.

Install

$ npm install --save jest-changed-files

API

hg.isHGRepository(cwd: string): Promise<?string>

Get the root of the mercurial repository containing cwd or return null if cwd is not inside a mercurial repository.

git.isGitRepository(cwd: string): Promise<?string>

Get the root of the git repository containing cwd or return null if cwd is not inside a git repository.

hg.findChangedFiles / git.findChangedFiles (root: string): Promise<Array<string>>

Get the list of files in a git/mecurial repository that have changed since the last commit.

Usage

import {git, hg} from 'jest-changed-files';

function changedFiles(cwd) {
  return Promise.all([
    git.isGitRepository(cwd),
    hg.isHGRepository(cwd),
  ]).then(([gitRoot, hgRoot]) => {
    if (gitRoot !== null) {
      return git.findChangedFiles(gitRoot);
    } else if (hgRoot !== null) {
      return hg.findChangedFiles(hgRoot);
    } else {
      throw new Error('Not in a git or hg repo');
    }
  });
}

FAQs

Last updated on 11 May 2017

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc