UNPKG

@contract-case/case-plugin-base

Version:

Plugin framework for writing plugins for the ContractCase test framework

109 lines 4.97 kB
import { CaseMockDescriptorFor } from '@contract-case/case-plugin-dsl-types'; import { MatcherExecutor } from './matchers/types'; import { CaseMatcherFor, IsCaseNodeForType } from './matchers/utility.types'; import { IsMockDescriptorForType, MockExecutor } from './mocks/executors.types'; import { PluginDslDeclaration } from './dsl/types'; export * from './corePlugins'; export * from './context/types'; export * from './logger/types'; export * from './matchers/types'; export * from './mocks/types'; export * from './dsl/types'; /** * Describes the plugin name and version * @public */ export type PluginDescription = { /** * The full name of the plugin, for humans. This is printed in error messages * about the plugin. */ humanReadableName: string; /** * The short name of the plugin, for convenience in configuration. * * This is the key used by the mockConfig configuration property. * It should be reasonably unique. If two plugins share a shortName, they * might not be able to be loaded during the same run, as plugins validate * their `mockConfig[shortName]` setting. * * If you have two plugins that need the same configuration properties, * it's fine for them to share their shortName. */ shortName: string; /** * A unique machine name, used to reason about the plugin's load state when * loading a plugin. This must be unique in the plugin ecosystem, * as two plugins with the same uniqueMachineName can't be loaded in the same * contract. For this reason, it is recommended you namespace your plugin * names with a common prefix. * * This is different from the shortname above, since you might have multiple * plugins wanting to share configuration, and the global uniqueness * constraint means that the uniqueMachineName might be too clumsy for a user * to comfortably use them as a configuration key. * * Plugins for distribution with ContractCase have their unique names * prefixed with {@link CORE_PLUGIN_PREFIX}. This is used to control the * logging and error messages during plugin loads. To keep the logs and error * messages correct, only use this prefix if you are developing core a plugin. */ uniqueMachineName: string; /** * The version of this plugin, used to reason about it at load time. * Must be a semantic version string. See {@link https://semver.org/} for * details. */ version: string; }; /** * Represents just the part of a plugin that can be used to generate DSL classes. * This is exported seprately, as processors that want to use the DSL declaration * might not know (or care about) the type parameters for the overall plugin. */ export type ContractCaseDslPlugin = { description: PluginDescription; /** * Declares DSL classes that can be generated by the DSL generator. */ dsl?: PluginDslDeclaration; }; /** * Represents a plugin for the ContractCase contract testing framework. * * A plugin can defines custom matchers or mock setups for testing different cases. * * It also can declare DSL objects, so that the matchers and interactions * defined in the plugin can be generated in each supported language. * * @public * @typeParam MatcherTypes - A union type of string constants for the matcher types supported by the plugin. * @typeParam MockTypes - A union type of string constants for the mocks types supported by the plugin. * @typeParam MatcherDescriptors - A union type of all matcher descriptor objects for the matchers supplied by this plugin. * @typeParam MockDescriptors - T A union type of all mock descriptor objects for the mocks supplied by this plugin * @typeParam AllSetupInfo - A union type representing the setup information required for all mocks supplied by this plugin. */ export type ContractCasePlugin<MatcherTypes extends string, MockTypes extends string, MatcherDescriptors extends IsCaseNodeForType<MatcherTypes>, MockDescriptors extends IsMockDescriptorForType<MockTypes>, AllSetupInfo> = ContractCaseDslPlugin & { description: PluginDescription; /** * Matcher executors determine how matchers run. These are keyed by the types * of matchers in your plugin. See the {@link MatcherExecutor} documentation * for details. */ matcherExecutors: { [T in MatcherTypes]: MatcherExecutor<T, CaseMatcherFor<MatcherDescriptors, T>>; }; /** * Mock executors determine how the mock side of an interaction runs. * These are keyed by the types of mocks in your plugin. * * Note that Mock, Interaction, and Example are used interchangeably * in some places. * * See the {@link MockExecutor} documentation for details. */ setupMocks: { [T in MockTypes]: MockExecutor<T, CaseMockDescriptorFor<MockDescriptors, T>, AllSetupInfo>; }; }; //# sourceMappingURL=types.d.ts.map