Skip to content

Commit

Permalink
rename; reorder; fix CLI.md
Browse files Browse the repository at this point in the history
  • Loading branch information
alsuren committed Jan 15, 2018
1 parent cccbb01 commit 9e6409a
Show file tree
Hide file tree
Showing 14 changed files with 36 additions and 35 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
* `[jest-cli]` Make Jest exit without an error when no tests are found in the
case of `--lastCommit`, `--findRelatedTests`, or `--onlyChanged` options
having been passed to the CLI
* `[jest-cli]` Allow selectively running tests for code changed since arbitrary
revisions. ([#5188](https://github.com/facebook/jest/pull/5188))
* `[jest-cli]` `--changedSince`: allow selectively running tests for code
changed since arbitrary revisions.
([#5312](https://github.com/facebook/jest/pull/5312))

### Fixes
* `[jest-cli]` Use `import-local` to support global Jest installations.
Expand Down
12 changes: 6 additions & 6 deletions docs/CLI.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,17 +103,17 @@ 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`.

### `--changedFilesToContributeTo`

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`

Runs tests related to the current changes and the changes made in the last
commit. Behaves similarly to `--onlyChanged`.

### `--changedSince`

Runs tests related the changes since the provided branch. If the current branch
has diverged from the given branch, then only changes made locally will be
tested. Behaves similarly to `--onlyChanged`.

### `--ci`

When this option is provided, Jest will assume it is running in a CI
Expand Down
8 changes: 4 additions & 4 deletions integration-tests/__tests__/jest_changed_files.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ test('gets changed files for git', async () => {
run(`${GIT} commit -m "test3"`, DIR);

({changedFiles: files} = await getChangedFilesForRoots(roots, {
toContributeTo: 'HEAD^^',
changedSince: 'HEAD^^',
}));
// Returns files from the last 2 commits
expect(
Expand All @@ -214,7 +214,7 @@ test('gets changed files for git', async () => {
run(`${GIT} commit -m "test5"`, DIR);

({changedFiles: files} = await getChangedFilesForRoots(roots, {
toContributeTo: 'master',
changedSince: 'master',
}));
// Returns files from this branch but not ones that only exist on master
expect(
Expand Down Expand Up @@ -297,7 +297,7 @@ test('gets changed files for hg', async () => {
run(`${HG} commit -m "test3"`, DIR);

({changedFiles: files} = await getChangedFilesForRoots(roots, {
toContributeTo: '-3',
changedSince: '-3',
}));
// Returns files from the last 2 commits
expect(
Expand All @@ -317,7 +317,7 @@ test('gets changed files for hg', async () => {
run(`${HG} commit -m "test4"`, DIR);

({changedFiles: files} = await getChangedFilesForRoots(roots, {
toContributeTo: 'master',
changedSince: 'master',
}));
// Returns files from this branch but not ones that only exist on master
expect(
Expand Down
8 changes: 4 additions & 4 deletions packages/jest-changed-files/src/git.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,17 @@ const adapter: SCMAdapter = {
cwd: string,
options?: Options,
): Promise<Array<Path>> => {
const toContributeTo: ?string =
options && (options.withAncestor ? 'HEAD^' : options.toContributeTo);
const changedSince: ?string =
options && (options.withAncestor ? 'HEAD^' : options.changedSince);

if (options && options.lastCommit) {
return await findChangedFilesUsingCommand(
['show', '--name-only', '--pretty=%b', 'HEAD'],
cwd,
);
} else if (toContributeTo) {
} else if (changedSince) {
const committed = await findChangedFilesUsingCommand(
['log', '--name-only', '--pretty=%b', 'HEAD', `^${toContributeTo}`],
['log', '--name-only', '--pretty=%b', 'HEAD', `^${changedSince}`],
cwd,
);
const staged = await findChangedFilesUsingCommand(
Expand Down
4 changes: 2 additions & 2 deletions packages/jest-changed-files/src/hg.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ const adapter: SCMAdapter = {
let args = ['status', '-amnu'];
if (options && options.withAncestor) {
args.push('--rev', 'ancestor(.^)');
} else if (options && options.toContributeTo) {
args.push('--rev', `ancestor(., ${options.toContributeTo})`);
} else if (options && options.changedSince) {
args.push('--rev', `ancestor(., ${options.changedSince})`);
} else if (options && options.lastCommit === true) {
args = ['tip', '--template', '{files%"{file}\n"}'];
}
Expand Down
16 changes: 8 additions & 8 deletions packages/jest-cli/src/cli/args.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const check = (argv: Argv) => {
'onlyChanged',
'lastCommit',
'changedFilesWithAncestor',
'changedFilesToContributeTo',
'changedSince',
]) {
if (argv[key]) {
argv.onlyChanged = true;
Expand Down Expand Up @@ -112,20 +112,20 @@ export const options = {
' dependency information.',
type: 'string',
},
changedFilesToContributeTo: {
changedFilesWithAncestor: {
description:
'Runs tests related to the current changes and the changes made in the ' +
'last commit. Behaves similarly to `--onlyChanged`.',
type: 'boolean',
},
changedSince: {
description:
'Runs tests related the changes since the provided branch. If the ' +
'current branch has diverged from the given branch, then only changes ' +
'made locally will be tested. Behaves similarly to `--onlyChanged`.',
nargs: 1,
type: 'string',
},
changedFilesWithAncestor: {
description:
'Runs tests related to the current changes and the changes made in the ' +
'last commit. Behaves similarly to `--onlyChanged`.',
type: 'boolean',
},
ci: {
default: isCI,
description:
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-cli/src/get_changed_files_promise.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ export default (
[],
);
return getChangedFilesForRoots(allRootsForAllProjects, {
changedSince: globalConfig.changedSince,
lastCommit: globalConfig.lastCommit,
toContributeTo: globalConfig.changedFilesToContributeTo,
withAncestor: globalConfig.changedFilesWithAncestor,
});
}
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-config/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ const getConfigs = (
return {
globalConfig: Object.freeze({
bail: options.bail,
changedFilesToContributeTo: options.changedFilesToContributeTo,
changedFilesWithAncestor: options.changedFilesWithAncestor,
changedSince: options.changedSince,
collectCoverage: options.collectCoverage,
collectCoverageFrom: options.collectCoverageFrom,
collectCoverageOnlyFrom: options.collectCoverageOnlyFrom,
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-config/src/normalize.js
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ export default function normalize(options: InitialOptions, argv: Argv) {
case 'bail':
case 'browser':
case 'cache':
case 'changedFilesToContributeTo':
case 'changedSince':
case 'changedFilesWithAncestor':
case 'clearMocks':
case 'collectCoverage':
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-config/src/valid_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ export default ({
browser: false,
cache: true,
cacheDirectory: '/tmp/user/jest',
changedFilesToContributeTo: '',
changedFilesWithAncestor: false,
changedSince: '',
clearMocks: false,
collectCoverage: true,
collectCoverageFrom: ['src', '!public'],
Expand Down
2 changes: 1 addition & 1 deletion test_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import type {GlobalConfig, ProjectConfig} from 'types/Config';

const DEFAULT_GLOBAL_CONFIG: GlobalConfig = {
bail: false,
changedFilesToContributeTo: '',
changedFilesWithAncestor: false,
changedSince: '',
collectCoverage: false,
collectCoverageFrom: [],
collectCoverageOnlyFrom: null,
Expand Down
2 changes: 1 addition & 1 deletion types/Argv.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ export type Argv = {|
browser: boolean,
cache: boolean,
cacheDirectory: string,
changedFilesToContributeTo: string,
changedFilesWithAncestor: boolean,
changedSince: string,
clearMocks: boolean,
ci: boolean,
collectCoverage: boolean,
Expand Down
2 changes: 1 addition & 1 deletion types/ChangedFiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import type {Path} from 'types/Config';
export type Options = {|
lastCommit?: boolean,
withAncestor?: boolean,
toContributeTo?: string,
changedSince?: string,
|};

export type ChangedFiles = Set<Path>;
Expand Down
4 changes: 2 additions & 2 deletions types/Config.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export type InitialOptions = {
cacheDirectory?: Path,
clearMocks?: boolean,
changedFilesWithAncestor?: boolean,
changedFilesToContributeTo?: string,
changedSince?: string,
collectCoverage?: boolean,
collectCoverageFrom?: Array<Glob>,
collectCoverageOnlyFrom?: {[key: string]: boolean},
Expand Down Expand Up @@ -158,7 +158,7 @@ export type SnapshotUpdateState = 'all' | 'new' | 'none';

export type GlobalConfig = {|
bail: boolean,
changedFilesToContributeTo: string,
changedSince: string,
changedFilesWithAncestor: boolean,
collectCoverage: boolean,
collectCoverageFrom: Array<Glob>,
Expand Down

0 comments on commit 9e6409a

Please sign in to comment.