@contract-case/case-plugin-base
Version:
Plugin framework for writing plugins for the ContractCase test framework
82 lines • 3.5 kB
TypeScript
import { AnyCaseMatcherOrData, InternalContractCaseCoreSetup, SetupInfoFor } from '@contract-case/case-plugin-dsl-types';
import { MatchContext } from '../context/types';
/**
* Represents the output state of a mock's execution, including what was expected.
* @public
*/
export type MockOutput = {
/**
* The actual data received by this mock, formatted by the executor.
*/
actual: unknown;
/**
* The expectations at this point from the matcher
*/
expected: AnyCaseMatcherOrData;
/**
* The current match context at this point in the matching
*/
context: MatchContext;
};
/**
* Represents the data produced by an invocation of a mock, ready for assertion.
* @public
* @typeParam AllSetupInfo - All known SetupInfo objects
* @typeParam T - the type of the mock descriptor that this data is for
*/
export type MockData<AllSetupInfo, T extends string> = {
config: SetupInfoFor<AllSetupInfo, T>;
/**
* Returns the results of the mock invocation, but without any assertions run on it.
*
* If your mock generates its own triggers, generate and call them during the execution of the assertableData method.
* If the trigger fails, throw either a CaseConfigurationError (in the case of
* user-supplied configuration mistakes or their code throwing unexpected
* errors), or a CaseCoreError if your plugin has crashed.
*
* @returns the {@link MockOutput} that can be asserted on.
*/
assertableData: () => Promise<MockOutput>;
};
/**
* A function that will set up and run a mock.
*
* During the execution of this function, you should validate the mock
* descriptor is correctly formed, and any configuration properties on the
* context that your plugin requires are present and correctly formed.
*
* Additionally, any listeners (eg http servers) that the mock requires should be
*
* @public
* @typeParam AllMockDescriptors - All known MockDescriptor objects
* @typeParam AllSetupInfo - All known SetupInfo objects
* @typeParam T - the type of the mock descriptor that this function consumes
* @param mock - The mock descriptor object that the user provides
* @param context - The {@link MatchContext} object for this run
* @returns - a Promise of the {@link MockData} resulting from this execution
*/
export type MockExecutorFn<Descriptor extends IsMockDescriptorForType<T>, AllSetupInfo, T extends string> = (mock: Descriptor, context: MatchContext) => Promise<MockData<AllSetupInfo, T>>;
/**
* The base type for a case matcher descriptor that has this string constant
* @public
*/
export interface IsMockDescriptorForType<T extends string> {
'_case:mock:type': T;
'_case:run:context:setup': InternalContractCaseCoreSetup;
}
/**
* Describes a mock executor for a plugin
*/
export type MockExecutor<MockType extends string, Descriptor extends IsMockDescriptorForType<MockType>, AllSetupInfo> = {
/** The actual executor that will set up the mock in a listening state */
executor: MockExecutorFn<Descriptor, AllSetupInfo, MockType>;
/**
* A function that will ensure that any sub-interactions have unique names
*
* If you don't have any plugin-provided context, and you're using the default
* `request` and `response` properties, you can use the `defaultNameMock`
* function from this package.
*/
ensureMatchersAreNamed: (mock: Descriptor, context: MatchContext) => Descriptor;
};
//# sourceMappingURL=executors.types.d.ts.map