Skip to content

Commit

Permalink
choreØ eplace function types (#10436)
Browse files Browse the repository at this point in the history
Co-authored-by: Simen Bekkhus <sbekkhus91@gmail.com>
  • Loading branch information
G-Rath and SimenB committed Sep 13, 2020
1 parent a79c34b commit 3dd4a95
Show file tree
Hide file tree
Showing 12 changed files with 34 additions and 22 deletions.
1 change: 1 addition & 0 deletions packages/jest-circus/package.json
Expand Up @@ -14,6 +14,7 @@
"@jest/environment": "^26.3.0",
"@jest/test-result": "^26.3.0",
"@jest/types": "^26.3.0",
"@types/babel__traverse": "^7.0.4",
"@types/node": "*",
"chalk": "^4.0.0",
"co": "^4.6.0",
Expand Down
Expand Up @@ -5,6 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/

import type BabelTraverse from '@babel/traverse';
import type {Circus, Config, Global} from '@jest/types';
import type {JestEnvironment} from '@jest/environment';
import {
Expand Down Expand Up @@ -51,7 +52,7 @@ export const initialize = async ({
config: Config.ProjectConfig;
environment: JestEnvironment;
getPrettier: () => null | any;
getBabelTraverse: () => Function;
getBabelTraverse: () => typeof BabelTraverse;
globalConfig: Config.GlobalConfig;
localRequire: (path: Config.Path) => any;
testPath: Config.Path;
Expand Down
15 changes: 9 additions & 6 deletions packages/jest-config/src/Deprecated.ts
Expand Up @@ -7,10 +7,11 @@

import chalk = require('chalk');
import prettyFormat = require('pretty-format');
import type {DeprecatedOptions} from 'jest-validate';

const format = (value: unknown) => prettyFormat(value, {min: true});

export default {
const deprecatedOptions: DeprecatedOptions = {
browser: () => ` Option ${chalk.bold(
'"browser"',
)} has been deprecated. Please install "browser-resolve" and use the "resolver" option in Jest configuration as follows:
Expand All @@ -26,7 +27,7 @@ export default {
Please update your configuration.`,

preprocessorIgnorePatterns: (options: {
preprocessorIgnorePatterns: Array<string>;
preprocessorIgnorePatterns?: Array<string>;
}) => ` Option ${chalk.bold(
'"preprocessorIgnorePatterns"',
)} was replaced by ${chalk.bold(
Expand All @@ -43,7 +44,7 @@ export default {
Please update your configuration.`,

scriptPreprocessor: (options: {
scriptPreprocessor: string;
scriptPreprocessor?: string;
}) => ` Option ${chalk.bold(
'"scriptPreprocessor"',
)} was replaced by ${chalk.bold(
Expand All @@ -60,7 +61,7 @@ export default {
Please update your configuration.`,

setupTestFrameworkScriptFile: (_options: {
setupTestFrameworkScriptFile: Array<string>;
setupTestFrameworkScriptFile?: string;
}) => ` Option ${chalk.bold(
'"setupTestFrameworkScriptFile"',
)} was replaced by configuration ${chalk.bold(
Expand All @@ -70,7 +71,7 @@ export default {
Please update your configuration.`,

testPathDirs: (options: {
testPathDirs: Array<string>;
testPathDirs?: Array<string>;
}) => ` Option ${chalk.bold('"testPathDirs"')} was replaced by ${chalk.bold(
'"roots"',
)}.
Expand All @@ -82,4 +83,6 @@ export default {
Please update your configuration.
`,
} as Record<string, Function>;
};

export default deprecatedOptions;
1 change: 1 addition & 0 deletions packages/jest-snapshot/package.json
Expand Up @@ -12,6 +12,7 @@
"dependencies": {
"@babel/types": "^7.0.0",
"@jest/types": "^26.3.0",
"@types/babel__traverse": "^7.0.4",
"@types/prettier": "^2.0.0",
"chalk": "^4.0.0",
"expect": "^26.4.2",
Expand Down
8 changes: 4 additions & 4 deletions packages/jest-snapshot/src/State.ts
Expand Up @@ -20,12 +20,12 @@ import {
testNameToKey,
} from './utils';
import {InlineSnapshot, saveInlineSnapshots} from './inline_snapshots';
import type {SnapshotData} from './types';
import type {BabelTraverse, Prettier, SnapshotData} from './types';

export type SnapshotStateOptions = {
updateSnapshot: Config.SnapshotUpdateState;
getPrettier: () => null | typeof import('prettier');
getBabelTraverse: () => Function;
getPrettier: () => null | Prettier;
getBabelTraverse: () => BabelTraverse;
expand?: boolean;
};

Expand Down Expand Up @@ -62,7 +62,7 @@ export default class SnapshotState {
private _snapshotPath: Config.Path;
private _inlineSnapshots: Array<InlineSnapshot>;
private _uncheckedKeys: Set<string>;
private _getBabelTraverse: () => Function;
private _getBabelTraverse: () => BabelTraverse;
private _getPrettier: () => null | typeof import('prettier');

added: number;
Expand Down
12 changes: 6 additions & 6 deletions packages/jest-snapshot/src/inline_snapshots.ts
Expand Up @@ -15,8 +15,8 @@ import {
templateLiteral,
} from '@babel/types';
import type {Frame} from 'jest-message-util';

import type {Config} from '@jest/types';
import type {BabelTraverse, Prettier} from './types';
import {escapeBacktickString} from './utils';

export type InlineSnapshot = {
Expand All @@ -26,8 +26,8 @@ export type InlineSnapshot = {

export function saveInlineSnapshots(
snapshots: Array<InlineSnapshot>,
prettier: typeof import('prettier') | null,
babelTraverse: Function,
prettier: Prettier | null,
babelTraverse: BabelTraverse,
): void {
if (!prettier) {
throw new Error(
Expand Down Expand Up @@ -60,7 +60,7 @@ const saveSnapshotsForFile = (
snapshots: Array<InlineSnapshot>,
sourceFilePath: Config.Path,
prettier: any,
babelTraverse: Function,
babelTraverse: BabelTraverse,
) => {
const sourceFile = fs.readFileSync(sourceFilePath, 'utf8');

Expand Down Expand Up @@ -181,7 +181,7 @@ const createInsertionParser = (
snapshots: Array<InlineSnapshot>,
snapshotMatcherNames: Array<string>,
inferredParser: string,
babelTraverse: Function,
babelTraverse: BabelTraverse,
) => (
text: string,
parsers: Record<string, (text: string) => any>,
Expand Down Expand Up @@ -248,7 +248,7 @@ const createInsertionParser = (
const createFormattingParser = (
snapshotMatcherNames: Array<string>,
inferredParser: string,
babelTraverse: Function,
babelTraverse: BabelTraverse,
) => (
text: string,
parsers: Record<string, (text: string) => any>,
Expand Down
3 changes: 3 additions & 0 deletions packages/jest-snapshot/src/types.ts
Expand Up @@ -29,3 +29,6 @@ export type ExpectationResult = {
pass: boolean;
message: () => string;
};

export type BabelTraverse = typeof import('@babel/traverse').default;
export type Prettier = typeof import('prettier');
3 changes: 1 addition & 2 deletions packages/jest-validate/src/exampleConfig.ts
Expand Up @@ -12,8 +12,7 @@ const config: ValidationOptions = {
condition: () => true,
deprecate: () => false,
deprecatedConfig: {
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
key: () => {},
key: (): string => 'Deprecation message',
},
error: () => {},
exampleConfig: {key: 'value', test: 'case'},
Expand Down
1 change: 1 addition & 0 deletions packages/jest-validate/src/index.ts
Expand Up @@ -11,6 +11,7 @@ export {
format,
logValidationWarning,
} from './utils';
export type {DeprecatedOptions} from './types';
export {default as validate} from './validate';
export {default as validateCLIOptions} from './validateCLIOptions';
export {multipleValidOptions} from './condition';
4 changes: 3 additions & 1 deletion packages/jest-validate/src/types.ts
Expand Up @@ -11,7 +11,9 @@ type Title = {
warning?: string;
};

export type DeprecatedOptions = Record<string, Function>;
export type DeprecatedOptionFunc = (arg: Record<string, any>) => string;

export type DeprecatedOptions = Record<string, DeprecatedOptionFunc>;

export type ValidationOptions = {
comment?: string;
Expand Down
4 changes: 2 additions & 2 deletions packages/jest-validate/src/validateCLIOptions.ts
Expand Up @@ -12,7 +12,7 @@ import type {Options} from 'yargs';
import {ValidationError, createDidYouMeanMessage, format} from './utils';
import {deprecationWarning} from './deprecated';
import defaultConfig from './defaultConfig';
import type {DeprecatedOptions} from './types';
import type {DeprecatedOptionFunc, DeprecatedOptions} from './types';

const BULLET: string = chalk.bold('\u25cf');
export const DOCUMENTATION_NOTE = ` ${chalk.bold('CLI Options Documentation:')}
Expand Down Expand Up @@ -88,7 +88,7 @@ export default function validateCLIOptions(
}

const CLIDeprecations = Object.keys(deprecationEntries).reduce<
Record<string, Function>
Record<string, DeprecatedOptionFunc>
>((acc, entry) => {
if (options[entry]) {
acc[entry] = deprecationEntries[entry];
Expand Down
1 change: 1 addition & 0 deletions yarn.lock
Expand Up @@ -11887,6 +11887,7 @@ fsevents@^1.2.7:
"@babel/traverse": ^7.3.4
"@babel/types": ^7.0.0
"@jest/types": ^26.3.0
"@types/babel__traverse": ^7.0.4
"@types/graceful-fs": ^4.1.3
"@types/natural-compare": ^1.4.0
"@types/prettier": ^2.0.0
Expand Down

0 comments on commit 3dd4a95

Please sign in to comment.