cli-testing-library
Version:
Simple and complete CLI testing utilities that encourage good testing practices.
35 lines (34 loc) • 1.4 kB
JavaScript
;
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const queryHelpers = require("../query-helpers.cjs");
const matches = require("../matches.cjs");
const queryByErrorBase = (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.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] = queryHelpers.buildQueries(
queryByErrorBase,
getMissingError
);
function getByError(...args) {
return _getByError(...args);
}
function queryByError(...args) {
return _queryByErrorWithSuggestions(...args);
}
function findByError(...args) {
return _findByError(...args);
}
exports.findByError = findByError;
exports.getByError = getByError;
exports.queryByError = queryByError;
//# sourceMappingURL=error.cjs.map