Skip to content

Commit

Permalink
Make lastCommit and changedFilesWithAncestor work through config (#5476)
Browse files Browse the repository at this point in the history
  • Loading branch information
mjesun authored and cpojer committed Feb 7, 2018
1 parent faf8883 commit a94d130
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 11 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

### Features

* `[jest-config]` Allow lastComit and changedFilesWithAncestor via JSON config
([#5476](https://github.com/facebook/jest/pull/5476))
* `[jest-util]` Add deletion to `process.env` as well
([#5466](https://github.com/facebook/jest/pull/5466))
* `[jest-util]` Add case-insensitive getters/setters to `process.env`
Expand Down
13 changes: 12 additions & 1 deletion packages/jest-changed-files/src/hg.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,17 @@ const env = Object.assign({}, process.env, {
HGPLAIN: 1,
});

const ANCESTORS = [
// Parent commit to this one.
'.^',

// The first commit of my branch, only if we are not on the default branch.
'min(branch(.)) and not min(branch(default))',

// Latest public commit.
'max(public())',
];

const adapter: SCMAdapter = {
findChangedFiles: async (
cwd: string,
Expand All @@ -25,7 +36,7 @@ const adapter: SCMAdapter = {
return new Promise((resolve, reject) => {
let args = ['status', '-amnu'];
if (options && options.withAncestor) {
args.push('--rev', 'ancestor(.^)');
args.push('--rev', `ancestor(${ANCESTORS.join(', ')})`);
} else if (options && options.changedSince) {
args.push('--rev', `ancestor(., ${options.changedSince})`);
} else if (options && options.lastCommit === true) {
Expand Down
6 changes: 0 additions & 6 deletions packages/jest-cli/src/__tests__/cli/args.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,6 @@ describe('check', () => {
);
});

it('sets onlyChanged if lastCommit is specified', () => {
const argv: Argv = {lastCommit: true};
check(argv);
expect(argv.onlyChanged).toBe(true);
});

it('raises an exception if findRelatedTests is specified with no file paths', () => {
const argv: Argv = {_: [], findRelatedTests: true};
expect(() => check(argv)).toThrow(
Expand Down
4 changes: 1 addition & 3 deletions packages/jest-cli/src/cli/args.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ export const check = (argv: Argv) => {
'changedFilesWithAncestor',
'changedSince',
]) {
if (argv[key]) {
argv.onlyChanged = true;
}
if (argv[key] && argv.watchAll) {
throw new Error(
`Both --${key} and --watchAll were specified, but these two ` +
Expand Down Expand Up @@ -113,6 +110,7 @@ export const options = {
type: 'string',
},
changedFilesWithAncestor: {
default: undefined,
description:
'Runs tests related to the current changes and the changes made in the ' +
'last commit. Behaves similarly to `--onlyChanged`.',
Expand Down
1 change: 1 addition & 0 deletions packages/jest-config/src/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export default ({
browser: false,
cache: true,
cacheDirectory,
changedFilesWithAncestor: false,
clearMocks: false,
coveragePathIgnorePatterns: [NODE_MODULES_REGEXP],
coverageReporters: ['json', 'text', 'lcov', 'clover'],
Expand Down
12 changes: 11 additions & 1 deletion packages/jest-config/src/normalize.js
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,7 @@ export default function normalize(options: InitialOptions, argv: Argv) {
case 'findRelatedTests':
case 'forceCoverageMatch':
case 'forceExit':
case 'lastCommit':
case 'listTests':
case 'logHeapUsage':
case 'mapCoverage':
Expand Down Expand Up @@ -521,7 +522,6 @@ export default function normalize(options: InitialOptions, argv: Argv) {
newOptions.nonFlagArgs = argv._;
newOptions.testPathPattern = buildTestPathPattern(argv);
newOptions.json = argv.json;
newOptions.lastCommit = argv.lastCommit;

newOptions.testFailureExitCode = parseInt(newOptions.testFailureExitCode, 10);

Expand Down Expand Up @@ -571,6 +571,16 @@ export default function normalize(options: InitialOptions, argv: Argv) {
);
}

for (const key of [
'lastCommit',
'changedFilesWithAncestor',
'changedSince',
]) {
if (newOptions[key]) {
newOptions.onlyChanged = true;
}
}

return {
hasDeprecationWarnings,
options: newOptions,
Expand Down
1 change: 1 addition & 0 deletions packages/jest-config/src/valid_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export default ({
providesModuleNodeModules: ['react', 'react-native'],
},
json: false,
lastCommit: false,
logHeapUsage: true,
mapCoverage: false,
moduleDirectories: ['node_modules'],
Expand Down
2 changes: 2 additions & 0 deletions types/Config.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export type DefaultOptions = {|
browser: boolean,
cache: boolean,
cacheDirectory: Path,
changedFilesWithAncestor: boolean,
clearMocks: boolean,
coveragePathIgnorePatterns: Array<string>,
coverageReporters: Array<string>,
Expand Down Expand Up @@ -98,6 +99,7 @@ export type InitialOptions = {
haste?: HasteConfig,
reporters?: Array<ReporterConfig | string>,
logHeapUsage?: boolean,
lastCommit?: boolean,
listTests?: boolean,
mapCoverage?: boolean,
moduleDirectories?: Array<string>,
Expand Down

0 comments on commit a94d130

Please sign in to comment.