UNPKG

cli-testing-library

Version:

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

35 lines (34 loc) 1.25 kB
import { buildQueries } from "../query-helpers.js"; import { makeNormalizer, matches, fuzzyMatches } from "../matches.js"; const queryByErrorBase = (instance, text, { exact = false, collapseWhitespace, trim, normalizer, stripAnsi } = {}) => { const matcher = exact ? matches : fuzzyMatches; const matchNormalizer = makeNormalizer({ stripAnsi, collapseWhitespace, trim, normalizer }); const str = instance.stderrArr.map((obj) => obj.contents).join("\n"); if (matcher(str, instance, text, matchNormalizer)) return instance; else return null; }; const getMissingError = (_c, text) => `Unable to find an stdout line with the text: ${text}. This could be because the text is broken up by multiple lines. In this case, you can provide a function for your text matcher to make your matcher more flexible.`; const [_queryByErrorWithSuggestions, _getByError, _findByError] = buildQueries( queryByErrorBase, getMissingError ); function getByError(...args) { return _getByError(...args); } function queryByError(...args) { return _queryByErrorWithSuggestions(...args); } function findByError(...args) { return _findByError(...args); } export { findByError, getByError, queryByError }; //# sourceMappingURL=error.js.map