UNPKG

@contract-case/case-core

Version:

Core functionality for the ContractCase contract testing suite

96 lines 4.01 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.logLevel = exports.stringStateVariable = exports.stateVariable = exports.shapedLike = exports.exactlyLike = exports.namedMatch = exports.withExample = exports.and = void 0; const case_entities_internal_1 = require("@contract-case/case-entities-internal"); const case_plugin_base_1 = require("@contract-case/case-plugin-base"); const entities_1 = require("../../../entities"); /** * Meta matcher that matches all matchers provided. Use this to combine matching rules for the same element * * @param matchers - All of the matchers to run against this particular spot */ const and = (...matchers) => (0, entities_1.coreAndMatcher)(...matchers); exports.and = and; /** * Adds an example to the provided matcher. Useful when you have a complicated * set of constraints and Case can't figure out what the best example should be. * * @param matcher - Any matcher * @param example - The example to use when stripping the matchers */ const withExample = (matcher, example) => ({ '_case:matcher:type': case_entities_internal_1.CASCADING_CONTEXT_MATCHER_TYPE, '_case:matcher:child': matcher, '_case:matcher:example': example, }); exports.withExample = withExample; /** * Meta matcher that gives the matcher below it a unique name that can be reused in tests after this one. * * @param uniqueName - The name you can use to match this content later * @param matcherOrData - The content of this named match. If omitted, the content will be looked up in a previously named match */ const namedMatch = (uniqueName, matcherOrData) => matcherOrData === undefined ? (0, entities_1.coreLookupMatcherRequest)(uniqueName) : (0, case_plugin_base_1.coreLookupMatcher)(uniqueName, matcherOrData); exports.namedMatch = namedMatch; /** * Everything inside this matcher will be matched exactly, unless overridden with an `any*` matcher * * Use this to switch out of `shapedLike` and back to the default exact matching. * * @param content - The example object, array, primitive or matcher to match exactly against */ const exactlyLike = (content) => ({ '_case:matcher:type': case_entities_internal_1.CASCADING_CONTEXT_MATCHER_TYPE, '_case:matcher:child': content, '_case:context:matchBy': 'exact', }); exports.exactlyLike = exactlyLike; /** * Everything inside this matcher will be matched on the shape of the data (ie, type alone), unless overriden with other matchers * * Use this to switch out of the default `exactlyLike` matching. * * @param content - The example object, array, primitive or matcher to match against, ignoring content */ const shapedLike = (content) => (0, entities_1.coreShapedLike)(content); exports.shapedLike = shapedLike; /** * Matches the content of a variable from a provider state. * * @param name - The name of the variable */ const stateVariable = (name) => ({ '_case:matcher:type': case_entities_internal_1.CONTEXT_VARIABLE_TYPE, '_case:matcher:variableName': name, }); exports.stateVariable = stateVariable; /** * Matches the content of a variable from a provider state. * * @param name - The name of the variable */ const stringStateVariable = (name) => ({ '_case:matcher:type': case_entities_internal_1.CONTEXT_VARIABLE_TYPE, '_case:matcher:variableName': name, '_case:matcher:resolvesTo': 'string', }); exports.stringStateVariable = stringStateVariable; /** * Alters the case log level below this matcher. Useful for debugging. * * This has no effect on matching. * * Note that this log level change is saved into the contract, which may not be what you want. * * @param logLevel - The new {@link LogLevel} * @param child - The next matcher in the tree. */ const logLevel = (level, child) => ({ '_case:matcher:type': case_entities_internal_1.CASCADING_CONTEXT_MATCHER_TYPE, '_case:matcher:child': child, '_case:currentRun:context:logLevel': level, }); exports.logLevel = logLevel; //# sourceMappingURL=meta.js.map