flagpole
Version:
Simple and fast DOM integration, headless or headful browser, and REST API testing framework.
235 lines • 7.77 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const common_tags_1 = require("common-tags");
const cli_ansi_1 = require("cli-ansi");
class ConsoleLine {
constructor(message) {
this.textPrefix = "";
this.textSuffix = "";
this.message = "";
this.fg = [255, 255, 255];
this.type = "comment";
this.timestamp = new Date();
this.message = message;
}
toString() {
return `${this.textPrefix} ${this.message} ${this.textSuffix}`;
}
toConsoleString() {
return cli_ansi_1.default.fgRgb(this.toString(), this.fg[0], this.fg[1], this.fg[2]);
}
}
exports.ConsoleLine = ConsoleLine;
ConsoleLine.targetLineLength = 72;
class HeadingLine extends ConsoleLine {
constructor(message) {
super(message);
this.fg = [255, 255, 0];
this.type = "h1";
}
toString() {
let text = super.toString().trim();
let padLength = Math.ceil((ConsoleLine.targetLineLength - text.length) / 2);
return common_tags_1.oneLine `
${"=".repeat(padLength)}
${text}
${"=".repeat(padLength)}
`;
}
}
exports.HeadingLine = HeadingLine;
class SubheadingLine extends ConsoleLine {
constructor(message) {
super(message);
this.fg = [255, 255, 0];
this.type = "h2";
}
toString() {
let text = super.toString().trim();
return ` ${cli_ansi_1.default.fgYellow(cli_ansi_1.default.underlined(text))} \n`;
}
}
exports.SubheadingLine = SubheadingLine;
class SectionHeadingLine extends ConsoleLine {
constructor(message) {
super(message);
this.fg = [255, 255, 255];
this.type = "h3";
}
toString() {
let text = super.toString().trim();
return ` ${cli_ansi_1.default.fgWhite(cli_ansi_1.default.bold(text))}`;
}
}
exports.SectionHeadingLine = SectionHeadingLine;
class CustomLine extends ConsoleLine {
constructor(message, fg) {
super(message);
this.fg = fg;
this.type = "comment";
}
}
exports.CustomLine = CustomLine;
class LineBreak extends ConsoleLine {
constructor() {
super(" ");
this.type = "decoration";
}
}
exports.LineBreak = LineBreak;
class CommentLine extends ConsoleLine {
constructor(message) {
super(message);
this.textPrefix = "»";
this.fg = [0, 255, 255];
this.type = "comment";
}
toConsoleString() {
return common_tags_1.oneLine `
${cli_ansi_1.default.bgRgb(cli_ansi_1.default.fgBlack(" " + this.textPrefix + " "), 150, 150, 150)}
${cli_ansi_1.default.fgRgb(this.message, 120, 120, 120)}
`;
}
}
exports.CommentLine = CommentLine;
class PassLine extends ConsoleLine {
constructor(message) {
super(message);
this.textPrefix = "✔";
this.fg = [0, 255, 0];
this.type = "resultPass";
}
toConsoleString() {
return common_tags_1.oneLine `
${cli_ansi_1.default.bgGreen(cli_ansi_1.default.fgWhite(" " + this.textPrefix + " "))}
${this.message}
`;
}
}
exports.PassLine = PassLine;
class ActionCompletedLine extends PassLine {
constructor(verb, noun) {
super(`${verb} ${noun}`);
this._verb = verb;
this._noun = noun;
this.type = "comment";
}
toConsoleString() {
return common_tags_1.oneLine `
${cli_ansi_1.default.bgGreen(cli_ansi_1.default.fgWhite(" " + this.textPrefix + " "))}
${cli_ansi_1.default.bgRgb(` ${this._verb} `, 65, 65, 65)}
${cli_ansi_1.default.fgRgb(this._noun, 120, 120, 120)}
`;
}
}
exports.ActionCompletedLine = ActionCompletedLine;
class FailLine extends ConsoleLine {
constructor(message) {
super(message);
this.textPrefix = "✕";
this.fg = [255, 0, 0];
this.type = "resultFailure";
}
toConsoleString() {
return common_tags_1.oneLine `
${cli_ansi_1.default.bgRed(cli_ansi_1.default.fgWhite(" " + this.textPrefix + " "))}
${this.message}
`;
}
}
exports.FailLine = FailLine;
class ActionFailedLine extends FailLine {
constructor(verb, noun) {
super(`${verb} ${noun}`);
this._verb = verb;
this._noun = noun;
this.type = "resultFailure";
}
toConsoleString() {
return common_tags_1.oneLine `
${cli_ansi_1.default.bgRed(cli_ansi_1.default.fgWhite(" " + this.textPrefix + " "))}
${cli_ansi_1.default.bgRgb(` ${this._verb} `, 65, 65, 65)}
${cli_ansi_1.default.fgRgb(this._noun, 120, 120, 120)}
`;
}
}
exports.ActionFailedLine = ActionFailedLine;
class OptionalFailLine extends ConsoleLine {
constructor(message) {
super(message);
this.textPrefix = "✕";
this.fg = [255, 100, 100];
this.type = "resultOptionalFailure";
this.textSuffix = "[Optional]";
}
toConsoleString() {
return common_tags_1.oneLine `
${cli_ansi_1.default.bgMagenta(cli_ansi_1.default.fgWhite(" " + this.textPrefix + " "))}
${this.message} [Optional]
`;
}
}
exports.OptionalFailLine = OptionalFailLine;
class WarningLine extends ConsoleLine {
constructor(message) {
super(message);
this.textPrefix = "!";
this.fg = [255, 100, 100];
this.type = "comment";
}
toConsoleString() {
return common_tags_1.oneLine `
${cli_ansi_1.default.bgMagenta(cli_ansi_1.default.fgWhite(" " + this.textPrefix + " "))}
${this.message}
`;
}
}
exports.WarningLine = WarningLine;
class DetailLine extends ConsoleLine {
constructor(message) {
super(message);
this.textPrefix = "…";
this.fg = [255, 255, 0];
this.type = "detail";
}
toConsoleString() {
return common_tags_1.oneLine `
${cli_ansi_1.default.bgWhite(cli_ansi_1.default.fgBlack(" " + this.textPrefix + " "))}
${this.message}
`;
}
}
exports.DetailLine = DetailLine;
class SourceCodeBlock extends ConsoleLine {
constructor(message, highlight) {
super(message);
this.textPrefix = " ";
this.highlight = null;
this.fg = [255, 255, 255];
this.type = "detail";
this.highlight = highlight || null;
}
toConsoleString() {
const lines = this._codeHighlight(this.message).split("\n");
let out = `\n`;
lines.forEach((line) => {
out += `${this.textPrefix}${line}\n`;
});
return out;
}
_codeHighlight(source) {
if (this.highlight !== null) {
const regex = new RegExp(`(${this.highlight})`, "ig");
source = source.replace(regex, `${cli_ansi_1.default.startInverse}$1${cli_ansi_1.default.endInverse}`);
}
source = source
.replace(/ ([a-z-]+)=/gi, ` ${cli_ansi_1.default.esc(cli_ansi_1.FG_MAGENTA)}$1${cli_ansi_1.default.startFgRgb(this.fg)}=`)
.replace(/="([^"]+)"/gi, `="${cli_ansi_1.default.esc(cli_ansi_1.FG_GREEN)}$1${cli_ansi_1.default.startFgRgb(this.fg)}"`)
.replace(/='([^']+)"/gi, `='${cli_ansi_1.default.esc(cli_ansi_1.FG_GREEN)}$1${cli_ansi_1.default.startFgRgb(this.fg)}'`)
.replace(/<([a-z-]+) /gi, `<${cli_ansi_1.default.esc(cli_ansi_1.FG_YELLOW)}$1${cli_ansi_1.default.startFgRgb(this.fg)} `)
.replace(/<(\/[a-z-]+)>/gi, `<${cli_ansi_1.default.esc(cli_ansi_1.FG_YELLOW)}$1${cli_ansi_1.default.startFgRgb(this.fg)}>`);
return source;
}
}
exports.SourceCodeBlock = SourceCodeBlock;
//# sourceMappingURL=consoleline.js.map