diff --git a/packages/jest-changed-files/README.md b/packages/jest-changed-files/README.md index bed7ebd44d5f..cc9b0afb2a11 100644 --- a/packages/jest-changed-files/README.md +++ b/packages/jest-changed-files/README.md @@ -11,38 +11,50 @@ $ npm install --save jest-changed-files ## API -### `hg.isHGRepository(cwd: string): Promise` +### `getChangedFilesForRoots(roots: >, options: ?object): Promise` -Get the root of the mercurial repository containing `cwd` or return `null` if -`cwd` is not inside a mercurial repository. +Get the list of files and repos that have changed since the last commit. -### `git.isGitRepository(cwd: string): Promise` +#### Parameters +roots: Array of string paths gathered from [jest roots](https://facebook.github.io/jest/docs/configuration.html#roots-array-string). -Get the root of the git repository containing `cwd` or return `null` if -`cwd` is not inside a git repository. +options: Object literal with keys +* lastCommit: boolean +* withAncestor: boolean -### `hg.findChangedFiles / git.findChangedFiles (root: string): Promise>` +### findRepos(roots: >): Promise -Get the list of files in a git/mecurial repository that have changed since the -last commit. +Get a set of git and hg repositories. +#### Parameters +roots: Array of string paths gathered from [jest roots](https://facebook.github.io/jest/docs/configuration.html#roots-array-string). ## Usage ```javascript -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'); - } - }); -} +import {getChangedFilesForRoots} from 'jest-changed-files'; + +getChangedFilesForRoots(['/path/to/test'], { + lastCommit: true, + withAncestor: true, +}).then((files) => { + /* + { + repos: [], + changedFiles: [] + } + */ +}); +``` + +```javascript +import {findRepos} from 'jest-changed-files'; + +findRepos(['/path/to/test']).then((repos) => { + /* + { + git: Set, + hg: Set + } + */ +}); ```