UNPKG

vitest-bamboo-reporter

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