'use strict';var crypto=require('crypto'),fs=require('fs'),path=require('path');function w(o){if(typeof o!="object"||o===null)return  false;let i=o;return typeof i.schemaVersion=="string"&&typeof i.testRunId=="string"&&typeof i.startedAt=="string"&&typeof i.completedAt=="string"&&typeof i.totalDuration=="number"&&typeof i.summary=="object"&&Array.isArray(i.timeline)}async function k(o,i){let r=[];for(let t of o){let n;try{n=fs.readFileSync(t,"utf-8");}catch(e){throw new Error(`Failed to read file: ${t}: ${e instanceof Error?e.message:String(e)}`)}let s;try{s=JSON.parse(n);}catch(e){throw new Error(`Invalid JSON in file: ${t}: ${e instanceof Error?e.message:String(e)}`)}if(!w(s))throw new Error(`Invalid report schema in file: ${t}`);r.push(s);}if(r.length===0)throw new Error("No valid reports to merge");let u=r.map(t=>t.testRunId),a=[];for(let t of r)a.push(...t.timeline);a.sort((t,n)=>{let s="visitedAt"in t?t.visitedAt:t.timestamp,e="visitedAt"in n?n.visitedAt:n.timestamp;return new Date(s).getTime()-new Date(e).getTime()});let d=h(r.map(t=>t.summary),a.length),l=r.reduce((t,n)=>n.startedAt<t?n.startedAt:t,r[0].startedAt),m=r.reduce((t,n)=>n.completedAt>t?n.completedAt:t,r[0].completedAt),c=new Date(m).getTime()-new Date(l).getTime(),p={schemaVersion:r[0].schemaVersion,testRunId:i.testRunId??crypto.randomUUID(),startedAt:l,completedAt:m,totalDuration:c,summary:d,ci:r.find(t=>t.ci!==null)?.ci??null,metadata:r.find(t=>t.metadata!==null)?.metadata??null,timeline:a,shardRunIds:u},f=path.dirname(i.output);return fs.mkdirSync(f,{recursive:true}),fs.writeFileSync(i.output,JSON.stringify(p,null,2),"utf-8"),p}function h(o,i){let r=0,u=0,a=0,d=0,l=0,m=0,c=0,p=0,f=0,t=0,n=0,s=0;for(let e of o)r+=e.total,u+=e.passed,a+=e.failed,d+=e.flaky,l+=e.skipped,m+=e.timedout,c+=e.totalApiCalls,p+=e.totalAssertions,f+=e.passedAssertions,t+=e.failedAssertions,n+=e.totalNavigations,s+=e.totalActionSteps;return {total:r,passed:u,failed:a,flaky:d,skipped:l,timedout:m,totalApiCalls:c,uniqueApiUrls:0,apiCallsByMethod:{},apiCallsByStatusRange:{"2xx":0,"3xx":0,"4xx":0,"5xx":0,error:0},apiResponseTime:null,totalAssertions:p,passedAssertions:f,failedAssertions:t,totalNavigations:n,uniqueNavigationUrls:0,totalTimelineSteps:i,totalActionSteps:s,actionStepsByCategory:{}}}exports.mergeReports=k;//# sourceMappingURL=merge.cjs.map
//# sourceMappingURL=merge.cjs.map