import { GlobalConfig } from '@jest/types/build/Config'; import { PLUGIN_CONTEXT_KEY, VALIDATION_MAP } from './utils/constant.js'; import type { Context } from '.'; import type { AggregatedResult } from '@jest/test-result'; import type { Config } from '@jest/types'; export interface Hash { [name: string]: T; } export declare type Json = Hash; export declare type JsonArray = Array; export declare type MaybeArray = T | T[]; export declare type MaybePromise = T | Promise; export declare type GetValue = (name: string) => T; export declare type SetValue = (name: string, value: T) => void; export interface DefaultPluginAPI { context: PluginContext; registerTask: RegisterTask; getAllTask: () => string[]; getAllPlugin: GetAllPlugin; cancelTask: CancelTask; onGetConfig: OnGetConfig; onGetJestConfig: OnGetJestConfig; onHook: OnHook; setValue: SetValue; getValue: GetValue; registerUserConfig: (args: MaybeArray>) => void; hasRegistration: (name: string, type?: 'cliOption' | 'userConfig') => boolean; registerCliOption: (args: MaybeArray>) => void; registerMethod: RegisterMethod; applyMethod: ApplyMethodAPI; hasMethod: HasMethod; modifyUserConfig: ModifyUserConfig; modifyConfigRegistration: ModifyConfigRegistration; modifyCliRegistration: ModifyCliRegistration; } export declare type PropType = TObj[TProp]; export declare type PluginContext = Pick; export declare type UserConfigContext = PluginContext & { taskName: T; }; export declare type ValidationKey = keyof typeof VALIDATION_MAP; export interface JestResult { results: AggregatedResult; globalConfig: GlobalConfig; } export interface OnHookCallbackArg { err?: Error; args?: CommandArgs; stats?: any; url?: string; devServer?: any; config?: any; result?: JestResult; [other: string]: unknown; } export interface OnHookCallback { (arg?: OnHookCallbackArg): MaybePromise; } export interface HookOptions { enforce?: 'pre' | 'post'; } export interface OnHook { (eventName: string, callback: OnHookCallback, options?: HookOptions): void; } export interface PluginConfig { (config: T): Promise | void | T; } export interface SetConfig { (config: T, value: any, context: UserConfigContext): Promise | void | T; } export interface Validation { (value: any): boolean; } export interface UserConfigArgs { name: string; setConfig?: SetConfig; defaultValue?: any; validation?: string | Validation; ignoreTasks?: string[]; } export interface CliOptionArgs { name: string; setConfig?: SetConfig; commands?: string[]; ignoreTasks?: string[]; } export interface OnGetConfig { (name: string, fn: PluginConfig): void; (fn: PluginConfig): void; } export interface OnGetJestConfig { (fn: JestConfigFunction): void; } export interface RegisterTask { (name: string, config: T): void; } export interface CancelTask { (name: string): void; } export interface MethodRegistration { (args?: any): void; } export interface MethodCurry { (data?: any): MethodRegistration; } export declare type MethodFunction = MethodRegistration | MethodCurry; export interface MethodOptions { pluginName?: boolean; } export interface RegisterMethod { (name: string, fn: MethodFunction, options?: MethodOptions): void; } declare type Method = [string, string] | string; export interface ApplyMethod { (config: Method, ...args: any[]): any; } export interface ApplyMethodAPI { (name: string, ...args: any[]): any; } export interface HasMethod { (name: string): boolean; } export interface ModifyConfig { (userConfig: UserConfig): Omit; } export interface ModifyUserConfig { (configKey: string | ModifyConfig, value?: any, options?: { deepmerge: boolean; }): void; } export interface GetAllPlugin { (dataKeys?: string[]): Array>>; } export interface PluginInfo extends Partial<_Plugin> { pluginPath?: string; options?: K; } export interface _Plugin { name?: string; setup: PluginSetup; } export interface PluginSetup { (api: PluginAPI, options?: K): MaybePromise; } export declare type PluginLegacy = string | [string, Json] | PluginSetup; export declare type Plugin = _Plugin | PluginLegacy; export declare type PluginAPI = Omit, 'onHook' | 'setValue' | 'getValue'> & Omit & { context: PluginContext & ('context' extends keyof U ? U['context'] : {}); } & Pick, 'onHook' | 'setValue' | 'getValue'>; export declare type CommandName = 'start' | 'build' | 'test' | string; export declare type CommandArgs = Record; export declare type PluginList = Array | Plugin>; export declare type GetBuiltInPlugins = (userConfig: UserConfig) => PluginList; export declare type CommandModule = (context: Context, options: any) => Promise; export declare type RegisterCommandModules = (key: string, module: CommandModule) => void; export interface ContextOptions { command: CommandName; rootDir?: string; configFile?: string | string[]; commandArgs: CommandArgs; plugins?: PluginList; getBuiltInPlugins?: GetBuiltInPlugins; extendsPluginAPI?: U; } export interface TaskConfig { name: U; config: T; modifyFunctions: Array>; } export declare type UserConfig = K & { plugins: PluginList; [key: string]: any; }; export interface ModeConfig { [name: string]: UserConfig; } export interface JestConfigFunction { (JestConfig: Config.InitialOptions): Config.InitialOptions; } export interface ModifyRegisteredConfigCallbacks { (configArgs: T): T; } export declare type UserConfigRegistration = Record>; export declare type CliOptionRegistration = Record>; export interface ModifyConfigRegistration { (configFunc: ModifyRegisteredConfigCallbacks>): void; (configName: string, configFunc: ModifyRegisteredConfigCallbacks>): void; } export interface ModifyCliRegistration { (configFunc: ModifyRegisteredConfigCallbacks>): void; (configName: string, configFunc: ModifyRegisteredConfigCallbacks>): void; } export declare type ModifyRegisteredConfigArgs = [string, ModifyRegisteredConfigCallbacks>] | [ModifyRegisteredConfigCallbacks>]; export declare type ModifyRegisteredCliArgs = [string, ModifyRegisteredConfigCallbacks>] | [ModifyRegisteredConfigCallbacks>]; export declare type OnGetConfigArgs = [string, PluginConfig] | [PluginConfig]; export declare type RegistrationKey = 'modifyConfigRegistrationCallbacks' | 'modifyCliRegistrationCallbacks'; export declare type EmptyObject = {}; export {};