diff --git a/packages/jest-circus/package.json b/packages/jest-circus/package.json index b6cf49688093..ea32a9dc4b75 100644 --- a/packages/jest-circus/package.json +++ b/packages/jest-circus/package.json @@ -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", diff --git a/packages/jest-circus/src/legacy-code-todo-rewrite/jestAdapterInit.ts b/packages/jest-circus/src/legacy-code-todo-rewrite/jestAdapterInit.ts index bedd74bb922d..96651b7337d0 100644 --- a/packages/jest-circus/src/legacy-code-todo-rewrite/jestAdapterInit.ts +++ b/packages/jest-circus/src/legacy-code-todo-rewrite/jestAdapterInit.ts @@ -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 { @@ -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; diff --git a/packages/jest-config/src/Deprecated.ts b/packages/jest-config/src/Deprecated.ts index 388602284c8d..493a44770692 100644 --- a/packages/jest-config/src/Deprecated.ts +++ b/packages/jest-config/src/Deprecated.ts @@ -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: @@ -26,7 +27,7 @@ export default { Please update your configuration.`, preprocessorIgnorePatterns: (options: { - preprocessorIgnorePatterns: Array; + preprocessorIgnorePatterns?: Array; }) => ` Option ${chalk.bold( '"preprocessorIgnorePatterns"', )} was replaced by ${chalk.bold( @@ -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( @@ -60,7 +61,7 @@ export default { Please update your configuration.`, setupTestFrameworkScriptFile: (_options: { - setupTestFrameworkScriptFile: Array; + setupTestFrameworkScriptFile?: string; }) => ` Option ${chalk.bold( '"setupTestFrameworkScriptFile"', )} was replaced by configuration ${chalk.bold( @@ -70,7 +71,7 @@ export default { Please update your configuration.`, testPathDirs: (options: { - testPathDirs: Array; + testPathDirs?: Array; }) => ` Option ${chalk.bold('"testPathDirs"')} was replaced by ${chalk.bold( '"roots"', )}. @@ -82,4 +83,6 @@ export default { Please update your configuration. `, -} as Record; +}; + +export default deprecatedOptions; diff --git a/packages/jest-snapshot/package.json b/packages/jest-snapshot/package.json index ecd1adb2c4e5..c02c6ea42cc3 100644 --- a/packages/jest-snapshot/package.json +++ b/packages/jest-snapshot/package.json @@ -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", diff --git a/packages/jest-snapshot/src/State.ts b/packages/jest-snapshot/src/State.ts index 24fbbee262f5..1d7ac9586b5a 100644 --- a/packages/jest-snapshot/src/State.ts +++ b/packages/jest-snapshot/src/State.ts @@ -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; }; @@ -62,7 +62,7 @@ export default class SnapshotState { private _snapshotPath: Config.Path; private _inlineSnapshots: Array; private _uncheckedKeys: Set; - private _getBabelTraverse: () => Function; + private _getBabelTraverse: () => BabelTraverse; private _getPrettier: () => null | typeof import('prettier'); added: number; diff --git a/packages/jest-snapshot/src/inline_snapshots.ts b/packages/jest-snapshot/src/inline_snapshots.ts index bf0d9719106b..108cd4850b06 100644 --- a/packages/jest-snapshot/src/inline_snapshots.ts +++ b/packages/jest-snapshot/src/inline_snapshots.ts @@ -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 = { @@ -26,8 +26,8 @@ export type InlineSnapshot = { export function saveInlineSnapshots( snapshots: Array, - prettier: typeof import('prettier') | null, - babelTraverse: Function, + prettier: Prettier | null, + babelTraverse: BabelTraverse, ): void { if (!prettier) { throw new Error( @@ -60,7 +60,7 @@ const saveSnapshotsForFile = ( snapshots: Array, sourceFilePath: Config.Path, prettier: any, - babelTraverse: Function, + babelTraverse: BabelTraverse, ) => { const sourceFile = fs.readFileSync(sourceFilePath, 'utf8'); @@ -181,7 +181,7 @@ const createInsertionParser = ( snapshots: Array, snapshotMatcherNames: Array, inferredParser: string, - babelTraverse: Function, + babelTraverse: BabelTraverse, ) => ( text: string, parsers: Record any>, @@ -248,7 +248,7 @@ const createInsertionParser = ( const createFormattingParser = ( snapshotMatcherNames: Array, inferredParser: string, - babelTraverse: Function, + babelTraverse: BabelTraverse, ) => ( text: string, parsers: Record any>, diff --git a/packages/jest-snapshot/src/types.ts b/packages/jest-snapshot/src/types.ts index 40ddd1cabfaa..e5ee10395c5e 100644 --- a/packages/jest-snapshot/src/types.ts +++ b/packages/jest-snapshot/src/types.ts @@ -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'); diff --git a/packages/jest-validate/src/exampleConfig.ts b/packages/jest-validate/src/exampleConfig.ts index b577e0c2910d..1bdf832d6cf9 100644 --- a/packages/jest-validate/src/exampleConfig.ts +++ b/packages/jest-validate/src/exampleConfig.ts @@ -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'}, diff --git a/packages/jest-validate/src/index.ts b/packages/jest-validate/src/index.ts index 01b9fccab3c1..08a162613c96 100644 --- a/packages/jest-validate/src/index.ts +++ b/packages/jest-validate/src/index.ts @@ -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'; diff --git a/packages/jest-validate/src/types.ts b/packages/jest-validate/src/types.ts index 879669cc80b7..b0e72f7dcc4b 100644 --- a/packages/jest-validate/src/types.ts +++ b/packages/jest-validate/src/types.ts @@ -11,7 +11,9 @@ type Title = { warning?: string; }; -export type DeprecatedOptions = Record; +export type DeprecatedOptionFunc = (arg: Record) => string; + +export type DeprecatedOptions = Record; export type ValidationOptions = { comment?: string; diff --git a/packages/jest-validate/src/validateCLIOptions.ts b/packages/jest-validate/src/validateCLIOptions.ts index e3f34dfacc63..72ad11aef1c9 100644 --- a/packages/jest-validate/src/validateCLIOptions.ts +++ b/packages/jest-validate/src/validateCLIOptions.ts @@ -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:')} @@ -88,7 +88,7 @@ export default function validateCLIOptions( } const CLIDeprecations = Object.keys(deprecationEntries).reduce< - Record + Record >((acc, entry) => { if (options[entry]) { acc[entry] = deprecationEntries[entry]; diff --git a/yarn.lock b/yarn.lock index 77341813bae7..a2d5faac7325 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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