cli-testing-library
Version:
Simple and complete CLI testing utilities that encourage good testing practices.
35 lines (34 loc) • 1.39 kB
JavaScript
;
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const queryHelpers = require("../query-helpers.cjs");
const matches = require("../matches.cjs");
const queryByTextBase = (instance, text, { exact = false, collapseWhitespace, trim, normalizer, stripAnsi } = {}) => {
const matcher = exact ? matches.matches : matches.fuzzyMatches;
const matchNormalizer = matches.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] = queryHelpers.buildQueries(
queryByTextBase,
getMissingError
);
function getByText(...args) {
return _getByText(...args);
}
function queryByText(...args) {
return _queryByTextWithSuggestions(...args);
}
function findByText(...args) {
return _findByText(...args);
}
exports.findByText = findByText;
exports.getByText = getByText;
exports.queryByText = queryByText;
//# sourceMappingURL=text.cjs.map