UNPKG

cli-testing-library

Version:

Simple and complete CLI testing utilities that encourage good testing practices.

49 lines (48 loc) 2.26 kB
import { TestInstance } from './types.js'; export type MatcherFunction = (content: string, element: TestInstance | null) => boolean; export type Matcher = MatcherFunction | RegExp | number | string; export type NormalizerFn = (text: string) => string; export interface NormalizerOptions extends DefaultNormalizerOptions { normalizer?: NormalizerFn; } export interface MatcherOptions { exact?: boolean; /** Use normalizer with getDefaultNormalizer instead */ trim?: boolean; /** Use normalizer with getDefaultNormalizer instead */ stripAnsi?: boolean; /** Use normalizer with getDefaultNormalizer instead */ collapseWhitespace?: boolean; normalizer?: NormalizerFn; /** suppress suggestions for a specific query */ suggest?: boolean; } export type Match = (textToMatch: string, node: TestInstance | null, matcher: Matcher, options?: MatcherOptions) => boolean; export interface DefaultNormalizerOptions { trim?: boolean; collapseWhitespace?: boolean; stripAnsi?: boolean; } /** * @private */ declare function fuzzyMatches(textToMatch: string, node: TestInstance | null, matcher: Matcher, normalizer: NormalizerFn): boolean; /** * @private */ declare function matches(textToMatch: string, node: TestInstance | null, matcher: Matcher, normalizer: NormalizerFn): boolean; declare function getDefaultNormalizer({ trim, collapseWhitespace, stripAnsi, }?: DefaultNormalizerOptions): NormalizerFn; /** * @param {Object} props * Constructs a normalizer to pass to functions in matches.js * @param {boolean|undefined} props.trim The user-specified value for `trim`, without * any defaulting having been applied * @param {boolean|undefined} props.stripAnsi The user-specified value for `stripAnsi`, without * any defaulting having been applied * @param {boolean|undefined} props.collapseWhitespace The user-specified value for * `collapseWhitespace`, without any defaulting having been applied * @param {Function|undefined} props.normalizer The user-specified normalizer * @returns {Function} A normalizer */ declare function makeNormalizer({ trim, stripAnsi, collapseWhitespace, normalizer, }: NormalizerOptions): NormalizerFn; export { fuzzyMatches, matches, getDefaultNormalizer, makeNormalizer };