playwright-confluence-reporter
Version:
A Playwright reporter for Confluence
18 lines (17 loc) • 3.47 kB
JavaScript
(function(o,s){typeof exports=="object"&&typeof module<"u"?module.exports=s():typeof define=="function"&&define.amd?define(s):(o=typeof globalThis<"u"?globalThis:o||self,o["playwright-confluence-reporter"]=s())})(this,function(){"use strict";var g=Object.defineProperty;var y=(o,s,t)=>s in o?g(o,s,{enumerable:!0,configurable:!0,writable:!0,value:t}):o[s]=t;var p=(o,s,t)=>y(o,typeof s!="symbol"?s+"":s,t);class o{constructor(t){p(this,"results");p(this,"confluenceConfig");p(this,"testSummary");this.confluenceConfig={generatePage:!0,...t},this.results={}}onTestEnd(t,e){var h;const n=t.parent.title,r=t.title,i=t._projectId||"unknown",a=e.status,u=e.duration,c=((h=e.error)==null?void 0:h.message)||"",l=e.steps.filter(f=>f.category==="test.step").map(f=>f.title),d=l.length>0?`<h6>${l.join("</h6><h6>")}</h6>`:"";this.results[n]||(this.results[n]={}),this.results[n][r]||(this.results[n][r]={}),this.results[n][r][i]={status:a,duration:u,description:d,error:c}}async onEnd(t){const{confluenceUrl:e,username:n,apiKey:r,spaceId:i,generatePage:a,pageTitle:u}=this.confluenceConfig;if(!e||!n||!r||!i){console.error("❌ Missing Confluence configuration",this.confluenceConfig);return}if(this.testSummary=t,!a){console.info("Skipping Confluence page generation");return}const c=u||new Date().toLocaleString("en-US",{dateStyle:"short",timeStyle:"short"}),l=this.generateConfluenceTable();if(!l){console.error("❌ Failed to generate test table");return}await this.createConfluencePage(c,l)}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 r in this.results[e][n]){const{status:i,description:a,duration:u,error:c}=this.results[e][n][r];t+=`
<tr>
<td><h6>${e}</h6></td>
<td><h6>${n}</h6></td>
<td><h6>${r}</h6></td>
<td><h6>${i==="passed"?"✅":"❌"}</td>
<td><h6>${(u/1e3).toFixed(1)} sec.</td>
<td>${a}</td>
</tr>
`,c&&(t+=`
<tr>
<td colspan="6">
<h6 style="color: red;">${c}</h6>
</td>
</tr>
`)}return t+="</tbody></table>",t}async createConfluencePage(t,e){const{confluenceUrl:n,username:r,apiKey:i,spaceId:a,parentPageId:u}=this.confluenceConfig;if(!n||!r||!i||!a){console.error("❌ Missing Confluence configuration",this.confluenceConfig);return}const c=Buffer.from(`${r}:${i}`).toString("base64"),l={spaceId:a,parentId:u,status:"current",title:t,body:{representation:"storage",value:e}};try{const h=await(await fetch(`${n}/api/v2/pages`,{method:"POST",headers:{Authorization:`Basic ${c}`,Accept:"application/json","Content-Type":"application/json"},body:JSON.stringify(l)})).json(),f=`${h._links.base}${h._links.webui}`;console.log("✅ Confluence page created",f)}catch(d){console.error("❌ Failed to create Confluence page:",d)}}}return o});
//# sourceMappingURL=index.umd.js.map