Skip to content
Prev Previous commit
Next Next commit
Refactor watch extensions as per PR review (#6473)
  • Loading branch information
tdd committed Jul 10, 2018
commit 87939182c79d405901ca6db9c1dc4d48c087bc14
45 changes: 22 additions & 23 deletions packages/jest-cli/src/lib/update_global_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,29 @@

import {replacePathSepForRegex} from 'jest-regex-util';

import type {
GlobalConfig,
ReporterConfig,
SnapshotUpdateState,
} from 'types/Config';

type Options = {
bail?: boolean,
collectCoverage?: boolean,
collectCoverageFrom?: Array<string>,
collectCoverageOnlyFrom?: ?{[key: string]: boolean},
coverageDirectory?: string,
coverageReporters?: Array<string>,
import type {GlobalConfig} from 'types/Config';

export type Options = {
bail?: $PropertyType<GlobalConfig, 'bail'>,
collectCoverage?: $PropertyType<GlobalConfig, 'collectCoverage'>,
collectCoverageFrom?: $PropertyType<GlobalConfig, 'collectCoverageFrom'>,
collectCoverageOnlyFrom?: $PropertyType<
GlobalConfig,
'collectCoverageOnlyFrom',
>,
coverageDirectory?: $PropertyType<GlobalConfig, 'coverageDirectory'>,
coverageReporters?: $PropertyType<GlobalConfig, 'coverageReporters'>,
mode?: 'watch' | 'watchAll',
noSCM?: boolean,
notify?: boolean,
notifyMode?: string,
onlyFailures?: boolean,
passWithNoTests?: boolean,
reporters?: Array<ReporterConfig>,
testNamePattern?: string,
testPathPattern?: string,
updateSnapshot?: SnapshotUpdateState,
verbose?: ?boolean,
noSCM?: $PropertyType<GlobalConfig, 'noSCM'>,
notify?: $PropertyType<GlobalConfig, 'notify'>,
notifyMode?: $PropertyType<GlobalConfig, 'notifyMode'>,
onlyFailures?: $PropertyType<GlobalConfig, 'onlyFailures'>,
passWithNoTests?: $PropertyType<GlobalConfig, 'passWithNoTests'>,
reporters?: $PropertyType<GlobalConfig, 'reporters'>,
testNamePattern?: $PropertyType<GlobalConfig, 'testNamePattern'>,
testPathPattern?: $PropertyType<GlobalConfig, 'testPathPattern'>,
updateSnapshot?: $PropertyType<GlobalConfig, 'updateSnapshot'>,
verbose?: $PropertyType<GlobalConfig, 'verbose'>,
};

export default (globalConfig: GlobalConfig, options: Options): GlobalConfig => {
Expand Down
25 changes: 3 additions & 22 deletions packages/jest-cli/src/watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,10 @@
* @flow
*/

import type {
GlobalConfig,
ReporterConfig,
SnapshotUpdateState,
} from 'types/Config';
import type {GlobalConfig} from 'types/Config';
import type {Context} from 'types/Context';
import type {WatchPlugin} from './types';
import type {Options as UpdateGlobalConfigOptions} from './lib/update_global_config';

import ansiEscapes from 'ansi-escapes';
import chalk from 'chalk';
Expand Down Expand Up @@ -86,23 +83,7 @@ export default function watch(
testPathPattern,
updateSnapshot,
verbose,
}: {
bail?: boolean,
collectCoverage?: boolean,
collectCoverageFrom?: Array<string>,
collectCoverageOnlyFrom?: {[key: string]: boolean},
coverageDirectory?: string,
coverageReporters?: Array<string>,
mode?: 'watch' | 'watchAll',
notify?: boolean,
notifyMode?: string,
onlyFailures?: boolean,
reporters?: Array<ReporterConfig>,
testNamePattern?: string,
testPathPattern?: string,
updateSnapshot?: SnapshotUpdateState,
verbose?: boolean,
} = {}) => {
}: UpdateGlobalConfigOptions = {}) => {
const previousUpdateSnapshot = globalConfig.updateSnapshot;
globalConfig = updateGlobalConfig(globalConfig, {
Copy link
Contributor

Choose a reason for hiding this comment

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

Now that there are a lot of options, maybe we could move a lot of this !== undefined logic into the updateGlobalConfig function, so that it is the only place that knows how to handle all of that logic

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, that's an option. I really disliked the un-DRYness of this part of the code, but making it dynamically iterate over a list of props confused the heck out of Flow 😒 .

I'll try and move that logic inside updateGlobalConfig and see how it goes.

bail,
Expand Down