UNPKG

@contract-case/case-core

Version:

Core functionality for the ContractCase contract testing suite

55 lines 3.36 kB
import { MatchContext, ResultFormatter, LogLevelContext, Logger, MatchContextWithoutLookup, MatchResult } from '@contract-case/case-plugin-base'; import { AnyCaseMatcher } from '@contract-case/case-entities-internal'; import { AnyCaseMatcherOrData, AnyData, AnyLeafOrStructure } from '@contract-case/case-plugin-dsl-types'; import type { CaseConfig, DefaultConfig } from './config/types'; import { ContractData, CaseContractDescription } from '../entities/types'; type UserProvidedFunction = (...args: unknown[]) => Promise<unknown>; export declare class BaseCaseContract { currentContract: ContractData; initialContext: MatchContext; /** * The currently executing context. Used to make it easy to do things * like get state variables during a stripMatchers call inside a test trigger */ runningContext: MatchContext; userProvidedFunctions: Record<string, UserProvidedFunction>; constructor(description: CaseContractDescription, config: CaseConfig, defaultConfig: DefaultConfig, resultPrinter: ResultFormatter, makeLogger: (context: LogLevelContext) => Logger, parentVersions: Array<string>, userProvidedFunctions?: Record<string, UserProvidedFunction>); registerFunction(handle: string, invokeableFn: UserProvidedFunction): void; invokeFunctionByHandle(handle: string, callerArguments: unknown[], context: MatchContextWithoutLookup): Promise<unknown>; lookupVariable(name: string, context: MatchContextWithoutLookup): AnyCaseMatcherOrData; addVariable(name: string, type: 'default' | 'state', stateName: string, value: AnyCaseMatcherOrData, context: MatchContextWithoutLookup): [name: string, value: AnyCaseMatcherOrData]; saveLookupableMatcher(namedMatcher: AnyCaseMatcherOrData, context: MatchContextWithoutLookup): ContractData; lookupMatcher(uniqueName: string, context: MatchContextWithoutLookup): AnyCaseMatcherOrData; /** * Strips the matchers from a (potentially) case matcher and returns * the concrete example it would match. * * Note this isn't the only example it could match - just the default version. * * WARNING: If called outside a test, this function runs using the context of * the last test run. This means that state variables might not be correct. * Perhaps we should consider making it an error to call this if a test * isn't running? * * @param matcherOrData - the matcher or data to strip the matchers from * @returns the concrete example */ stripMatchers(matcherOrData: AnyCaseMatcher | AnyLeafOrStructure): AnyData; /** * Checks if a matcher matchers some actual data. * * This is only exposed for tests at the moment - if it were exposed further, * we'd need to use the running test context like stripMatchers does. * * * WARNING: If called outside a test, this function runs using the context of * the last test run. This means that state variables might not be correct. * * @param matcherOrData - the matcher or data that is expected * @param actual - the actual data to match against * @returns a {@link MatchResult} object with the results of the match */ checkMatch(matcherOrData: AnyCaseMatcher | AnyLeafOrStructure, actual: unknown): Promise<MatchResult>; } export {}; //# sourceMappingURL=BaseCaseContract.d.ts.map