Socket
Socket
Sign inDemoInstall

jest-changed-files

Package Overview
Dependencies
18
Maintainers
6
Versions
172
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.19%
Maintainers
6
Install size
232 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

29.4.0

Features

  • [expect, @jest/expect-utils] Support custom equality testers (#13654)
  • [jest-config, jest-worker] Use os.availableParallelism if available to calculate number of workers to spawn (#13738)
  • [@jest/globals, jest-mock] Add jest.replaceProperty() that replaces property value (#13496)
  • [jest-haste-map] ignore Sapling vcs directories (.sl/) (#13674)
  • [jest-resolve] Support subpath imports (#13705, #13723, #13777)
  • [jest-runtime] Add jest.isolateModulesAsync for scoped module initialization of asynchronous functions (#13680)
  • [jest-runtime] Add jest.isEnvironmentTornDown function (#13741)
  • [jest-test-result] Added skipped and focused status to FormattedTestResult (#13700)
  • [jest-transform] Support for asynchronous createTransformer (#13762)

Fixes

  • [jest-environment-node] Fix non-configurable globals (#13687)
  • [@jest/expect-utils] toMatchObject should handle Symbol properties (#13639)
  • [jest-mock] Fix mockReset and resetAllMocks undefined return value(#13692)
  • [jest-resolve] Add global paths to require.resolve.paths (#13633)
  • [jest-resolve] Correct node core module detection when using node: specifiers (#13806)
  • [jest-runtime] Support WASM files that import JS resources (#13608)
  • [jest-runtime] Use the scriptTransformer cache in jest-runner (#13735)
  • [jest-runtime] Enforce import assertions when importing JSON in ESM (#12755 & #13805)
  • [jest-snapshot] Make sure to import babel outside of the sandbox (#13694)
  • [jest-transform] Ensure the correct configuration is passed to preprocessors specified multiple times in the transform option (#13770)

Chore & Maintenance

  • [@jest/fake-timers] Update @sinonjs/fake-timers (#13612)
  • [docs] Improve custom puppeteer example to prevent worker warnings (#13619)

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

getChangedFilesForRoots(roots: Array<string>, options: Options): Promise<ChangedFiles>

Get the list of files and repos that have changed since the last commit.

Parameters

roots: Array of string paths gathered from jest roots.

options: Object literal with keys

  • lastCommit: boolean
  • withAncestor: boolean
  • changedSince: string

Returns

A Promise of Object literal with keys

  • changedFiles: Set<string>
  • repos:
    • git: Set<string>
    • hg: Set<string>

findRepos(roots: Array): Promise

Get a set of git and hg repositories.

Parameters

roots: Array of string paths gathered from jest roots.

Returns

A Promise of Object literal with keys

  • git: Set<string>
  • hg: Set<string>

Usage

import {getChangedFilesForRoots} from 'jest-changed-files';

getChangedFilesForRoots(['/path/to/test'], {
  lastCommit: true,
  withAncestor: true,
}).then(files => {
  /*
  {
    repos: [],
    changedFiles: []
  }
  */
});
import {getChangedFilesForRoots} from 'jest-changed-files';

getChangedFilesForRoots(['/path/to/test'], {
  changedSince: 'main',
}).then(files => {
  /*
  {
    repos: [],
    changedFiles: []
  }
  */
});
import {findRepos} from 'jest-changed-files';

findRepos(['/path/to/test']).then(repos => {
  /*
  {
    git: Set<Path>,
    hg: Set<Path>
  }
  */
});

FAQs

Last updated on 24 Jan 2023

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