cli-testing-library
Version:
Simple and complete CLI testing utilities that encourage good testing practices.
35 lines (34 loc) • 1.24 kB
JavaScript
import { buildQueries } from "../query-helpers.js";
import { makeNormalizer, matches, fuzzyMatches } from "../matches.js";
const queryByTextBase = (instance, text, { exact = false, collapseWhitespace, trim, normalizer, stripAnsi } = {}) => {
const matcher = exact ? matches : fuzzyMatches;
const matchNormalizer = makeNormalizer({
stripAnsi,
collapseWhitespace,
trim,
normalizer
});
const str = instance.stdoutArr.map((output) => output.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 [_queryByTextWithSuggestions, _getByText, _findByText] = buildQueries(
queryByTextBase,
getMissingError
);
function getByText(...args) {
return _getByText(...args);
}
function queryByText(...args) {
return _queryByTextWithSuggestions(...args);
}
function findByText(...args) {
return _findByText(...args);
}
export {
findByText,
getByText,
queryByText
};
//# sourceMappingURL=text.js.map