UNPKG

cypress-terminal-report

Version:

Better terminal and file output for cypress test logs.

34 lines (33 loc) 1.22 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const constants_1 = __importDefault(require("../constants")); const PADDING = ' '; const PADDING_LOGS = PADDING.repeat(6); const SEVERITY_ICON = { [constants_1.default.SEVERITY.ERROR]: 'X', [constants_1.default.SEVERITY.WARNING]: '!', [constants_1.default.SEVERITY.SUCCESS]: 'K', }; const padTypeText = (text) => { return ' '.repeat(Math.max(PADDING_LOGS.length - text.length, 0)) + text; }; const padTimeText = (text) => { return PADDING_LOGS + text; }; function logsTxtFormatter(logs, EOL = '\n') { return logs .map(({ type, message, severity, timeString }) => { let formattedLog = (padTypeText(`${type} (${SEVERITY_ICON[severity]}): `) + message.replace(/\n/g, `${EOL}${PADDING_LOGS}`) + EOL).replace(/\s+\n/, '\n'); if (timeString) { formattedLog = padTimeText(`Time: ${timeString}`) + `\n` + formattedLog; } return formattedLog; }) .join(''); } exports.default = logsTxtFormatter;