cli-testing-library
Version:
Simple and complete CLI testing utilities that encourage good testing practices.
31 lines (29 loc) • 1.06 kB
JavaScript
;
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const sliceAnsi = require("slice-ansi");
const getUserCodeFrame = require("./get-user-code-frame.cjs");
function prettyCLI(testInstance, maxLength) {
if (typeof maxLength !== "number") {
maxLength = typeof process !== "undefined" && Number(process.env.DEBUG_PRINT_LIMIT) || 7e3;
}
if (maxLength === 0) {
return "";
}
if (!("stdoutArr" in testInstance && "stderrArr" in testInstance)) {
throw new TypeError(`Expected an instance but got ${testInstance}`);
}
const outStr = testInstance.getStdallStr();
return maxLength !== void 0 && outStr.length > maxLength ? sliceAnsi(outStr, 0, maxLength) : outStr;
}
const logCLI = (...args) => {
const userCodeFrame = getUserCodeFrame.getUserCodeFrame();
if (userCodeFrame) {
process.stdout.write(`${prettyCLI(...args)}
${userCodeFrame}`);
} else {
process.stdout.write(prettyCLI(...args));
}
};
exports.logCLI = logCLI;
exports.prettyCLI = prettyCLI;
//# sourceMappingURL=pretty-cli.cjs.map