Skip to content

Commit

Permalink
WIP: --changedFilesSinceCommit=origin/master + hg support
Browse files Browse the repository at this point in the history
  • Loading branch information
alsuren committed Jan 13, 2018
1 parent f845792 commit 57a7181
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 11 deletions.
6 changes: 6 additions & 0 deletions docs/CLI.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@ two times slower._
If you want to inspect the cache, use `--showConfig` and look at the
`cacheDirectory` value. If you need to clear the cache, use `--clearCache`.

### `--changedFilesSinceCommit`

When used together with `--onlyChanged` or `--watch`, it runs tests related the
changes since the provided revision. If the current branch is not a child of the
given commit, then only changes made locally will be tested.

### `--changedFilesWithAncestor`

When used together with `--onlyChanged` or `--watch`, it runs tests related to
Expand Down
48 changes: 48 additions & 0 deletions integration_tests/__tests__/jest_changed_files.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,23 @@ test('gets changed files for git', async () => {
.map(filePath => path.basename(filePath))
.sort(),
).toEqual(['file1.txt', 'file4.txt']);

run(`${GIT} checkout HEAD^^ -b feature-branch`, DIR);

writeFiles(DIR, {
'file5.txt': 'file5',
});
run(`${GIT} commit -am "test5"`, DIR);

({changedFiles: files} = await getChangedFilesForRoots(roots, {
sinceCommit: 'master',
}));
// Returns files from this branch but not ones that only exist on master
expect(
Array.from(files)
.map(filePath => path.basename(filePath))
.sort(),
).toEqual(['file5.txt']);
});

test('gets changed files for hg', async () => {
Expand Down Expand Up @@ -274,4 +291,35 @@ test('gets changed files for hg', async () => {
.map(filePath => path.basename(filePath))
.sort(),
).toEqual(['file1.txt', 'file4.txt']);

run(`${HG} commit -m "test3"`, DIR);

({changedFiles: files} = await getChangedFilesForRoots(roots, {
sinceCommit: '-2',
}));
// Returns files from the last 2 commits
expect(
Array.from(files)
.map(filePath => path.basename(filePath))
.sort(),
).toEqual(['file1.txt', 'file4.txt']);

run(`${HG} bookmark master`, DIR);
// Back up and develop on a different branch
run(`${HG} checkout --rev=-2`, DIR);

writeFiles(DIR, {
'file5.txt': 'file5',
});
run(`${HG} commit -am "test5"`, DIR);

({changedFiles: files} = await getChangedFilesForRoots(roots, {
sinceCommit: 'master',
}));
// Returns files from this branch but not ones that only exist on master
expect(
Array.from(files)
.map(filePath => path.basename(filePath))
.sort(),
).toEqual(['file5.txt']);
});
14 changes: 9 additions & 5 deletions packages/jest-changed-files/src/git.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,19 @@ const adapter: SCMAdapter = {
cwd,
);
} else if (sinceCommit) {
const changed = await findChangedFilesUsingCommand(
['diff', '--name-only', '--diff-filter=ACMR', sinceCommit],
const committed = await findChangedFilesUsingCommand(
['log', '--name-only', '--pretty=%b', 'HEAD', `^${sinceCommit}`],
cwd,
);
const untracked = await findChangedFilesUsingCommand(
['ls-files', '--other', '--exclude-standard'],
const staged = await findChangedFilesUsingCommand(
['diff', '--cached', '--name-only'],
cwd,
);
return changed.concat(untracked);
const unstaged = await findChangedFilesUsingCommand(
['ls-files', '--other', '--modified', '--exclude-standard'],
cwd,
);
return [...committed, ...staged, ...unstaged];
} else {
return await findChangedFilesUsingCommand(
['ls-files', '--other', '--modified', '--exclude-standard'],
Expand Down
7 changes: 2 additions & 5 deletions packages/jest-changed-files/src/hg.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,11 @@ const adapter: SCMAdapter = {
options: Options,
): Promise<Array<Path>> => {
return new Promise((resolve, reject) => {
if (options && options.sinceCommit) {
throw new Error(
'`changedFilesSinceCommit` is not supported in hg repos.',
);
}
let args = ['status', '-amnu'];
if (options && options.withAncestor) {
args.push('--rev', 'ancestor(.^)');
} else if (options && options.sinceCommit) {
args.push(`--rev', 'ancestor(., ${options.sinceCommit})`);
} else if (options && options.lastCommit === true) {
args = ['tip', '--template', '{files%"{file}\n"}'];
}
Expand Down
4 changes: 3 additions & 1 deletion packages/jest-cli/src/cli/args.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,9 @@ export const options = {
changedFilesSinceCommit: {
description:
'When used together with `--onlyChanged` or `--watch`, it runs tests ' +
'related the changes since the provided revision.',
'related the changes since the provided revision. If the current ' +
'branch is not a child of the given commit, then only changes made ' +
'locally will be tested.',
type: 'string',
},
changedFilesWithAncestor: {
Expand Down

0 comments on commit 57a7181

Please sign in to comment.