UNPKG

@currents/playwright

Version:

[Currents](https://currents.dev/playwright) is the most popular and advanced cloud-based platform for Playwright - debugging, error analysis, real-time analytics, orchestration, and more

63 lines (50 loc) 34.9 kB
#! /usr/bin/env node "use strict";var Nr=Object.create;var Z=Object.defineProperty;var _r=Object.getOwnPropertyDescriptor;var Fr=Object.getOwnPropertyNames;var jr=Object.getPrototypeOf,Lr=Object.prototype.hasOwnProperty;var a=(e,t)=>()=>(e&&(t=e(e=0)),t);var _e=(e,t)=>{for(var r in t)Z(e,r,{get:t[r],enumerable:!0})},$r=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of Fr(t))!Lr.call(e,s)&&s!==r&&Z(e,s,{get:()=>t[s],enumerable:!(n=_r(t,s))||n.enumerable});return e};var f=(e,t,r)=>(r=e!=null?Nr(jr(e)):{},$r(t||!e||!e.__esModule?Z(r,"default",{value:e,enumerable:!0}):r,e));var o=a(()=>{"use strict"});var Fe=a(()=>{"use strict";o()});var je=a(()=>{"use strict";o()});function Le(e){Hr.push(e)}var Hr,Q=a(()=>{"use strict";o();Hr=[]});var R,Br,qr,Mr,sn,j=a(()=>{"use strict";o();R={None:"none",Summary:"summary",Detailed:"detailed"},Br={introAndSummary:!1,testOutput:!1,progress:!1,tables:!1,warningsAndErrors:!1},qr={introAndSummary:!0,testOutput:"line",progress:!1,tables:!1,warningsAndErrors:!0},Mr={introAndSummary:!0,testOutput:"full",progress:!0,tables:!0,warningsAndErrors:!0},sn={[R.None]:Br,[R.Summary]:qr,[R.Detailed]:Mr}});var $e,He,Be=a(()=>{"use strict";o();$e=[],He=[]});function Wr(e){return qe?!!qe[e]:!0}function $(e,t){Le(t),Wr(e)&&console.log(t)}var y,L,qe,H,u,x,D,yn,wn,Cn,bn,Tn,On,xn,vn,Rn,l,En,Me=a(()=>{"use strict";o();y=f(require("chalk")),L=f(require("util"));j();b();Q();Be();qe=null;H=(...e)=>{$("introAndSummary",L.default.format(...e))},u=(...e)=>{let t=L.default.format(...e);He.push(t),d("WARNING: ",t),$("warningsAndErrors",y.default.bgYellow.black(" WARNING ")+" "+t)},x=(...e)=>{let t=L.default.format(...e);$e.push(t),d("ERROR: ",t),$("warningsAndErrors",y.default.bgRed.white(" ERROR ")+" "+t)},D=(e=2)=>{let t=Math.max(0,Math.floor(e));t!==0&&$("introAndSummary",Array(t).fill("").join(` `))},yn=y.default.cyan,wn=y.default.blueBright,Cn=y.default.red,bn=y.default.yellow,Tn=y.default.green,On=y.default.gray,xn=y.default.white,vn=y.default.black,Rn=y.default.magenta,l=y.default.dim,En=y.default.bold});var O=a(()=>{"use strict";o();Q();Me()});function te(e){if(!e)return;if(e==="false")return!1;let t=parseInt(e,10);if(isNaN(t)||t<1)throw new ee.CommanderError(255,"Invalid argument provided.","--pwc-cancel-after-failures must be a positive integer or 'false', provided: "+e);return t}function We(e){if(!e)return;let t=["SIGUSR1","SIGUSR2"];if(!t.includes(e.toUpperCase().trim()))throw new ee.CommanderError(255,"Invalid argument provided.","--pwc-reset-signal must be one of ("+t.join(", ")+"), provided: "+e);return e.toUpperCase().trim()}var ee,re=a(()=>{"use strict";o();ee=require("commander")});function h(e){return Gr[e]?.env}var Gr,oe=a(()=>{"use strict";o();re();Gr={currentsConfigFile:{name:"Currents Config File Path",env:"CURRENTS_CONFIG_FILE_PATH",cli:"--pwc-config"},ciBuildId:{name:"CI Build ID",env:"CURRENTS_CI_BUILD_ID",cli:"--ci-build-id"},recordKey:{name:"Record Key",env:"CURRENTS_RECORD_KEY",cli:"--key"},projectId:{name:"Project ID",env:"CURRENTS_PROJECT_ID",cli:"--project-id"},tag:{name:"Currents Tag",env:"CURRENTS_TAG",cli:"--tag"},environment:{name:"Currents Environment",env:"CURRENTS_ENVIRONMENT",cli:"--pwc-environment"},cancelAfterFailures:{name:"Currents Cancel After Failures",env:"CURRENTS_CANCEL_AFTER_FAILURES",cli:"--pwc-cancel-after-failures"},disableTestTags:{name:"Disable Test Tags",env:"CURRENTS_DISABLE_TEST_TAGS",cli:"--pwc-disable-test-tags"},disableTitleTags:{name:"Disable Title Tags",env:"CURRENTS_DISABLE_TITLE_TAGS",cli:"--pwc-disable-title-tags"},testSuiteFile:{name:"Test Suite File",env:"CURRENTS_TEST_SUITE_FILE",cli:"--pwc-test-suite-file"},machineId:{name:"Machine ID",env:"CURRENTS_MACHINE_ID",cli:"--pwc-machine-id"},orchestrationId:{name:"Orchestration ID",env:"CURRENTS_ORCHESTRATION_ID",cli:"--pwc-orchestration-id"},outputFile:{name:"Output File",env:"CURRENTS_OUTPUT_FILE",cli:"--pwc-output-file"},consoleOutput:{name:"Console Output",env:"CURRENTS_CONSOLE_OUTPUT",cli:"--pwc-console-output"},batchSize:{name:"Batch Size",env:"CURRENTS_BATCH_SIZE",cli:"--pwc-batch-size"},discoveryFile:{name:"Discovery File",env:"CURRENTS_DISCOVERY_FILE",cli:"--pwc-discovery-file"},ciUrl:{name:"CI URL",env:"CURRENTS_CI_URL"}}});function ze(e){return{ciBuildId:e.ciBuildId,projectId:e.projectId,recordKey:e.key,tag:e.tag,environment:e.pwcEnvironment,removeTitleTags:e.pwcRemoveTitleTags,cancelAfterFailures:e.pwcCancelAfterFailures,disableTestTags:e.pwcDisableTestTags||e.pwcDisableTitleTags,testSuiteFile:e.pwcTestSuiteFile,machineId:e.pwcMachineId,outputFile:e.pwcOutputFile,consoleOutput:e.pwcConsoleOutput,pwcConfigPath:e.pwcConfig,orchestration:{resetSignal:e.pwcResetSignal,skipReporterInjection:e.pwcSkipReporterInjection,batchSize:e.pwcBatchSize,discoveryFile:e.pwcDiscoveryFile},coverage:{projects:e.pwcCoverage,dir:e.pwcCoverageDir}}}var Kr,Ln,ne=a(()=>{"use strict";o();Kr=f(require("fs"));b();Ln=d.extend("cli-options-serializer")});function Ge(){return Vr}var rs,os,Vr,se=a(()=>{"use strict";o();b();Fe();je();O();j();oe();ne();j();rs=d.extend("config"),os={removeTitleTags:!1,disableTestTags:!1,consoleOutput:R.Detailed,orchestration:{skipReporterInjection:!1},coverage:{projects:!1}},Vr=null});var Jr,Ke=a(()=>{"use strict";o();Jr=require("lodash");O()});var B=a(()=>{"use strict";o();se();oe();ne();Ke()});var Je,Ve=a(()=>{Je={name:"@currents/playwright",version:"2.3.3",main:"./dist/index.js",author:{name:"Currents Software Inc",email:"hello@currents.dev",url:"https://currents.dev"},license:"MIT",homepage:"https://currents.dev",repository:{type:"git",url:"https://github.com/currents-dev/currents-playwright-changelog.git"},scripts:{test:"vitest",rm:"rimraf dist",lint:'TIMING=1 eslint "**/*.ts*"',build:"tsup-node --minify --dts",dev:"tsup-node --watch --dts",release:"release-it --verbose","publish:npm":"npm run rm && npm run build && ./publish.js","release-ci":"npm run rm && npm run build && ./publish.js -t latest"},bin:{pwc:"./dist/bin/pwc.js","pwc-p":"./dist/bin/pwc-p.js"},devDependencies:{"@playwright/test":"^1.56.1","@release-it/conventional-changelog":"^11.0.1","@types/async-retry":"^1.4.5","@types/babel__code-frame":"^7.0.3","@types/debug":"^4.1.13","@types/getos":"^3.0.4","@types/istanbul-lib-coverage":"^2.0.6","@types/json-stringify-safe":"^5.0.3","@types/lodash":"^4.17.24","@types/pluralize":"^0.0.33","@types/proxy-from-env":"^1.0.4","@types/regexp.escape":"^2.0.0","@types/stack-utils":"^2.0.3","@types/tmp":"^0.2.6","@types/ws":"^8.18.1",eslint:"^10.5.0","eslint-config-custom":"*",msw:"^2.14.2","release-it":"^20.2.0",rimraf:"^6.1.3",tsup:"^8.5.0",typescript:"^6.0.3",vitest:"^4.1.9"},dependencies:{"@babel/code-frame":"^7.29.7","@commander-js/extra-typings":"^13.1.0","@currents/commit-info":"1.0.1-beta.0","async-retry":"^1.3.3",chalk:"^4.1.2",commander:"^13.1.0","date-fns":"^4.3.0",debug:"^4.4.3",dotenv:"^17.4.2",execa:"^9.6.0",getos:"^3.2.1","istanbul-lib-coverage":"^3.2.2",jiti:"2.7.0","json-stringify-safe":"^5.0.1","lil-http-terminator":"^1.2.3",lodash:"^4.18.1",nanoid:"^3.3.8","object-sizeof":"^2.6.5","p-debounce":"^2.1.0","p-map":"^4.0.0","p-queue":"6.6.2",pluralize:"^8.0.0","pretty-ms":"^7.0.1","proxy-from-env":"^1.1.0","regexp.escape":"^2.0.1","safe-regex2":"^5.1.1","source-map-support":"^0.5.21","stack-utils":"^2.0.6",tmp:"^0.2.7","tmp-promise":"^3.0.3","ts-pattern":"^5.8.0",undici:"^6.27.0",ws:"^8.21.0"},files:["dist","!**/*.map","!**/*/*.map","**/*.LEGAL.txt","!src/*.md","!src/**/*.md","LICENSE.md","README.md","CHANGELOG.md"],keywords:["playwright","playwright dashboard","cloud dashboard","reporter","currents","tests reporter","sorry cypress","ci"],exports:{".":{import:"./dist/index.js",require:"./dist/index.js"},"./discovery":{import:"./dist/reporters/discovery.js",require:"./dist/reporters/discovery.js"},"./orchestration":{import:"./dist/orchestration/index.js",require:"./dist/orchestration/index.js"},"./package.json":"./package.json"},engines:{node:">=18.17"},publishConfig:{access:"public",registry:"https://registry.npmjs.org"},"release-it":{npm:{publish:!1},github:{release:!0},plugins:{"@release-it/conventional-changelog":{preset:"angular",header:"# Changelog",ignoreVersion:!0,infile:"../../CHANGELOG.md"}},git:{commitMessage:"chore: release v${version}",tagName:"v${version}"},hooks:{"before:github:release":"npm run --prefix ../../ update-public-changelog"}}}});var q,ie=a(()=>{"use strict";o();Ve();q=Je.version});var ae,Ye,Xe=a(()=>{"use strict";o();ae=()=>process.env.CURRENTS_API_URL??"https://cy.currents.dev",Ye=()=>3e4});var Xr,xs,Ze=a(()=>{"use strict";o();Xr=f(require("ws"));b();xs=d.extend("ws")});var Qe,Us,et,tt=a(()=>{"use strict";o();Qe=f(require("events"));se();b();Ze();ce();Us=d.extend("pubsub"),et=new Qe.default});var pe,ot,rt,nt,st=a(()=>{"use strict";o();O();tt();pe={cancellationReason:null},ot=e=>{pe.cancellationReason||(pe.cancellationReason=e)},rt=()=>pe.cancellationReason,nt=({showWarning:e=!0}={})=>{let t=rt();t&&(e&&u("%s",t),et.emit("runCancelled",t))}});var ce=a(()=>{"use strict";o();st()});var it,k,ue=a(()=>{"use strict";o();it=require("nanoid"),k=(0,it.customAlphabet)("abcdefghijklmnopqrstuvwxyz",10)});var at,Zr,ct,pt=a(()=>{"use strict";o();at=require("ts-pattern"),Zr={outcome:null,scannerConfig:null,currentsConfig:null,internalConfig:null},ct=()=>Zr});function M(e){if(e===null||typeof e!="object")return!1;let t=e;return typeof t.message!="string"?!1:t.response!==void 0&&t.response!==null?!(typeof t.response.status!="number"||t.response.headers!==void 0&&typeof t.response.headers!="object"):!!(typeof t.code=="string"&&U.includes(t.code))}var U,A=a(()=>{"use strict";o();U=["ECONNABORTED","ECONNREFUSED","ECONNRESET","ETIMEDOUT","EPIPE","ENETUNREACH","EHOSTUNREACH","ENETRESET","ENOTFOUND","EAI_AGAIN"]});function ft(e){(0,m.match)(e).when(M,Qr).otherwise(()=>{u("Unexpected error while sending network request: %s",e)})}function Qr(e){let t=e.response?.config??e.config;return(0,m.match)(e).with({code:"ECONNABORTED"},()=>{u("Network connection aborted")}).with({code:"ECONNREFUSED"},()=>{u("Network connection aborted")}).with({code:"ECONNRESET"},()=>{u("Network connection reset")}).with({code:"EPIPE"},()=>{u("Network connection reset")}).with({code:"ENETUNREACH"},()=>{u("Network connection aborted")}).with({code:"EHOSTUNREACH"},()=>{u("Network connection aborted")}).with({code:"ETIMEDOUT"},()=>{u("Network connection timeout")}).with({response:m.P.not(m.P.nullish)},r=>{eo(r,{status:r.response.status,data:r.response.data})}).otherwise(()=>{u(`[currents] Unexpected network error: %s %O`,e.message,{method:t?.method,url:t?.url,status:e.response?.status,payload:t?.data,requestId:N(e)})})}function eo(e,{status:t,data:r}){let n=e.response?.config??e.config,s=n?.method,p=n?.url;(0,m.match)(t).with(401,()=>{u(`[currents] ${s} ${p} - 401 Unauthorized Request from cloud service`)}).with(400,()=>{u(`[currents] ${s} ${p} - 400 Bad Request from cloud service: %o`,r)}).with(429,()=>{u(`[currents] ${s} ${p} - 429 Too Many Requests from cloud service`)}).with(422,()=>{to(e,r)}).otherwise(()=>{u(`[currents] Unexpected network response: %s %O`,e.message,{method:s,url:p,status:e.response?.status,requestId:N(e)})})}function to(e,t){let r=e.response?.config??e.config;(0,m.match)(t).with({code:le.MISSING_SUITE,message:m.P.string,errors:m.P.array(m.P.string)},async n=>{let{message:s,errors:p}=n;D(1),x(...ut(s,p)),W({id:k(),text:(0,lt.default)(ct(),null,2)}).then(g=>{x(`Please share this URL with Currents support for further investigation: ${g}`)}).catch(g=>{u("Failed to upload debug artifact: %s",g)}),D(1)}).with({code:le.RUN_CANCELLED,message:m.P.string},n=>{ot(n.message),nt()}).with({code:le.RUN_EXPIRED,message:m.P.string},n=>{u(n.message)}).with({message:m.P.string,errors:m.P.array(m.P.string)},n=>{let{message:s,errors:p}=n;D(1),u(...ut(s,p)),D(1)}).otherwise(()=>{u(`[currents] Unexpected network response: %s %O`,e.message,{method:r?.method,url:r?.url,status:e.response?.status,requestId:N(e)})})}function ut(e,t){return dt.default.isString(e)?t?.length===0?[e]:[e,` ${(t??[]).map(r=>` - ${r}`).join(` `)} `]:["Unexpected network error"]}function N(e){let t=e?.response?.headers;if(!(!t||typeof t!="object")){for(let[r,n]of Object.entries(t))if(r.toLowerCase()==="apigw-requestid")return Array.isArray(n)?n[0]:n}}var lt,dt,m,le,de=a(()=>{"use strict";o();lt=f(require("json-stringify-safe")),dt=f(require("lodash")),m=require("ts-pattern");ce();ue();O();fe();pt();A();le={RUN_CANCELLED:"RUN_CANCELLED",RUN_EXPIRED:"RUN_EXPIRED",MISSING_SUITE:"MISSING_SUITE"}});function yt(e,t,r){let n=r.method?.toUpperCase(),s=r.url,p=N(t),g=(0,gt.default)(ge(e)),w=`Network request '${n} ${s}' failed: '${t.message}'.${p?` Request ID: ${p}.`:""} Next attempt is in ${g} (${e}/${r["transport-retry"]?.retries??me()}).`;mt(w),u(w)}var gt,mt,ge,ht,me,wt=a(()=>{"use strict";o();gt=f(require("pretty-ms"));b();O();de();A();mt=d.extend("http"),ge=e=>{let t=[3e3,15e3,3e4];return t[Math.min(Math.max(e-1,0),t.length-1)]},ht=e=>{if(mt("isRetriableError: %o",{message:e.message,code:"code"in e?e.code:void 0,status:"response"in e?e.response?.status:void 0,headers:"response"in e?e.response?.headers:void 0,data:"response"in e?e.response?.data:void 0}),"code"in e&&e.code&&U.includes(e.code))return!0;if(!M(e)||!e.response)return!1;let t=e.response.headers;return t==null||typeof t!="object"?!1:[429,500,502,503,504].includes(e.response.status??0)},me=()=>3});function oo(e){let t=Tt.default.getProxyForUrl(e);if(t)return ro("Using HTTP proxy %s for %s",t,e),Ct===t&&z||(Ct=t,z=new bt.ProxyAgent(t)),z}function Ot(e,t){if(/^https?:\/\//i.test(t))return t;let r=e??"",n=r.endsWith("/")?r:`${r}/`,s=t.replace(/^\/+/,"");return new URL(s,n).href}function no(e){let t={};return e.forEach((r,n)=>{let s=t[n];s===void 0?t[n]=r:Array.isArray(s)?s.push(r):t[n]=[String(s),r]}),t}function so(e){for(let[t,r]of Object.entries(e))if(t.toLowerCase()==="content-type"){let n=Array.isArray(r)?r[0]:r;return typeof n!="string"?"":n.split(";")[0]?.trim()?.toLowerCase()??""}return""}function io(e,t){let r=t.toLowerCase();if(r.includes("application/json")||r.endsWith("+json"))return!0;let n=e.trim();return n.length?/^(?:\{|\[|"|-?\d|true$|false$|null$)/.test(n):!1}function ao(e,t){if(!e.length)return null;if(io(e,t))try{return JSON.parse(e)}catch{return e}return e}function co(e){let t=e;for(let r=0;r<8&&t&&typeof t=="object";r++){let n=t;if(n.name==="AbortError"||n.name==="TimeoutError"||typeof n.message=="string"&&/aborted|timeout/i.test(n.message))return!0;t=n.cause}return!1}function xt(e){if(!e||typeof e!="object")return;if(co(e))return"ETIMEDOUT";let t=e,r=typeof t.message=="string"?t.message:"";if(t.name==="AbortError"||t.code==="UND_ERR_ABORTED"||t.code==="ABORT_ERR"||/aborted|timeout/i.test(r)||t.code==="UND_ERR_CONNECT_TIMEOUT"||t.code==="UND_ERR_HEADERS_TIMEOUT"||t.code==="UND_ERR_BODY_TIMEOUT")return"ETIMEDOUT";if(t.code==="UND_ERR_SOCKET")return"ECONNRESET";if(typeof t.code=="string"&&U.includes(t.code))return t.code;if(t.cause)return xt(t.cause);if(/connection reset|other side closed|terminated|socket hang up/i.test(r))return"ECONNRESET"}function po(e){return e instanceof he.Readable}function uo(e){return po(e)?{body:he.Readable.toWeb(e),duplex:"half"}:{body:e}}async function G(e,t,r){let n=oo(e),s,p;try{let C={method:t.method,headers:t.headers,signal:t.signal};if(t.body!==void 0){let S=uo(t.body);C.body=S.body,S.duplex&&(C.duplex=S.duplex)}n!==void 0&&(C.dispatcher=n),s=await fetch(e,C),p=await s.text()}catch(C){let S=xt(C);throw{message:C instanceof Error?C.message:String(C),code:S,config:r}}let g=no(s.headers),w=so(g),I=ao(p,w),T=s.status,F=s.statusText;if(!s.ok)throw{message:`Request failed with status code ${T}`,config:r,response:{status:T,statusText:F,headers:g,data:I,config:r}};return{data:I,status:T,statusText:F,headers:g,config:r}}var he,bt,Tt,ro,Ct,z,ye=a(()=>{"use strict";o();he=require("stream"),bt=require("undici");b();A();Tt=f(require("proxy-from-env")),ro=d.extend("http:transport"),Ct=null,z=null});function ho(e){if(e){for(let[t,r]of Object.entries(e))if(t.toLowerCase()==="x-currents-idempotency-key"&&r!==void 0)return Array.isArray(r)?r[0]:String(r)}}function yo(e,t){if(!e)return;let r=t.toLowerCase();for(let[n,s]of Object.entries(e))if(n.toLowerCase()===r&&s!==void 0)return Array.isArray(s)?s[0]:String(s)}function wo(e){let t={};if(!e)return t;for(let[r,n]of Object.entries(e))n!==void 0&&(t[r.toLowerCase()]=Array.isArray(n)?n.join(", "):String(n));return t}function Co(...e){if(typeof AbortSignal.any=="function")return AbortSignal.any(e);let t=new AbortController;for(let r of e){if(r.aborted)return t.abort(r.reason),t.signal;r.addEventListener("abort",()=>t.abort(r.reason),{once:!0})}return t.signal}async function bo(e){let t={...mo,...e.currentsOptions};return!t.enableCompression||e.data===void 0||Buffer.isBuffer(e.data)||typeof e.data=="string"||(0,St.default)(e.data)<=t.compressThresholdBytes?e:{...e,data:await go((0,we.default)(e.data)),headers:{...e.headers,"Content-Encoding":"gzip"}}}function To(e){let{data:t}=e;if(t!==void 0)return Buffer.isBuffer(t)||typeof t=="string"?t:(0,we.default)(t)}async function Oo(e){let t=e.baseURL??ae(),r=e["transport-retry"]?.retries??me(),n=ho(e.headers)??(0,Et.nanoid)(),s=await bo(e),p=To(s),g=(s.method??"get").toUpperCase(),w=e.signal;if(w?.aborted)throw{message:w.reason?.message??"Request aborted",code:"ECONNABORTED",config:e};let I;for(let T=0;T<=r;T++){let F=s.timeout??Ye(),C=AbortSignal.timeout(F),S=w?Co(w,C):C,P=Ge(),v={...wo(s.headers),...fo,"accept-encoding":"gzip, deflate, br","x-currents-idempotency-key":n,"x-pwc-request-attempt":String(T),"x-currents-key":P?.recordKey??""};P?.orchestrationId&&(v["x-currents-orchestration-id"]=P.orchestrationId),P?.machineId&&(v["x-currents-machine-id"]=P.machineId),yo(e.headers,"content-type")||(v["content-type"]=v["content-type"]??"application/json");let kr={...s,method:g,url:e.url,baseURL:t,headers:v},Ur=Ot(t,e.url??""),Ae={method:g,url:e.url,headers:v,data:Buffer.isBuffer(p)?"buffer":p};T?vt("network request retry: %o",Rt({...Ae,isRetry:!0})):vt("network request: %o",Rt(Ae));try{return await G(Ur,{method:g,headers:v,body:p,signal:S},kr)}catch(X){I=X;let Ne=X;if(!ht(Ne)||T>=r)throw X;yt(T+1,Ne,{...e,method:g}),await new Promise(Ar=>setTimeout(Ar,ge(T+1)))}}throw I}function xo(){return{request:e=>Oo(e)}}function Dt(){return K||(K=xo(),K)}function Rt(e){return{method:e.method,baseUrl:ae(),url:e.url,data:e.isRetry?"<retry>":vo(e.data),headers:{...e.headers,"x-currents-key":"***"}}}function vo(e){let t=e;return t?.results?.raw?{...t,results:{...t.results,raw:"***"}}:e}var we,Et,St,Pt,It,vt,lo,fo,go,mo,K,kt=a(()=>{"use strict";o();we=f(require("json-stringify-safe")),Et=require("nanoid"),St=f(require("object-sizeof")),Pt=require("util"),It=f(require("zlib"));B();b();ie();Xe();wt();ye();vt=d.extend("http"),lo=1024*1024*1,fo={"x-pw-version":"0.0.0","x-pwc-version":q},go=(0,Pt.promisify)(It.default.gzip),mo={enableCompression:!1,compressThresholdBytes:lo},K=null});async function Nt(e,t=Dt){try{let r=await t().request(e);return Ut("network response: %o",{...At.default.omit(r,"request","config"),url:r.config.url,method:r.config.method}),r}catch(r){let n=r;throw Ut("network error: %o",{code:n.code,message:n.message,url:n.config?.url,method:n.config?.method,status:n.response?.status,headers:n.response?.headers,data:n.response?.data}),ft(n),n}}var At,Ut,_t=a(()=>{"use strict";o();At=f(require("lodash"));b();kt();de();Ut=d.extend("http")});var Ft=a(()=>{"use strict";o();_t();A()});var jt={};_e(jt,{getDebugUrl:()=>Ro});var Ro,Lt=a(()=>{"use strict";o();Ft();Ro=({runId:e,type:t})=>Nt({method:"POST",url:"runs/debug-logs",data:{type:t,runId:e}}).then(r=>r.data)});function So(e,t){return Wt({path:e,name:null,uploadUrl:t,contentType:"text/plain"},"text/plain")}async function Wt(e,t,r){let n=await Ht.default.readFile(e.path);return Ce("Uploading file %s",e.uploadUrl,{buffer:Buffer.byteLength(n)}),zt(n,e.uploadUrl,t,r)}async function Po(e,t,r){return Ce("Uploading buffer %s",e.name,{buffer:Buffer.byteLength(e.buffer)}),zt(e.buffer,e.uploadUrl,t,r)}function Io(e){let t;try{t=new URL(e)}catch{throw new Error(`Invalid upload URL: ${e}`)}if(!["http:","https:"].includes(t.protocol))throw new Error(`Unsupported upload URL protocol: ${t.protocol||"unknown"}`);return e}async function Do(e,t,r,n){let s=Io(t),p=e,g={"Content-Disposition":"inline","Content-Type":r};n?.compress&&(p=await Eo(e),g["Content-Encoding"]="gzip"),await G(s,{method:"PUT",headers:g,body:p},{method:"PUT",url:s,headers:g})}async function zt(e,t,r,n){await(0,$t.default)(async()=>{await Do(e,t,r,n)},{retries:5,onRetry:(s,p)=>{if(Ce(`Upload failed %d out of 5 attempts: %s %o`,p,s.message,s.response?.data),p===5){x(`Cannot upload after ${p} times: ${s.message}`);return}u(`Upload failed ${p} out of 5 attempts: ${s.message}`)}})}var $t,Ht,Bt,qt,Ce,Eo,Mt,Gt=a(()=>{"use strict";o();$t=f(require("async-retry")),Ht=f(require("fs/promises")),Bt=require("util"),qt=require("zlib");b();ye();O();Ce=d.extend("upload"),Eo=(0,Bt.promisify)(qt.gzip),Mt=(s=>(s.PNG="image/png",s.WEBM="video/webm",s.TEXT="text/plain",s.ZIP="application/zip",s))(Mt||{})});var Kt={};_e(Kt,{ContentType:()=>Mt,sendBuffer:()=>Po,sendPath:()=>Wt,uploadText:()=>So});var Vt=a(()=>{"use strict";o();Gt()});async function W(e){let{getDebugUrl:t}=await Promise.resolve().then(()=>(Lt(),jt));try{let{readUrl:r,uploadUrl:n}=await t({runId:e.id,type:"pw-debug"}),{uploadText:s,sendBuffer:p}=await Promise.resolve().then(()=>(Vt(),Kt));return"text"in e&&await p({name:`${e.id}-discovery-debug.log`,buffer:Buffer.from(e.text,"utf-8"),contentType:"text/plain",uploadUrl:n},"text/plain"),"path"in e&&await s(e.path,n),r}catch{return null}}var be,Te=a(()=>{"use strict";o();be=f(require("debug"))});function ko(e){return e==="false"?!1:e==="remote"?"remote":e==="full"?"full":!!e}var Jt,_,Oe=a(()=>{"use strict";o();Jt=require("@commander-js/extra-typings"),_=new Jt.Option("--pwc-debug [boolean | 'remote' | 'full']","enable debug logs. Specify 'remote' to upload logs to Currents. Specify 'full' to dump the debug logs to stdout and upload to Currents.").argParser(ko).env("CURRENTS_DEBUG")});var Yt,Xt,Zt=a(()=>{"use strict";o();Yt=require("@commander-js/extra-typings");Oe();Xt=()=>new Yt.Command().allowUnknownOption().allowExcessArguments(!0).addOption(_).helpOption(!1)});var E,Qt,ve,er,tr,xe,V,Re=a(()=>{"use strict";o();E=f(require("debug")),Qt=f(require("fs")),ve=f(require("path")),er=f(require("util")),tr=require("fs/promises");ue();O();Zt();Te();E.default.useColors=function(){return!1};xe=E.default.log,V=class e{constructor(t="core"){this.source=t;if(this.mode=Xt().parse().opts().pwcDebug??!1,this.debug=(0,E.default)(`currents:remote-debug:${this.source}`),!this.mode)return this;if(!this.shouldEnableDebug())return this;let r=process.env.DEBUG?`${process.env.DEBUG},currents*`:"currents*";if(E.default.enable(r),!this.shouldUploadRemoteDebug())return this;let n=k(),s=ve.default.resolve(".currents-debug"),p=ve.default.resolve(s,`${n}.log`);(0,tr.mkdir)(s,{recursive:!0}),H(l(`\u{1F47E} Initiated remote ${this.source} debug log collection:`),l(p));let g=Qt.default.createWriteStream(p,{flags:"a"});return E.default.log=(...w)=>{this.mode&&(g.write(`${er.default.formatWithOptions({colors:!1},...w)} `),this.shouldMuteLocalStdout()||xe(...w))},this.pipelines[n]={id:n,writeStream:g,type:this.source,tempFilePath:p},this}source;static instance;static factory(t="core"){return this.instance||(this.instance=new e(t)),this.instance}pipelines={};mode;debug;getDebugMode(){return this.mode}async finalize({runId:t}={runId:void 0}){try{let r=Object.keys(this.pipelines);r.length===0&&(this.debug("No debug pipelines found"),E.default.log=xe);for(let n of r)await this.uploadDebug(n,t??k())}catch{}finally{E.default.log=xe}}async uploadDebug(t,r){let n=this.pipelines[t];if(!n){this.debug("No debug pipeline found for id %s",t);return}H(l(`\u{1F47E} ${n.type} debug log written:`),l(n?.tempFilePath));try{let s=await W({id:r,path:n.tempFilePath});n?.writeStream.end(),H(l(`\u{1F47E} ${n.type} debug log uploaded:`),l(s))}catch(s){u(`Failed to upload ${n.type}} debug log ${l(n.tempFilePath)}: ${s.message}`)}}shouldEnableDebug(){return this.mode==="full"||this.mode==="remote"||this.mode===!0}shouldUploadRemoteDebug(){return this.mode==="full"||this.mode==="remote"}shouldMuteLocalStdout(){return this.mode==="remote"}}});var fe=a(()=>{"use strict";o();Te();Re()});var d,b=a(()=>{"use strict";o();fe();d=(0,be.default)("currents")});o();var Na=require("source-map-support/register"),Dr=require("commander");b();o();var Ee;async function rr(){if(Ee)return Ee;let{execa:e}=await import("execa");return Ee=e,e}O();Re();o();var Pr=f(require("fs"));B();b();o();var Se=f(require("fs")),or=require("tmp-promise"),nr=async()=>{let{path:e}=await(0,or.file)();return e};o();var Rr=require("@commander-js/extra-typings"),Ie=f(require("chalk")),Ko=require("commander");ie();O();o();var c=require("@commander-js/extra-typings"),sr=require("commander");B();re();Oe();var ir=new c.Option("--pwc-config <path>","path to currents config file (currents.config.[ts|js])").env(h("currentsConfigFile")),ar=new c.Option("--ci-build-id <id>","the unique run identifier").env(h("ciBuildId")),cr=new c.Option("-k, --key <record-key>","your secret Record Key obtained from Currents").env(h("recordKey")),pr=new c.Option("-p, --project-id <project>","the project ID for results reporting obtained from Currents").env(h("projectId")),ur=new c.Option("-t, --tag <tag>","comma-separated tag(s) for recorded runs in Currents").argParser(Pe),lr=new c.Option("--pwc-environment <name>","run-level environment name for Currents (e.g. staging, prod)").env(h("environment")),dr=new c.Option("--pwc-remove-title-tags","remove tags from test names in Currents, e.g. `Test name @smoke` becomes `Test name` in the dashboard"),fr=new c.Option("--pwc-disable-title-tags","[DEPRECATED] Use --pwc-disable-test-tags instead"),gr=new c.Option("--pwc-disable-test-tags","disable reporting tags defined on the test or suite level, or extracted from the test title"),mr=new c.Option("--pwc-cancel-after-failures <number | false>","abort the cloud run after the specified number of failed tests detected. Overrides the default Currents Project settings. If set, must be a positive integer or 'false' to disable automatic cancellations").env(h("cancelAfterFailures")).argParser(te),hr=new c.Option("--pwc-output-file <string>","path to the file where the run summary output will be written.").env(h("outputFile")),Uo=new c.Option("--pwc-discovery-file <file>","path to the test discovery file shared by `pwc-p discover` and `pwc-p run`").env(h("discoveryFile")),Ao=new c.Option("--list","ignored (discover always runs playwright with --list)").hideHelp(),No=new c.Option("--reporter <reporters>","ignored (discover always runs playwright with --reporter=list)").hideHelp(),yr=new c.Option("--pwc-console-output <preset>","reporter console output: none (no stdout), summary (intro + one line per test + summary), detailed (full output)").choices(Object.values(R)).env(h("consoleOutput")),wr=new c.Option("--pwc-test-suite-file <path>","path to the full test suite file for orchestration and reporting").env(h("testSuiteFile")).hideHelp(),Cr=new c.Option("--pwc-machine-id <string>","unique identifier of the machine running the tests. If not provided, it will be generated automatically. See: https://docs.currents.dev/?q=machineId").env(h("machineId")),br=new c.Option("--pwc-orchestration-id <string>","unique identifier of the orchestration session this run belongs to. See: https://docs.currents.dev/?q=orchestrationId").env(h("orchestrationId")).hideHelp();var Tr=new c.Option("--pwc-inspect","enable inspect mode, run playwright with --inspect-brk flag or developments and debugging").default(!1).hideHelp(),_o=new c.Option("--pwc-reset-signal <'SIGUSR1' | 'SIGUSR2'>","specify a process signal to listen for to trigger a reset of the current in progress tests. Only avaiable on OSes with POSIX signal support.").argParser(We),Or=new c.Option("--reporter <reporter>","Reporter to use, comma-separated").argParser(Pe).hideHelp(),Fo=new c.Option("-c, --config <file>","Playwright configuration file path"),jo=new c.Option("--tsconfig <path>","path to a single tsconfig applicable to all imported files"),ga=new c.Option("--test-list <file>","path to a file containing a list of tests to run (Playwright --test-list)"),ma=new c.Option("--project <name...>","only run tests from the specified Playwright projects (variadic)"),Lo=new c.Option("-j, --workers <workers>","number of concurrent workers or percentage of logical CPU cores per shard"),$o=new c.Option("--timeout <ms>","per-test timeout in milliseconds"),Ho=new c.Option("--headed","run tests in headed browsers"),Bo=new c.Option("--fully-parallel","run all tests in parallel (Playwright fullyParallel)"),qo=new c.Option("--output <dir>","directory for output artifacts"),Mo=new c.Option("--ignore-snapshots","ignore screenshot and snapshot expectations"),Wo=new c.Option("--fail-on-flaky-tests","fail the run if any test is flagged as flaky");var zo=new c.Option("--pwc-skip-reporter-injection","do not inject @currents/playwright reporter, use the reporters specified in the playwright configuration file");function Pe(e,t=[]){return e?t.concat(e.split(",").map(r=>r.trim())):t}var xr=new c.Option("--pwc-coverage [projects...]","comma-separated list of projects to collect coverage for, e.g. `project1,project2`. If no projects are specified, coverage will be collected for all projects.").argParser(Pe),vr=new c.Option("--pwc-coverage-dir <path>","directory path for reading coverage reports"),Go=new c.Option("--pwc-batch-size <'auto' | number>","set the number of parallel workers for orchestration; Use 'auto' to match the number of Playwright workers. If a number is provided, it must be a positive integer.").default("auto").env(h("batchSize")).argParser(e=>{if(e==="auto")return e;let t=Number(e);if(!isNaN(t)&&Number.isInteger(t)&&t>0)return t;throw new sr.InvalidArgumentError('Provide either "auto" or a positive integer.')});var Er=(e=ke())=>e.version(q),De=`---------------------------------------------------- \u{1F4D6} Documentation: https://docs.currents.dev \u{1F919} Support: support@currents.dev ----------------------------------------------------`,Vo=` ${De} ${Ie.default.bold("Examples")} Run all tests in the current directory: ${l("pwc --key <record-key> --project-id <id> --ci-build-id <build-id>")} Run only tests filtered by the tag "@smoke": ${l("pwc --key <record-key> --project-id <id> --ci-build-id <build-id> --grep smoke")} Run playwright tests and add tags "tagA", "tagB" to the recorded run: ${l("pwc --key <record-key> --project-id <id> --ci-build-id <build-id> --tag tagA --tag tagB")} Provide playwright arguments and flags: ${l("pwc --key <record-key> --project-id <id> --ci-build-id <build-id> -- --workers 2 --timeout 10000 --shard 1/2")} `,Jo=` Orchestration is a two-step process: 1. Select tests for orchestration: ${l("pwc-p discover --pwc-discovery-file <path>")} 2. Orchestrate the selected tests: ${l("pwc-p run --key <record-key> --project-id <id> --ci-build-id <build-id> --pwc-discovery-file <path>")} Discovery file can be set by: ${l("--pwc-discovery-file <path>")} CLI flag ${l("CURRENTS_DISCOVERY_FILE")} environment variable ${l("orchestration.discoveryFile")} in currents.config ${Ie.default.bold("Examples")} (assuming you have a discovery file at tests.txt) Orchestrate the selected tests: ${l("pwc-p run --key <record-key> --project-id <id> --ci-build-id <build-id> --pwc-discovery-file tests.txt")} Extra Playwright runtime flags (supported subset only): ${l("pwc-p run --pwc-discovery-file tests.txt --key <record-key> --project-id <id> --ci-build-id <build-id> -j 4 --timeout 60000")} Add tags "tagA", "tagB" to the recorded run: ${l("pwc-p run --pwc-discovery-file tests.txt --key <record-key> --project-id <id> --ci-build-id <build-id> --tag tagA --tag tagB")} `,Oa=` ${De}${Jo}`;var xa=` ${De} Orchestration is a two-step process: 1. Select tests for orchestration: ${l("pwc-p discover --pwc-discovery-file <path>")} 2. Orchestrate the selected tests: ${l("pwc-p run --key <record-key> --project-id <id> --ci-build-id <build-id> --pwc-discovery-file <path>")} See ${l("pwc-p discover --help")} / ${l("pwc-p run --help")} for more details.`;function Sr(e){return e.code==="commander.helpDisplayed"||e.code==="commander.help"||e.code==="commander.version"}var ke=()=>new Rr.Command().name("pwc").usage("[options] [playwright arguments and flags]").allowUnknownOption().allowExcessArguments(!0).showHelpAfterError("(add --help for additional information)").description(`\u{1F3AD} Run Playwright tests on CI using https://currents.dev ${Vo}`).addOption(ar).addOption(cr).addOption(pr).addOption(ur).addOption(lr).addOption(ir).addOption(dr).addOption(gr).addOption(fr).addOption(mr).addOption(hr).addOption(yr).addOption(wr).addOption(Cr).addOption(br).addOption(Tr).addOption(_).addOption(xr).addOption(vr).addOption(Or).action(function(){this.opts().pwcDisableTitleTags&&u(`${l("--pwc-disable-title-tags")} has been renamed to ${l("--pwc-disable-test-tags")}.`)});var Ue=d.extend("cli-manager"),J=class{program;cliOptions;parsedConfig;configFilePath=null;constructor(t={isOrchestration:!1}){if(t.isOrchestration){if(!t.runCommand)throw new Error("CLIManager: orchestration mode requires `runCommand` (parsed `pwc-p run` Commander instance).");this.program=t.runCommand,this.cliOptions=t.runCommand.opts()}else this.program=Er(ke()),this.cliOptions=this.program.parse().opts();Ue("CLI options: %o",this.cliOptions),this.parsedConfig=ze(this.cliOptions),Ue("Parsed config from CLI options: %o",this.parsedConfig)}getCLIReporters(){return this.cliOptions.reporter?.filter(t=>!/@currents/.test(t))||[]}async getConfigFilePath(){if(this.configFilePath)return this.configFilePath;let t=await nr();return Pr.default.writeFileSync(t,JSON.stringify(this.parsedConfig)),Ue("CLI options temp file path: %s",t),this.configFilePath=t,this.configFilePath}};var Ir=d.extend("pwc");require("dotenv").config({quiet:!0});var Y=V.factory("pwc");async function Yo(){let e=new J;return await(await rr())("playwright",["test","--reporter",["@currents/playwright",...e.getCLIReporters()].join(","),...e.program.args],{stdio:"inherit",reject:!1,env:{...process.env,CURRENTS_DEBUG:String(Y.getDebugMode()),CURRENTS_PWC_CLI_CONFIG_PATH:await e.getConfigFilePath()}})}Yo().then(async e=>{Ir("execa result: %o",e),await Y.finalize(),process.exit(e.exitCode??0)}).catch(async e=>{e instanceof Dr.CommanderError&&(Sr(e)||x(e.message),await Y.finalize(),process.exit(e.exitCode)),Ir("execa failed: %o",e),await Y.finalize(),process.exit(1)}); //# sourceMappingURL=pwc.js.map