import { CB, Nullable } from 'vest-utils'; import { StandardSchemaV1 } from 'vest-utils/standardSchemaSpec'; import { TIsolateSuite } from '../core/isolate/IsolateSuite/IsolateSuite'; import { Severity } from './Severity'; import { SummaryFailure } from './SummaryFailure'; import { SuiteSelectors } from './selectors/suiteSelectors'; import { SuiteModifiers } from '../suite/SuiteTypes'; export class SummaryBase { public errorCount = 0; public warnCount = 0; public testCount = 0; public pendingCount = 0; } export class SuiteSummary< F extends TFieldName, G extends TGroupName, D = unknown, S extends TSchema = undefined, > extends SummaryBase { public [Severity.ERRORS]: SummaryFailure[] = []; public [Severity.WARNINGS]: SummaryFailure[] = []; public groups: Groups = {} as Groups; public tests: Tests = {} as Tests; public run!: { data: { raw: D | undefined; parsed: Partial> | undefined; }; time: Date; focus?: SuiteModifiers; }; public valid: Nullable = null; constructor() { super(); Object.defineProperty(this, 'run', { configurable: true, enumerable: false, value: { data: { raw: undefined, parsed: undefined, }, time: new Date(0), }, writable: true, }); } } export type TestsContainer = | Group | Tests; export type Groups = { [key in G]: Group; }; type Group = { [key in F]: SingleTestSummary; } & ValidProperty; export type Tests = { [key in F]: SingleTestSummary }; export type SingleTestSummary = SummaryBase & CommonSummaryProperties & ValidProperty; type ValidProperty = { valid: Nullable; }; export type CommonSummaryProperties = SummaryBase & { errors: string[]; warnings: string[]; }; export type GetFailuresResponse = FailureMessages | string[]; export type FailureMessages = Record; export type TSchema = any; export type InferSchemaData = S extends { '~standard': { types: { input: infer I } }; } ? I : S extends { infer: infer T } ? { [K in keyof T]: T[K] } & NonNullable : any; export type InferSchemaOutput = S extends { '~standard': { types: { output: infer O } }; } ? O : S extends { infer: infer T } ? { [K in keyof T]: T[K] } & NonNullable : any; type SuiteResultData< F extends TFieldName, G extends TGroupName, S extends TSchema = undefined, D = unknown, > = | (Omit, 'valid'> & SuiteSelectors & { valid: true; value: InferSchemaOutput; issues?: undefined; }) | (Omit, 'valid'> & SuiteSelectors & { valid: false; issues: ReadonlyArray; value?: undefined; }) | (Omit, 'valid'> & SuiteSelectors & { valid: null; issues?: undefined; value?: undefined; }); type BrandedFieldName = F & TFieldName; type BrandedGroupName = G & TGroupName; export type SuiteResult< F extends string = TFieldName, G extends string = TGroupName, S extends TSchema = undefined, D = unknown, > = SuiteResultData, BrandedGroupName, S, D> & { dump: CB; types: S extends undefined ? undefined : { input: InferSchemaData; output: InferSchemaOutput }; }; // Public-facing aliases remain plain strings; internals can still brand via FieldName/GroupName. export type TFieldName = string; export type TGroupName = string;