UNPKG

@bemedev/cli-test

Version:

A library for testing CLI libraries (INCEPTION !!)

77 lines 4.44 kB
import type { prepareEnvironment } from '@gmrchk/cli-testing-library'; import type { Mock, SuiteCollector, TestOptions } from 'vitest'; import type { UserConfig } from 'vitest/config'; export type Define<T> = Exclude<T, undefined>; export type Plugin = Exclude<Define<UserConfig['plugins']>[number], Promise<any> | null | undefined | false | Array<any>>; export type Nomit<T, K extends keyof T> = Omit<T, K>; export type Partialize<T, K extends keyof T> = Nomit<T, K> & Partial<Pick<T, K>>; export type ArgTests = { pathTsd: string; index?: number; name?: string; timeout?: number; }; export type Fn = (...args: any) => any; export type PickBy<T, U> = { [P in keyof T as T[P] extends U ? P : never]: T[P]; }; export type NotPickBy<T, U> = { [P in keyof T as T[P] extends U ? never : P]: T[P]; }; export type PickKeysBy<T, U> = keyof PickBy<T, U>; export type NotPickKeysBy<T, U> = keyof NotPickBy<T, U>; export type PickByFn<T> = PickBy<T, (...args: any) => any>; export type PickByFnKeys<T> = keyof PickByFn<T>; export type Env = Awaited<ReturnType<typeof prepareEnvironment>>; export type MockFsKeys = 'writeFile' | 'readFile' | 'mkdir' | 'rm' | 'readdir' | 'existsSync'; export type Args = Env & { mockFs: (...envs: MockFsKeys[]) => boolean; }; type DefFns = PickByFnKeys<Env>; type Def<K extends DefFns> = [Parameters<Env[K]>, ReturnType<Env[K]>]; export type Defs = { [K in DefFns]: Def<K>; }; export type ConfigDefs = Pick<Env, 'readFile' | 'writeFile' | 'makeDir' | 'removeDir' | 'ls' | 'exists'>; export type BuildMockFn = Mock<[ config: ConfigDefs, ...envs: MockFsKeys[] ], void>; export type MockFn = (args: Args) => void; export type FnString = (...args: any) => string; export type DescribeFnOptional = (invite: string | FnString, fn?: MockFn, options?: number | TestOptions | undefined) => SuiteCollector; export type DescribeFnOptionalParams = Parameters<DescribeFnOptional>; export type DescribeFn = (invite: string | FnString, fn: MockFn, options?: number | TestOptions | undefined) => SuiteCollector; export type DescribeFnParams = Parameters<DescribeFn>; export declare const SIMPLE_TRUE_KEYS: readonly ["only", "concurrent", "sequential", "shuffle"]; export type SimpleFnTrueKeys = (typeof SIMPLE_TRUE_KEYS)[number]; export declare function isSimpleTrueFnKey(value: unknown): value is SimpleFnTrueKeys; export declare const SIMPLE_FALSE_KEYS: readonly ["todo", "skip"]; export type SimpleFnFalseKeys = (typeof SIMPLE_FALSE_KEYS)[number]; export declare function isSimpleFalseFnKey(value: unknown): value is SimpleFnFalseKeys; export declare const SIMPLE_SIDE_EFFECT_KEYS: readonly ["only"]; export type SimpleFnSideEffectKeys = (typeof SIMPLE_SIDE_EFFECT_KEYS)[number]; export declare function isSideEffectFnKey(value: unknown): value is SimpleFnSideEffectKeys; export declare const SIMPLE_NO_SIDE_EFFECT_KEYS: readonly ["sequential", "shuffle", "concurrent", "todo", "skip"]; export type SimpleFnNoSideEffectKeys = (typeof SIMPLE_NO_SIDE_EFFECT_KEYS)[number]; export declare function isNotSideEffectFnKey(value: _SimpleFnKeys): value is SimpleFnNoSideEffectKeys; export declare const SIMPLE_INSIDE_EFFECT_KEYS: readonly ["shuffle", "concurrent"]; export type SimpleFnInsideEffectKeys = (typeof SIMPLE_INSIDE_EFFECT_KEYS)[number]; export declare function isSimpleInsideEffectFnKey(value: unknown): value is SimpleFnInsideEffectKeys; export declare const COMPLEX_KEYS: readonly ["runIf", "skipIf"]; export type ComplexFnKeys = (typeof COMPLEX_KEYS)[number]; export declare const SIMPLE_KEYS: readonly ["only", "concurrent", "sequential", "shuffle", "todo", "skip"]; export type _SimpleFnKeys = (typeof SIMPLE_KEYS)[number]; export type SimpleFnKeys<T extends boolean> = NoInfer<T> extends true ? _SimpleFnKeys : NoInfer<T> extends false ? SimpleFnFalseKeys : _SimpleFnKeys; export type ReturnIfTrue = DescribeFn & Omit<Record<_SimpleFnKeys, DescribeFn>, 'todo'> & { todo: DescribeFnOptional; }; export type ReturnIfBoolean = DescribeFnOptional & Record<_SimpleFnKeys, DescribeFnOptional>; export type ReturnIfFalse = { (invite: string, fn?: MockFn): SuiteCollector; skip: (invite: string, fn?: MockFn) => SuiteCollector; todo: (invite: string, fn?: MockFn) => SuiteCollector; }; export type ReturnIf<T extends boolean> = NoInfer<T> extends true ? ReturnIfTrue : NoInfer<T> extends false ? ReturnIfFalse : ReturnIfBoolean; export {}; //# sourceMappingURL=types.d.ts.map