UNPKG

flagpole

Version:

Simple and fast DOM integration, headless or headful browser, and REST API testing framework.

285 lines 9.39 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const _1 = require("."); const flagpole_1 = require("./flagpole"); var ConsoleColor; (function (ConsoleColor) { ConsoleColor["Bold"] = "\u001B[1m"; ConsoleColor["Underlined"] = "\u001B[4m"; ConsoleColor["Reversed"] = "\u001B[7m"; ConsoleColor["Reset"] = "\u001B[0m"; ConsoleColor["Bright"] = "\u001B[1m"; ConsoleColor["Dim"] = "\u001B[2m"; ConsoleColor["Underscore"] = "\u001B[4m"; ConsoleColor["Blink"] = "\u001B[5m"; ConsoleColor["Reverse"] = "\u001B[7m"; ConsoleColor["Hidden"] = "\u001B[8m"; ConsoleColor["FgBlack"] = "\u001B[30m"; ConsoleColor["FgRed"] = "\u001B[31m"; ConsoleColor["FgGreen"] = "\u001B[32m"; ConsoleColor["FgYellow"] = "\u001B[33m"; ConsoleColor["FgBlue"] = "\u001B[34m"; ConsoleColor["FgMagenta"] = "\u001B[35m"; ConsoleColor["FgCyan"] = "\u001B[36m"; ConsoleColor["FgWhite"] = "\u001B[37m"; ConsoleColor["FgBrightBlack"] = "\u001B[30;1m"; ConsoleColor["FgBrightRed"] = "\u001B[31;1m"; ConsoleColor["FgBrightGreen"] = "\u001B[32;1m"; ConsoleColor["FgBrightYellow"] = "\u001B[33;1m"; ConsoleColor["FgBrightBlue"] = "\u001B[34;1m"; ConsoleColor["FgBrightMagenta"] = "\u001B[35;1m"; ConsoleColor["FgBrightCyan"] = "\u001B[36;1m"; ConsoleColor["FgBrightWhite"] = "\u001B[37;1m"; ConsoleColor["BgBlack"] = "\u001B[40m"; ConsoleColor["BgRed"] = "\u001B[41m"; ConsoleColor["BgGreen"] = "\u001B[42m"; ConsoleColor["BgYellow"] = "\u001B[43m"; ConsoleColor["BgBlue"] = "\u001B[44m"; ConsoleColor["BgMagenta"] = "\u001B[45m"; ConsoleColor["BgCyan"] = "\u001B[46m"; ConsoleColor["BgWhite"] = "\u001B[47m"; ConsoleColor["BgBrightBlack"] = "\u001B[40;1m"; ConsoleColor["BgBrightRed"] = "\u001B[41;1m"; ConsoleColor["BgBrightGreen"] = "\u001B[42;1m"; ConsoleColor["BgBrightYellow"] = "\u001B[43;1m"; ConsoleColor["BgBrightBlue"] = "\u001B[44;1m"; ConsoleColor["BgBrightMagenta"] = "\u001B[45;1m"; ConsoleColor["BgBrightCyan"] = "\u001B[46;1m"; ConsoleColor["BgBrightWhite"] = "\u001B[47;1m"; })(ConsoleColor = exports.ConsoleColor || (exports.ConsoleColor = {})); var LogLineType; (function (LogLineType) { LogLineType[LogLineType["Pass"] = 0] = "Pass"; LogLineType[LogLineType["Fail"] = 1] = "Fail"; LogLineType[LogLineType["Comment"] = 2] = "Comment"; LogLineType[LogLineType["Detail"] = 3] = "Detail"; LogLineType[LogLineType["Heading"] = 4] = "Heading"; LogLineType[LogLineType["Subheading"] = 5] = "Subheading"; LogLineType[LogLineType["Decoration"] = 6] = "Decoration"; })(LogLineType = exports.LogLineType || (exports.LogLineType = {})); class LogLine { constructor(message) { this.color = ConsoleColor.FgWhite; this.textPrefix = ''; this.textSuffix = ''; this.message = ''; this.type = LogLineType.Comment; this.timestamp = new Date(); this.message = message; } getMergedString() { return `${this.textPrefix} ${this.message} ${this.textSuffix}`; } getClassName() { return LogLineType[this.type]; } print() { if (!_1.Flagpole.quietMode) { let line = ''; let style = _1.Flagpole.output; if (style == flagpole_1.FlagpoleOutput.text) { line = this.toString(); } else if (style == flagpole_1.FlagpoleOutput.html) { line = this.toHTML(); } else if (style == flagpole_1.FlagpoleOutput.json) { let json = this.toJson(); if (typeof json != 'string') { line = JSON.stringify(json); } } else if (style == flagpole_1.FlagpoleOutput.csv) { line = this.toCsv(); } else if (style == flagpole_1.FlagpoleOutput.tsv) { line = this.toTsv(); } else if (style == flagpole_1.FlagpoleOutput.psv) { line = this.toPsv(); } else { line = this.toConsoleString(); } if (line.length > 0) { console.log(line); } } } toConsoleString() { return this.color + this.getMergedString() + ConsoleColor.Reset; } toCsv() { return `"${this.timestamp.toUTCString()}","${this.getClassName()}","` + `${this.textPrefix}","${this.message}","${this.textSuffix}"`; } toTsv() { return this.timestamp.toUTCString() + "\t" + this.getClassName() + "\t" + this.textPrefix + "\t" + this.message + "\t" + this.textSuffix; } toPsv() { return `${this.timestamp.toUTCString()}|${this.getClassName()}|${this.textPrefix}|${this.message}|${this.textSuffix}`; } toString() { return this.getMergedString(); } toHTML() { return `<li class="${this.getClassName()}">${this.message}` + (this.textSuffix.length > 0 ? ` <span class="note">${this.textSuffix}</span>` : '') + "</li>\n"; } toJson() { return { type: this.getClassName(), message: this.message }; } } LogLine.targetLineLength = 72; exports.LogLine = LogLine; class HeadingLine extends LogLine { constructor(message) { super(message); this.color = ConsoleColor.FgYellow; this.type = LogLineType.Heading; } getMergedString() { let text = super.getMergedString().trim(); let padLength = Math.ceil((LogLine.targetLineLength - text.length) / 2); return ' '.repeat(padLength) + text + ' '.repeat(padLength); } toHTML() { return `<h2 class="${this.getClassName()}">${this.message}</h2>`; } } exports.HeadingLine = HeadingLine; class SubheadingLine extends LogLine { constructor(message) { super(message); this.color = ConsoleColor.FgWhite; this.type = LogLineType.Subheading; } toHTML() { return `<h3 class="${this.getClassName()}">${this.message}</h3>`; } } exports.SubheadingLine = SubheadingLine; class DecorationLine extends LogLine { constructor(message) { super(message); this.color = ConsoleColor.FgYellow; this.type = LogLineType.Decoration; } toHTML() { return `<div class="${this.getClassName()}">${this.message}</div>`; } toJson() { return ''; } } exports.DecorationLine = DecorationLine; class HorizontalRule extends LogLine { constructor(message = '=') { super(message); this.color = ConsoleColor.FgYellow; this.type = LogLineType.Decoration; } getMergedString() { let text = this.message.trim(); let reps = Math.ceil(LogLine.targetLineLength / text.length); return text.repeat(reps); } toHTML() { return '<hr class="decoration" />'; } toJson() { return ''; } } exports.HorizontalRule = HorizontalRule; class CustomLine extends LogLine { constructor(message, color) { super(message); this.color = color; this.type = LogLineType.Comment; } toHTML() { return `<div class="${this.getClassName()}">${this.message}</div>`; } toJson() { return ''; } } exports.CustomLine = CustomLine; class LineBreak extends LogLine { constructor() { super(' '); this.type = LogLineType.Decoration; } toHTML() { return '<br />'; } toJson() { return ''; } } exports.LineBreak = LineBreak; class CommentLine extends LogLine { constructor(message) { super(message); this.textPrefix = ' » '; this.color = ConsoleColor.FgCyan; this.type = LogLineType.Comment; } } exports.CommentLine = CommentLine; class PassLine extends LogLine { constructor(message) { super(message); this.textPrefix = ' ✔ '; this.color = ConsoleColor.FgGreen; this.type = LogLineType.Pass; } } exports.PassLine = PassLine; class FailLine extends LogLine { constructor(message) { super(message); this.textPrefix = ' ✕ '; this.color = ConsoleColor.FgRed; this.type = LogLineType.Fail; } } exports.FailLine = FailLine; class OptionalFailLine extends LogLine { constructor(message) { super(message); this.textPrefix = ' ✕ '; this.color = ConsoleColor.FgMagenta; this.type = LogLineType.Comment; this.textSuffix = '[Optional]'; } } exports.OptionalFailLine = OptionalFailLine; class WarningLine extends LogLine { constructor(message) { super(message); this.textPrefix = ' ! Warning: '; this.color = ConsoleColor.FgBrightYellow; this.type = LogLineType.Comment; } } exports.WarningLine = WarningLine; class DetailLine extends LogLine { constructor(message) { super(message); this.textPrefix = ' '; this.color = ConsoleColor.FgBrightYellow; this.type = LogLineType.Comment; } toHTML() { return `<li class="${this.getClassName()}"><blockquote class="code">${this.message}</blockquote></li>`; } } exports.DetailLine = DetailLine; //# sourceMappingURL=consoleline.js.map