UNPKG

cli-testing-library

Version:

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

31 lines (29 loc) 928 B
import sliceAnsi from "slice-ansi"; import { getUserCodeFrame } from "./get-user-code-frame.js"; 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(); if (userCodeFrame) { process.stdout.write(`${prettyCLI(...args)} ${userCodeFrame}`); } else { process.stdout.write(prettyCLI(...args)); } }; export { logCLI, prettyCLI }; //# sourceMappingURL=pretty-cli.js.map