UNPKG

playwright-confluence-reporter

Version:
105 lines (104 loc) 4.05 kB
var g = Object.defineProperty; var p = (u, t, e) => t in u ? g(u, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : u[t] = e; var d = (u, t, e) => p(u, typeof t != "symbol" ? t + "" : t, e); class m { constructor(t) { d(this, "results"); d(this, "confluenceConfig"); d(this, "testSummary"); this.confluenceConfig = { generatePage: !0, ...t }, this.results = {}; } onTestEnd(t, e) { var l; const n = t.parent.title, s = t.title, o = t._projectId || "unknown", r = e.status, i = e.duration, a = ((l = e.error) == null ? void 0 : l.message) || "", c = e.steps.filter((h) => h.category === "test.step").map((h) => h.title), f = c.length > 0 ? `<h6>${c.join("</h6><h6>")}</h6>` : ""; this.results[n] || (this.results[n] = {}), this.results[n][s] || (this.results[n][s] = {}), this.results[n][s][o] = { status: r, duration: i, description: f, error: a }; } async onEnd(t) { const { confluenceUrl: e, username: n, apiKey: s, spaceId: o, generatePage: r, pageTitle: i } = this.confluenceConfig; if (!e || !n || !s || !o) { console.error("❌ Missing Confluence configuration", this.confluenceConfig); return; } if (this.testSummary = t, !r) { console.info("Skipping Confluence page generation"); return; } const a = i || (/* @__PURE__ */ new Date()).toLocaleString("en-US", { dateStyle: "short", timeStyle: "short" }), c = this.generateConfluenceTable(); if (!c) { console.error("❌ Failed to generate test table"); return; } await this.createConfluencePage(a, c); } generateConfluenceTable() { if (!this.testSummary) return; let t = `<p><strong>Status:</strong> ${this.testSummary.status}</p><p><strong>Duration:</strong> ${(this.testSummary.duration / 1e3).toFixed(1)} sec.</p>`; this.confluenceConfig.meta && (t += this.confluenceConfig.meta.map((e) => `<p><strong>${e.key}:</strong> ${e.value}</p>`).join("")), t += "<table><thead><tr><th>Suite</th><th>Test</th><th>Project</th><th>Status</th><th>Duration</th><th>Steps</th></tr></thead><tbody>"; for (const e in this.results) for (const n in this.results[e]) for (const s in this.results[e][n]) { const { status: o, description: r, duration: i, error: a } = this.results[e][n][s]; t += ` <tr> <td><h6>${e}</h6></td> <td><h6>${n}</h6></td> <td><h6>${s}</h6></td> <td><h6>${o === "passed" ? "✅" : "❌"}</td> <td><h6>${(i / 1e3).toFixed(1)} sec.</td> <td>${r}</td> </tr> `, a && (t += ` <tr> <td colspan="6"> <h6 style="color: red;">${a}</h6> </td> </tr> `); } return t += "</tbody></table>", t; } async createConfluencePage(t, e) { const { confluenceUrl: n, username: s, apiKey: o, spaceId: r, parentPageId: i } = this.confluenceConfig; if (!n || !s || !o || !r) { console.error("❌ Missing Confluence configuration", this.confluenceConfig); return; } const a = Buffer.from(`${s}:${o}`).toString("base64"), c = { spaceId: r, parentId: i, status: "current", title: t, body: { representation: "storage", value: e } }; try { const l = await (await fetch(`${n}/api/v2/pages`, { method: "POST", headers: { Authorization: `Basic ${a}`, Accept: "application/json", "Content-Type": "application/json" }, body: JSON.stringify(c) })).json(), h = `${l._links.base}${l._links.webui}`; console.log("✅ Confluence page created", h); } catch (f) { console.error("❌ Failed to create Confluence page:", f); } } } export { m as default }; //# sourceMappingURL=index.es.js.map