UNPKG

@ibgib/helper-gib

Version:

common helper/utils/etc used in ibgib libs. Node v19+ needed for heavily-used isomorphic webcrypto hashing consumed in both node and browsers.

222 lines 6.52 kB
export interface InfoBase { /** * Log context. */ lc?: string; /** * If true, performs lots of trace verbose logging respeculation stuff. */ logalot?: boolean; } export type MaybeAsyncFn<TReturn = void> = (() => TReturn) | (() => Promise<TReturn>); export interface RespecFunctionInfo extends InfoBase { fn: MaybeAsyncFn; } export interface IfWeBlock extends InfoBase { } export interface RespecInfo extends InfoBase { /** * file path of spec. use meta.import.url */ title: string; kind: 'respecfully' | 'ifwe'; bodyFn: MaybeAsyncFn; parent?: RespecInfo; subBlocks: RespecInfo[]; /** * function(s) that execute before any respeculations. */ fnFirstOfAlls: MaybeAsyncFn[]; fnFirstOfAllsComplete?: boolean; /** * function(s) that execute before each respeculation. */ fnFirstOfEachs: MaybeAsyncFn[]; /** * function(s) that execute after any respeculations. */ fnLastOfAlls: MaybeAsyncFn[]; fnLastOfAllsComplete?: boolean; /** * function(s) that execute after each respeculation. */ fnLastOfEachs: MaybeAsyncFn[]; /** * If the respecful block contains a reckoning via `iReckon`, then this will * be contain the resulting object of that reckoning. */ reckonings: Reckoning[]; /** * if true, block as completed execution */ complete?: boolean; error?: any; /** * todo: stopOnFailure */ /** * If true, then this block is being focused on in testing. This is a way * to isolate testing (like if you're working on testing one particular * function). */ extraRespecful?: boolean; } export interface RespecOptions { overrideLc?: string; logalot?: boolean; /** * If true, then we're just checking the respec lib itself. This will not * include the block/reckoning in the final report. */ justMetaTesting?: boolean; /** * If true, then this block is being focused on in testing. This is a way * to isolate testing (like if you're working on testing one particular * function). */ extraRespecful?: boolean; } /** * todo: fill this out with whitelisted function names. */ export type ReckoningFunctionName = 'willEqual' | string; export interface ReckoningOptions { overrideLc?: string; addedMsg?: string; /** * If true, then we're just checking the respec lib itself. This will not * include the block/reckoning in the final report. */ justMetaTesting?: boolean; } export interface ReckoningInfo { /** * fn name to execute */ fnName?: ReckoningFunctionName | undefined; /** * need to rename. This is what the reckoning is testing against this.value * for some tests. */ x?: any | undefined; /** * Optional addedMsg */ addedMsg: string | undefined; } export declare class RespecGib { /** * All respec paths that were found with the given regexp and root * directory. */ allRespecPaths: string[]; /** * the paths of respec files after taking into account filtering. * This includes atow "extra respec". */ filteredRespecPaths: string[] | undefined; /** * Paths to respec files that were actually done. This is either going to be * `allRespecPaths` or `filteredRespecPaths`. */ respecPaths: string[]; /** * If true, then we are looking for - and have found - files/blocks with * extra respec. * * Note that atow (03/2024), this affects ONLY reporting of test results. In * the future, we may add a separate flag. */ extraRespecOnly: boolean; respecs: { [title: string]: RespecInfo[]; }; errorMsgs: string[]; ifWeBlocksSkipped: number; } export declare class Reckoning { #private; private value; private logalot; private extraLabel; failMsg: string | undefined; justMetaTesting: boolean | undefined; get not(): Reckoning; completed: Promise<boolean> | undefined; constructor(value: any, logalot?: boolean); /** * gives extra context for the test message. * * @param extraLabel for additional context info for the reckoning * @returns this reckoning for fluent method-chaining */ asTo(extraLabel: string): Reckoning; /** * wrapper/synonym for {@link asTo}. * * @see {@link asTo} */ wrt(extraLabel: string): Reckoning; /** * checks for strict equals ===. * * @param x value to test against this.value * @param opts * @returns this reckoning for fluent method-chaining */ willEqual(x: any, opts?: ReckoningOptions): Reckoning; /** * checks for strict equals ===. * the same as willEqual atow * * @param x value to test against this.value * @param opts * @returns true if passes, false if fails */ isGonnaBe(x: any, opts?: ReckoningOptions): Reckoning; /** * checks for truthy of this.value * * @param opts * @returns true if passes, false if fails */ isGonnaBeTruthy(opts?: ReckoningOptions): Reckoning; isGonnaBeFalsy(opts?: ReckoningOptions): Reckoning; /** * checks for this.value === true (unless not'd) * * @param opts * @returns true if passes, false if fails */ isGonnaBeTrue(opts?: ReckoningOptions): Reckoning; /** * checks for this.value === false (unless not'd) * * @param opts * @returns true if passes, false if fails */ isGonnaBeFalse(opts?: ReckoningOptions): Reckoning; /** * checks for this.value === undefined (unless not'd) * * @param opts * @returns true if passes, false if fails */ isGonnaBeUndefined(opts?: ReckoningOptions): Reckoning; /** * checks for this.value.includes(x) (unless not'd) * * @param x value to check for inclusion in this.value * @param opts * @returns true if passes, false if fails */ includes(x: any, opts?: ReckoningOptions): Reckoning; /** * long silly names means I need to refactor them. it's an indicator, conscious decision. eesh. * @param lc log context * @param error catch block error * @returns error msg with extraLabel if assigned */ getErrorMsgLabeledAndWhatnot(lc: string, addedMsg: string | undefined, error: any): string; } //# sourceMappingURL=respec-gib-types.d.mts.map