Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make lastCommit and changedFilesWithAncestor work through config #5476

Merged
merged 1 commit into from
Feb 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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', () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test case is removed because it does not apply anymore; the logic has been moved to normalize in jest-config. Which, in turn, it's the right place to have it (argv should be read-only).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

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 [
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'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