UNPKG

vitest-bamboo-reporter

Version:
65 lines (64 loc) 3.05 kB
var y = Object.defineProperty; var w = (t, s, i) => s in t ? y(t, s, { enumerable: !0, configurable: !0, writable: !0, value: i }) : t[s] = i; var p = (t, s, i) => (w(t, typeof s != "symbol" ? s + "" : s, i), i); import { existsSync as b, rmSync as N, mkdirSync as k, writeFileSync as A } from "fs"; import { resolve as I, dirname as R } from "path"; const E = (t) => { const s = []; return t.type === "benchmark" ? s : t.type === "test" ? [t] : [...t.tasks.map(E).flat()]; }, _ = (t) => t.tasks.map(E).flat(), S = (t) => t.suite && t.suite.name ? `${S(t.suite)} - ${t.name}` : t.name; class B { constructor() { p(this, "ctx"); p(this, "outputFile"); } onInit(s) { if (this.ctx = s, !this.ctx.config.outputFile) throw new Error( "BambooReporter requires config.outputFile to be defined in vite config" ); if (this.outputFile = typeof s.config.outputFile == "string" ? s.config.outputFile : s.config.outputFile["vitest-bamboo-reporter"], !this.outputFile || typeof this.outputFile != "string") throw new Error( "BambooReporter requires config.outputFile to be defined in vite config" ); b(this.outputFile) && N(this.outputFile); } onFinished(s = []) { const i = I(this.ctx.config.root, this.outputFile), f = R(i); b(f) || k(f, { recursive: !0 }); const e = { stats: { tests: 0, failures: 0, passes: 0, skipped: 0, duration: 0 }, failures: [], passes: [], skipped: [] }, a = s.map(_).flat(); a.forEach((r) => { var c, d, m, g, h, F; const n = r.name, u = S(r), o = { title: n, fullTitle: u, duration: Math.round(((c = r.result) == null ? void 0 : c.duration) || 0), errorCount: 0 }; ((d = r.result) == null ? void 0 : d.state) === "fail" ? (o.errorCount = ((m = r.result.errors) == null ? void 0 : m.length) || 1, o.error = ((g = r.result.errors) == null ? void 0 : g.map((T) => T.message).join("; ")) || "", e.failures.push(o)) : r.mode === "skip" || r.mode === "todo" || ((h = r.result) == null ? void 0 : h.state) === "skip" || ((F = r.result) == null ? void 0 : F.state) === "todo" ? e.skipped.push(o) : e.passes.push(o); }), e.stats.tests = e.failures.length + e.passes.length + e.skipped.length, e.stats.failures = e.failures.length, e.stats.passes = e.passes.length, e.stats.skipped = e.skipped.length, e.stats.duration = Math.round(a.reduce((r, n) => { var u; return r + (((u = n.result) == null ? void 0 : u.duration) || 0); }, 0)); const l = a.reduce((r, n) => { var o; const u = ((o = n.result) == null ? void 0 : o.startTime) || Number.MAX_SAFE_INTEGER; return u < r ? u : r; }, Number.MAX_SAFE_INTEGER); l !== Number.MAX_SAFE_INTEGER && (e.stats.start = new Date(l).toISOString(), e.stats.end = new Date(l + e.stats.duration).toISOString()), A(i, JSON.stringify(e, null, 2), "utf-8"), this.ctx.logger.log(`Bamboo report written to ${i}`); } } export { B as default };