UNPKG

beater-tap-reporter

Version:
56 lines (45 loc) 1.32 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); class TapLikeReporter { constructor(p) { this.tests = []; this.p = p; } finished(_) {} started(tests) { this.tests = tests; this.p("TAP version 13"); this.p(`1..${tests.length}`); } testStarted(_) {} testFinished({ error, test }) { var _a; const name = test.name; const ok = typeof error === "undefined" ? "ok" : "not ok"; const no = this.tests.indexOf(test) + 1; this.p(`${ok} ${no} - ${name}`); if (typeof error !== "undefined") { const stack = (_a = error.stack) !== null && _a !== void 0 ? _a : ""; this.p(" ---"); this.p(" name: " + error.name); this.p(" message: " + (error.message.indexOf("\n") >= 0 ? "|2\n " + error.message.split(/\n/).join("\n ") : error.message)); this.p(" stack: " + (stack.indexOf("\n") >= 0 ? "|2\n " + stack.split(/\n/).join("\n ") : stack)); this.p(" ..."); } } } const reporter = p => { const r = new TapLikeReporter(p !== null && p !== void 0 ? p : console.log.bind(console)); return { finished: r.finished.bind(r), started: r.started.bind(r), testFinished: r.testFinished.bind(r), testStarted: r.testStarted.bind(r) }; }; exports.reporter = reporter;