UNPKG

@contract-case/cli

Version:

Command-line interface for ContractCase, allowing interactions with the Contract / Pact Broker

57 lines 2.9 kB
import chalk from 'chalk'; import { Console } from 'node:console'; const stdout = new Console({ stdout: process.stdout }); const spaces = (size, str) => { const space = new Array(size).fill(' ').join(''); return `${space}${str.replace(/\n/g, `\n${space}`)}`; }; const printMatchError = async ({ kind, message, location, expected, actual, locationTag, errorTypeTag, }) => { // This is done as one line to prevent it splitting when multiple tests are running stdout.log(`${spaces(6, `${chalk.bgRed.white(` ${kind} `)} ${chalk.whiteBright(location)} ${chalk.whiteBright(message)}`)}\n${spaces(9, `Expected something like:\n${spaces(3, chalk.green(expected))}`)}\n${spaces(9, `Actual:\n${spaces(3, chalk.red(actual))}\n\n${spaces(12, `${chalk.gray(` - ${locationTag} [${errorTypeTag}]`)}`)}`)}\n\n`); }; const printMessageError = async ({ kind, location, message, locationTag, errorTypeTag, }) => { // This is done as one line to prevent it splitting when multiple tests are running stdout.log(`${spaces(6, `${chalk.bgRed.white(` ${kind} `)} ${chalk.whiteBright(location)} ${chalk.whiteBright(message)}`)}\n\n${spaces(12, `${chalk.gray(` - ${locationTag} [${errorTypeTag}]`)}`)}\n\n`); }; const printTestTitle = async ({ kind, icon, title, additionalText, }) => { const colourIcon = kind === 'success' ? chalk.greenBright : chalk.red; // This is done as one line to prevent it splitting when multiple tests are running stdout.log(spaces(3, `\n${colourIcon(icon)} ${chalk.whiteBright(title)}\n${additionalText}`)); }; const defaultResultPrinter = { printMatchError, printMessageError, printTestTitle, }; const defaultLogPrinter = { log: async (level, timestamp, version, typeString, location, message, additional) => { let typeColour = chalk.redBright; let messageColour = chalk.white; if (level === 'warn') { typeColour = chalk.yellowBright; messageColour = chalk.yellowBright; } if (level === 'error') { typeColour = chalk.redBright; messageColour = chalk.redBright; } if (level === 'debug') { typeColour = chalk.cyan; messageColour = chalk.cyan; } if (level === 'maintainerDebug') { typeColour = chalk.bgMagentaBright.black; messageColour = chalk.magentaBright; } if (level === 'deepMaintainerDebug') { typeColour = chalk.bgBlueBright.black; messageColour = chalk.blueBright; } stdout.log(`${timestamp} ${chalk.whiteBright(version)} ${typeColour(typeString)} ${chalk.blueBright(location)}: ${messageColour(message)}${additional !== '' ? `\n${messageColour(additional)}` : ''}`); }, }; export const defaultPrinter = { ...defaultResultPrinter, ...defaultLogPrinter, }; //# sourceMappingURL=defaultResultPrinter.js.map