Skip to content

Commit 55e7ed8

Browse files
committed
chore: migrate jest-validate to TypeScript
1 parent de52b48 commit 55e7ed8

25 files changed

+121
-124
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
- `[jest-runtime]`: Migrate to TypeScript ([#7964](https://github.com/facebook/jest/pull/7964), [#7988](https://github.com/facebook/jest/pull/7988))
7070
- `[@jest/fake-timers]`: Extract FakeTimers class from `jest-util` into a new separate package ([#7987](https://github.com/facebook/jest/pull/7987))
7171
- `[jest-repl]`: Migrate to TypeScript ([#8000](https://github.com/facebook/jest/pull/8000))
72+
- `[jest-validate]`: Migrate to TypeScript ([#7991](https://github.com/facebook/jest/pull/7991))
7273

7374
### Performance
7475

packages/jest-config/src/ReporterValidationErrors.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
*/
88

99
import {Config} from '@jest/types';
10-
// @ts-ignore: Not migrated to TS
1110
import {ValidationError} from 'jest-validate';
1211
import chalk from 'chalk';
1312
import getType from 'jest-get-type';
@@ -27,7 +26,7 @@ const ERROR = `${BULLET}Reporter Validation Error`;
2726
export function createReporterError(
2827
reporterIndex: number,
2928
reporterValue: Array<Config.ReporterConfig> | string,
30-
): ValidationError {
29+
) {
3130
const errorMessage =
3231
` Reporter at index ${reporterIndex} must be of type:\n` +
3332
` ${chalk.bold.green(validReporterTypes.join(' or '))}\n` +
@@ -44,7 +43,7 @@ export function createArrayReporterError(
4443
value: string | Object,
4544
expectedType: string,
4645
valueName: string,
47-
): ValidationError {
46+
) {
4847
const errorMessage =
4948
` Unexpected value for ${valueName} ` +
5049
`at index ${valueIndex} of reporter at index ${reporterIndex}\n` +

packages/jest-config/src/ValidConfig.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@
77

88
import {Config} from '@jest/types';
99
import {replacePathSepForRegex} from 'jest-regex-util';
10-
// @ts-ignore: Not migrated to TS
1110
import {multipleValidOptions} from 'jest-validate';
1211
import {NODE_MODULES} from './constants';
1312

1413
const NODE_MODULES_REGEXP = replacePathSepForRegex(NODE_MODULES);
1514

1615
const initialOptions: Config.InitialOptions = {
1716
automock: false,
17+
// @ts-ignore TODO: type this properly
1818
bail: multipleValidOptions(false, 0),
1919
browser: false,
2020
cache: true,

packages/jest-config/src/normalize.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import crypto from 'crypto';
99
import path from 'path';
1010
import glob from 'glob';
1111
import {Config} from '@jest/types';
12-
// @ts-ignore: Not migrated to TS
1312
import {ValidationError, validate} from 'jest-validate';
1413
import {clearLine, replacePathSepForGlob} from 'jest-util';
1514
import chalk from 'chalk';

packages/jest-config/src/utils.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
import path from 'path';
99
import {Config} from '@jest/types';
10-
// @ts-ignore: Not migrated to TS
1110
import {ValidationError} from 'jest-validate';
1211
import Resolver from 'jest-resolve';
1312
import chalk from 'chalk';

packages/jest-config/tsconfig.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
"rootDir": "src",
55
"outDir": "build"
66
},
7-
// TODO: This is missing `jest-validate`, in addition to and `jest-jasmine2`,
8-
// but those are just `require.resolve`d, so no real use for their types
7+
// TODO: This is missing `jest-jasmine2`, but that is just
8+
// `require.resolve`d, so no real use for its types
99
"references": [
1010
{"path": "../jest-environment-jsdom"},
1111
{"path": "../jest-environment-node"},
@@ -14,6 +14,7 @@
1414
{"path": "../jest-resolve"},
1515
{"path": "../jest-types"},
1616
{"path": "../jest-util"},
17+
{"path": "../jest-validate"},
1718
{"path": "../pretty-format"}
1819
]
1920
}

packages/jest-repl/src/cli/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
import Runtime from 'jest-runtime';
1111
import yargs from 'yargs';
12-
// @ts-ignore: Wait for jest-validate to get migrated
1312
import {validateCLIOptions} from 'jest-validate';
1413
import {deprecationEntries} from 'jest-config';
1514
import * as args from './args';
@@ -21,6 +20,7 @@ const REPL_SCRIPT = require.resolve('./repl.js');
2120
export = function() {
2221
const argv = yargs.usage(args.usage).options(args.options).argv;
2322

23+
// @ts-ignore: not the same arguments
2424
validateCLIOptions(argv, {...args.options, deprecationEntries});
2525

2626
argv._ = [REPL_SCRIPT];

packages/jest-repl/tsconfig.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
{"path": "../jest-config"},
99
{"path": "../jest-runtime"},
1010
{"path": "../jest-transform"},
11-
{"path": "../jest-types"}
12-
// TODO: Wait for this to get migrated
13-
// {"path": "../jest-validate"}
11+
{"path": "../jest-types"},
12+
{"path": "../jest-validate"}
1413
]
1514
}

packages/jest-runtime/src/cli/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import yargs from 'yargs';
1313
import {Config} from '@jest/types';
1414
import {JestEnvironment} from '@jest/environment';
1515
import {Console, setGlobal} from 'jest-util';
16-
// @ts-ignore: Not migrated to TS
1716
import {validateCLIOptions} from 'jest-validate';
1817
import {readConfig, deprecationEntries} from 'jest-config';
1918
import {VERSION} from '../version';
@@ -35,6 +34,7 @@ export function run(cliArgv?: Config.Argv, cliInfo?: Array<string>) {
3534
.version(false)
3635
.options(args.options).argv;
3736

37+
// @ts-ignore: fix this at some point
3838
validateCLIOptions(argv, {...args.options, deprecationEntries});
3939
}
4040

packages/jest-runtime/tsconfig.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
"rootDir": "src",
55
"outDir": "build"
66
},
7-
// TODO: Missing `jest-validate`
87
"references": [
98
{"path": "../jest-config"},
109
{"path": "../jest-environment"},
@@ -15,8 +14,9 @@
1514
{"path": "../jest-regex-util"},
1615
{"path": "../jest-resolve"},
1716
{"path": "../jest-snapshot"},
18-
{"path": "../jest-util"},
1917
{"path": "../jest-types"},
18+
{"path": "../jest-util"},
19+
{"path": "../jest-validate"},
2020
{"path": "../pretty-format"}
2121
]
2222
}

packages/jest-validate/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
},
99
"license": "MIT",
1010
"main": "build/index.js",
11+
"types": "build/index.d.ts",
1112
"dependencies": {
13+
"@jest/types": "^24.1.0",
1214
"camelcase": "^5.0.0",
1315
"chalk": "^2.0.1",
1416
"jest-get-type": "^24.0.0",

packages/jest-validate/src/__tests__/validateCLIOptions.test.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
*
77
*/
88

9-
'use strict';
10-
119
import validateCLIOptions from '../validateCLIOptions';
1210

1311
test('validates yargs special options', () => {

packages/jest-validate/src/condition.js renamed to packages/jest-validate/src/condition.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
*
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
6-
*
7-
* @flow
86
*/
97

108
const toString = Object.prototype.toString;
@@ -23,6 +21,7 @@ function validationConditionSingle(option: any, validOption: any): boolean {
2321
export function getValues(validOption: any) {
2422
if (
2523
Array.isArray(validOption) &&
24+
// @ts-ignore
2625
validOption[MULTIPLE_VALID_OPTIONS_SYMBOL]
2726
) {
2827
return validOption;
@@ -34,9 +33,11 @@ export function validationCondition(option: any, validOption: any): boolean {
3433
return getValues(validOption).some(e => validationConditionSingle(option, e));
3534
}
3635

36+
// TODO: This should infer the types of its arguments, and return a union type of the types
37+
// See https://github.com/Microsoft/TypeScript/issues/5453
3738
export function multipleValidOptions(...args: Array<any>) {
3839
const options = [...args];
39-
// $FlowFixMe
40+
// @ts-ignore
4041
options[MULTIPLE_VALID_OPTIONS_SYMBOL] = true;
4142
return options;
4243
}

packages/jest-validate/src/defaultConfig.js renamed to packages/jest-validate/src/defaultConfig.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,17 @@
33
*
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
6-
*
7-
* @flow
86
*/
97

10-
import type {ValidationOptions} from './types';
8+
import {ValidationOptions} from './types';
119

1210
import {deprecationWarning} from './deprecated';
1311
import {unknownOptionWarning} from './warnings';
1412
import {errorMessage} from './errors';
1513
import {validationCondition} from './condition';
1614
import {ERROR, DEPRECATION, WARNING} from './utils';
1715

18-
export default ({
16+
const validationOptions: ValidationOptions = {
1917
comment: '',
2018
condition: validationCondition,
2119
deprecate: deprecationWarning,
@@ -31,4 +29,6 @@ export default ({
3129
warning: WARNING,
3230
},
3331
unknown: unknownOptionWarning,
34-
}: ValidationOptions);
32+
};
33+
34+
export default validationOptions;

packages/jest-validate/src/deprecated.js renamed to packages/jest-validate/src/deprecated.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,9 @@
33
*
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
6-
*
7-
* @flow
86
*/
97

10-
import type {ValidationOptions} from './types';
8+
import {DeprecatedOptions, ValidationOptions} from './types';
119

1210
import {logValidationWarning, DEPRECATION} from './utils';
1311

@@ -19,9 +17,9 @@ const deprecationMessage = (message: string, options: ValidationOptions) => {
1917
};
2018

2119
export const deprecationWarning = (
22-
config: Object,
20+
config: {[key: string]: any},
2321
option: string,
24-
deprecatedOptions: Object,
22+
deprecatedOptions: DeprecatedOptions,
2523
options: ValidationOptions,
2624
): boolean => {
2725
if (option in deprecatedOptions) {

packages/jest-validate/src/errors.js renamed to packages/jest-validate/src/errors.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,13 @@
33
*
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
6-
*
7-
* @flow
86
*/
97

10-
import type {ValidationOptions} from './types';
11-
128
import chalk from 'chalk';
139
import getType from 'jest-get-type';
1410
import {formatPrettyObject, ValidationError, ERROR} from './utils';
1511
import {getValues} from './condition';
12+
import {ValidationOptions} from './types';
1613

1714
export const errorMessage = (
1815
option: string,

packages/jest-validate/src/exampleConfig.js renamed to packages/jest-validate/src/exampleConfig.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,18 @@
33
*
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
6-
*
7-
* @flow
86
*/
97

10-
import type {ValidationOptions} from './types';
8+
import {ValidationOptions} from './types';
119

1210
const config: ValidationOptions = {
1311
comment: ' A comment',
14-
condition: (option, validOption) => true,
15-
deprecate: (config, option, deprecatedOptions, options) => false,
12+
condition: () => true,
13+
deprecate: () => false,
1614
deprecatedConfig: {
17-
key: config => {},
15+
key: () => {},
1816
},
19-
error: (option, received, defaultValue, options) => {},
17+
error: () => {},
2018
exampleConfig: {key: 'value', test: 'case'},
2119
recursive: true,
2220
recursiveBlacklist: [],
@@ -25,7 +23,7 @@ const config: ValidationOptions = {
2523
error: 'Validation Error',
2624
warning: 'Validation Warning',
2725
},
28-
unknown: (config, option, options) => {},
26+
unknown: () => {},
2927
};
3028

3129
export default config;

packages/jest-validate/src/index.js renamed to packages/jest-validate/src/index.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
*
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
6-
*
7-
* @flow
86
*/
97

108
import {
@@ -17,7 +15,7 @@ import validate from './validate';
1715
import validateCLIOptions from './validateCLIOptions';
1816
import {multipleValidOptions} from './condition';
1917

20-
module.exports = {
18+
export = {
2119
ValidationError,
2220
createDidYouMeanMessage,
2321
format,

packages/jest-validate/src/types.js

Lines changed: 0 additions & 44 deletions
This file was deleted.

0 commit comments

Comments
 (0)