Skip to content

Commit a94d130

Browse files
mjesuncpojer
authored andcommitted
Make lastCommit and changedFilesWithAncestor work through config (#5476)
1 parent faf8883 commit a94d130

8 files changed

Lines changed: 30 additions & 11 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
### Features
44

5+
* `[jest-config]` Allow lastComit and changedFilesWithAncestor via JSON config
6+
([#5476](https://github.com/facebook/jest/pull/5476))
57
* `[jest-util]` Add deletion to `process.env` as well
68
([#5466](https://github.com/facebook/jest/pull/5466))
79
* `[jest-util]` Add case-insensitive getters/setters to `process.env`

packages/jest-changed-files/src/hg.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,17 @@ const env = Object.assign({}, process.env, {
1717
HGPLAIN: 1,
1818
});
1919

20+
const ANCESTORS = [
21+
// Parent commit to this one.
22+
'.^',
23+
24+
// The first commit of my branch, only if we are not on the default branch.
25+
'min(branch(.)) and not min(branch(default))',
26+
27+
// Latest public commit.
28+
'max(public())',
29+
];
30+
2031
const adapter: SCMAdapter = {
2132
findChangedFiles: async (
2233
cwd: string,
@@ -25,7 +36,7 @@ const adapter: SCMAdapter = {
2536
return new Promise((resolve, reject) => {
2637
let args = ['status', '-amnu'];
2738
if (options && options.withAncestor) {
28-
args.push('--rev', 'ancestor(.^)');
39+
args.push('--rev', `ancestor(${ANCESTORS.join(', ')})`);
2940
} else if (options && options.changedSince) {
3041
args.push('--rev', `ancestor(., ${options.changedSince})`);
3142
} else if (options && options.lastCommit === true) {

packages/jest-cli/src/__tests__/cli/args.test.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,6 @@ describe('check', () => {
3838
);
3939
});
4040

41-
it('sets onlyChanged if lastCommit is specified', () => {
42-
const argv: Argv = {lastCommit: true};
43-
check(argv);
44-
expect(argv.onlyChanged).toBe(true);
45-
});
46-
4741
it('raises an exception if findRelatedTests is specified with no file paths', () => {
4842
const argv: Argv = {_: [], findRelatedTests: true};
4943
expect(() => check(argv)).toThrow(

packages/jest-cli/src/cli/args.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@ export const check = (argv: Argv) => {
2626
'changedFilesWithAncestor',
2727
'changedSince',
2828
]) {
29-
if (argv[key]) {
30-
argv.onlyChanged = true;
31-
}
3229
if (argv[key] && argv.watchAll) {
3330
throw new Error(
3431
`Both --${key} and --watchAll were specified, but these two ` +
@@ -113,6 +110,7 @@ export const options = {
113110
type: 'string',
114111
},
115112
changedFilesWithAncestor: {
113+
default: undefined,
116114
description:
117115
'Runs tests related to the current changes and the changes made in the ' +
118116
'last commit. Behaves similarly to `--onlyChanged`.',

packages/jest-config/src/defaults.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export default ({
3333
browser: false,
3434
cache: true,
3535
cacheDirectory,
36+
changedFilesWithAncestor: false,
3637
clearMocks: false,
3738
coveragePathIgnorePatterns: [NODE_MODULES_REGEXP],
3839
coverageReporters: ['json', 'text', 'lcov', 'clover'],

packages/jest-config/src/normalize.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,7 @@ export default function normalize(options: InitialOptions, argv: Argv) {
474474
case 'findRelatedTests':
475475
case 'forceCoverageMatch':
476476
case 'forceExit':
477+
case 'lastCommit':
477478
case 'listTests':
478479
case 'logHeapUsage':
479480
case 'mapCoverage':
@@ -521,7 +522,6 @@ export default function normalize(options: InitialOptions, argv: Argv) {
521522
newOptions.nonFlagArgs = argv._;
522523
newOptions.testPathPattern = buildTestPathPattern(argv);
523524
newOptions.json = argv.json;
524-
newOptions.lastCommit = argv.lastCommit;
525525

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

@@ -571,6 +571,16 @@ export default function normalize(options: InitialOptions, argv: Argv) {
571571
);
572572
}
573573

574+
for (const key of [
575+
'lastCommit',
576+
'changedFilesWithAncestor',
577+
'changedSince',
578+
]) {
579+
if (newOptions[key]) {
580+
newOptions.onlyChanged = true;
581+
}
582+
}
583+
574584
return {
575585
hasDeprecationWarnings,
576586
options: newOptions,

packages/jest-config/src/valid_config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export default ({
4747
providesModuleNodeModules: ['react', 'react-native'],
4848
},
4949
json: false,
50+
lastCommit: false,
5051
logHeapUsage: true,
5152
mapCoverage: false,
5253
moduleDirectories: ['node_modules'],

types/Config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export type DefaultOptions = {|
2727
browser: boolean,
2828
cache: boolean,
2929
cacheDirectory: Path,
30+
changedFilesWithAncestor: boolean,
3031
clearMocks: boolean,
3132
coveragePathIgnorePatterns: Array<string>,
3233
coverageReporters: Array<string>,
@@ -98,6 +99,7 @@ export type InitialOptions = {
9899
haste?: HasteConfig,
99100
reporters?: Array<ReporterConfig | string>,
100101
logHeapUsage?: boolean,
102+
lastCommit?: boolean,
101103
listTests?: boolean,
102104
mapCoverage?: boolean,
103105
moduleDirectories?: Array<string>,

0 commit comments

Comments
 (0)