@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) • 35.6 kB
JavaScript
;var _r=Object.create;var Z=Object.defineProperty;var Fr=Object.getOwnPropertyDescriptor;var jr=Object.getOwnPropertyNames;var Lr=Object.getPrototypeOf,$r=Object.prototype.hasOwnProperty;var a=(e,t)=>()=>(e&&(t=e(e=0)),t);var je=(e,t)=>{for(var r in t)Z(e,r,{get:t[r],enumerable:!0})},Hr=(e,t,r,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of jr(t))!$r.call(e,s)&&s!==r&&Z(e,s,{get:()=>t[s],enumerable:!(o=Fr(t,s))||o.enumerable});return e};var g=(e,t,r)=>(r=e!=null?_r(Lr(e)):{},Hr(t||!e||!e.__esModule?Z(r,"default",{value:e,enumerable:!0}):r,e));var n=a(()=>{"use strict"});var Le=a(()=>{"use strict";n()});var $e=a(()=>{"use strict";n()});function He(e){Mr.push(e)}var Mr,Q=a(()=>{"use strict";n();Mr=[]});var R,Br,qr,Wr,ao,j=a(()=>{"use strict";n();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},Wr={introAndSummary:!0,testOutput:"full",progress:!0,tables:!0,warningsAndErrors:!0},ao={[R.None]:Br,[R.Summary]:qr,[R.Detailed]:Wr}});var Me,Be,qe=a(()=>{"use strict";n();Me=[],Be=[]});function zr(e){return We?!!We[e]:!0}function $(e,t){He(t),zr(e)&&console.log(t)}var w,L,We,H,u,x,D,Co,bo,To,Oo,xo,vo,Ro,Eo,So,l,Po,ze=a(()=>{"use strict";n();w=g(require("chalk")),L=g(require("util"));j();b();Q();qe();We=null;H=(...e)=>{$("introAndSummary",L.default.format(...e))},u=(...e)=>{let t=L.default.format(...e);Be.push(t),d("WARNING: ",t),$("warningsAndErrors",w.default.bgYellow.black(" WARNING ")+" "+t)},x=(...e)=>{let t=L.default.format(...e);Me.push(t),d("ERROR: ",t),$("warningsAndErrors",w.default.bgRed.white(" ERROR ")+" "+t)},D=(e=2)=>{let t=Math.max(0,Math.floor(e));t!==0&&$("introAndSummary",Array(t).fill("").join(`
`))},Co=w.default.cyan,bo=w.default.blueBright,To=w.default.red,Oo=w.default.yellow,xo=w.default.green,vo=w.default.gray,Ro=w.default.white,Eo=w.default.black,So=w.default.magenta,l=w.default.dim,Po=w.default.bold});var O=a(()=>{"use strict";n();Q();ze()});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 Ge(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()}function re(e){if(e===void 0)return;let t;if(typeof e=="number")t=e;else{let r=e.trim();if(r==="")return;t=Number(r)}if(!(!Number.isInteger(t)||t<0))return t}var ee,ne=a(()=>{"use strict";n();ee=require("commander")});function m(e){return Kr[e]?.env}var Kr,oe=a(()=>{"use strict";n();ne();Kr={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"},pendingChildExitTimeoutMs:{name:"Pending Child Exit Timeout",env:"CURRENTS_OR8N_PENDING_CHILD_EXIT_TIMEOUT_MS",cli:"--pwc-pending-child-exit-timeout-ms"},ciUrl:{name:"CI URL",env:"CURRENTS_CI_URL"}}});function Ke(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,pendingChildExitTimeoutMs:e.pwcPendingChildExitTimeoutMs},coverage:{projects:e.pwcCoverage,dir:e.pwcCoverageDir}}}var Vr,Ho,se=a(()=>{"use strict";n();Vr=g(require("fs"));b();Ho=d.extend("cli-options-serializer")});function Ve(){return Jr}var os,ss,Jr,ie=a(()=>{"use strict";n();b();Le();$e();O();j();oe();se();j();os=d.extend("config"),ss={removeTitleTags:!1,disableTestTags:!1,consoleOutput:R.Detailed,orchestration:{skipReporterInjection:!1},coverage:{projects:!1}},Jr=null});var Xr,Je=a(()=>{"use strict";n();Xr=require("lodash");O()});var M=a(()=>{"use strict";n();ie();oe();se();Je()});var Ye,Xe=a(()=>{Ye={name:"@currents/playwright",version:"2.4.0",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.1",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 B,ae=a(()=>{"use strict";n();Xe();B=Ye.version});var pe,Ze,Qe=a(()=>{"use strict";n();pe=()=>process.env.CURRENTS_API_URL??"https://cy.currents.dev",Ze=()=>3e4});var Zr,Rs,et=a(()=>{"use strict";n();Zr=g(require("ws"));b();Rs=d.extend("ws")});var tt,As,rt,nt=a(()=>{"use strict";n();tt=g(require("events"));ie();b();et();ce();As=d.extend("pubsub"),rt=new tt.default});var ue,st,ot,it,at=a(()=>{"use strict";n();O();nt();ue={cancellationReason:null},st=e=>{ue.cancellationReason||(ue.cancellationReason=e)},ot=()=>ue.cancellationReason,it=({showWarning:e=!0}={})=>{let t=ot();t&&(e&&u("%s",t),rt.emit("runCancelled",t))}});var ce=a(()=>{"use strict";n();at()});var pt,k,le=a(()=>{"use strict";n();pt=require("nanoid"),k=(0,pt.customAlphabet)("abcdefghijklmnopqrstuvwxyz",10)});var ct,Qr,ut,lt=a(()=>{"use strict";n();ct=require("ts-pattern"),Qr={outcome:null,scannerConfig:null,currentsConfig:null,internalConfig:null},ut=()=>Qr});function q(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,N=a(()=>{"use strict";n();U=["ECONNABORTED","ECONNREFUSED","ECONNRESET","ETIMEDOUT","EPIPE","ENETUNREACH","EHOSTUNREACH","ENETRESET","ENOTFOUND","EAI_AGAIN"]});function mt(e){(0,h.match)(e).when(q,en).otherwise(()=>{u("Unexpected error while sending network request: %s",e)})}function en(e){let t=e.response?.config??e.config;return(0,h.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:h.P.not(h.P.nullish)},r=>{tn(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:A(e)})})}function tn(e,{status:t,data:r}){let o=e.response?.config??e.config,s=o?.method,c=o?.url;(0,h.match)(t).with(401,()=>{u(`[currents] ${s} ${c} - 401 Unauthorized Request from cloud service`)}).with(400,()=>{u(`[currents] ${s} ${c} - 400 Bad Request from cloud service:
%o`,r)}).with(429,()=>{u(`[currents] ${s} ${c} - 429 Too Many Requests from cloud service`)}).with(422,()=>{rn(e,r)}).otherwise(()=>{u(`[currents] Unexpected network response: %s
%O`,e.message,{method:s,url:c,status:e.response?.status,requestId:A(e)})})}function rn(e,t){let r=e.response?.config??e.config;(0,h.match)(t).with({code:de.MISSING_SUITE,message:h.P.string,errors:h.P.array(h.P.string)},async o=>{let{message:s,errors:c}=o;D(1),x(...dt(s,c)),W({id:k(),text:(0,gt.default)(ut(),null,2)}).then(f=>{x(`Please share this URL with Currents support for further investigation:
${f}`)}).catch(f=>{u("Failed to upload debug artifact: %s",f)}),D(1)}).with({code:de.RUN_CANCELLED,message:h.P.string},o=>{st(o.message),it()}).with({code:de.RUN_EXPIRED,message:h.P.string},o=>{u(o.message)}).with({message:h.P.string,errors:h.P.array(h.P.string)},o=>{let{message:s,errors:c}=o;D(1),u(...dt(s,c)),D(1)}).otherwise(()=>{u(`[currents] Unexpected network response: %s
%O`,e.message,{method:r?.method,url:r?.url,status:e.response?.status,requestId:A(e)})})}function dt(e,t){return ft.default.isString(e)?t?.length===0?[e]:[e,`
${(t??[]).map(r=>` - ${r}`).join(`
`)}
`]:["Unexpected network error"]}function A(e){let t=e?.response?.headers;if(!(!t||typeof t!="object")){for(let[r,o]of Object.entries(t))if(r.toLowerCase()==="apigw-requestid")return Array.isArray(o)?o[0]:o}}var gt,ft,h,de,ge=a(()=>{"use strict";n();gt=g(require("json-stringify-safe")),ft=g(require("lodash")),h=require("ts-pattern");ce();le();O();fe();lt();N();de={RUN_CANCELLED:"RUN_CANCELLED",RUN_EXPIRED:"RUN_EXPIRED",MISSING_SUITE:"MISSING_SUITE"}});function Ct(e,t,r){let o=r.method?.toUpperCase(),s=r.url,c=A(t),f=(0,ht.default)(me(e)),y=`Network request '${o} ${s}' failed: '${t.message}'.${c?` Request ID: ${c}.`:""} Next attempt is in ${f} (${e}/${r["transport-retry"]?.retries??he()}).`;wt(y),u(y)}var ht,wt,me,yt,he,bt=a(()=>{"use strict";n();ht=g(require("pretty-ms"));b();O();ge();N();wt=d.extend("http"),me=e=>{let t=[3e3,15e3,3e4];return t[Math.min(Math.max(e-1,0),t.length-1)]},yt=e=>{if(wt("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(!q(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)},he=()=>3});function on(e){let t=xt.default.getProxyForUrl(e);if(t)return nn("Using HTTP proxy %s for %s",t,e),Tt===t&&z||(Tt=t,z=new Ot.ProxyAgent(t)),z}function vt(e,t){if(/^https?:\/\//i.test(t))return t;let r=e??"",o=r.endsWith("/")?r:`${r}/`,s=t.replace(/^\/+/,"");return new URL(s,o).href}function sn(e){let t={};return e.forEach((r,o)=>{let s=t[o];s===void 0?t[o]=r:Array.isArray(s)?s.push(r):t[o]=[String(s),r]}),t}function an(e){for(let[t,r]of Object.entries(e))if(t.toLowerCase()==="content-type"){let o=Array.isArray(r)?r[0]:r;return typeof o!="string"?"":o.split(";")[0]?.trim()?.toLowerCase()??""}return""}function pn(e,t){let r=t.toLowerCase();if(r.includes("application/json")||r.endsWith("+json"))return!0;let o=e.trim();return o.length?/^(?:\{|\[|"|-?\d|true$|false$|null$)/.test(o):!1}function cn(e,t){if(!e.length)return null;if(pn(e,t))try{return JSON.parse(e)}catch{return e}return e}function un(e){let t=e;for(let r=0;r<8&&t&&typeof t=="object";r++){let o=t;if(o.name==="AbortError"||o.name==="TimeoutError"||typeof o.message=="string"&&/aborted|timeout/i.test(o.message))return!0;t=o.cause}return!1}function Rt(e){if(!e||typeof e!="object")return;if(un(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 Rt(t.cause);if(/connection reset|other side closed|terminated|socket hang up/i.test(r))return"ECONNRESET"}function ln(e){return e instanceof we.Readable}function dn(e){return ln(e)?{body:we.Readable.toWeb(e),duplex:"half"}:{body:e}}async function G(e,t,r){let o=on(e),s,c;try{let C={method:t.method,headers:t.headers,signal:t.signal};if(t.body!==void 0){let S=dn(t.body);C.body=S.body,S.duplex&&(C.duplex=S.duplex)}o!==void 0&&(C.dispatcher=o),s=await fetch(e,C),c=await s.text()}catch(C){let S=Rt(C);throw{message:C instanceof Error?C.message:String(C),code:S,config:r}}let f=sn(s.headers),y=an(f),I=cn(c,y),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:f,data:I,config:r}};return{data:I,status:T,statusText:F,headers:f,config:r}}var we,Ot,xt,nn,Tt,z,ye=a(()=>{"use strict";n();we=require("stream"),Ot=require("undici");b();N();xt=g(require("proxy-from-env")),nn=d.extend("http:transport"),Tt=null,z=null});function wn(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 yn(e,t){if(!e)return;let r=t.toLowerCase();for(let[o,s]of Object.entries(e))if(o.toLowerCase()===r&&s!==void 0)return Array.isArray(s)?s[0]:String(s)}function Cn(e){let t={};if(!e)return t;for(let[r,o]of Object.entries(e))o!==void 0&&(t[r.toLowerCase()]=Array.isArray(o)?o.join(", "):String(o));return t}function bn(...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 Tn(e){let t={...hn,...e.currentsOptions};return!t.enableCompression||e.data===void 0||Buffer.isBuffer(e.data)||typeof e.data=="string"||(0,It.default)(e.data)<=t.compressThresholdBytes?e:{...e,data:await mn((0,Ce.default)(e.data)),headers:{...e.headers,"Content-Encoding":"gzip"}}}function On(e){let{data:t}=e;if(t!==void 0)return Buffer.isBuffer(t)||typeof t=="string"?t:(0,Ce.default)(t)}async function xn(e){let t=e.baseURL??pe(),r=e["transport-retry"]?.retries??he(),o=wn(e.headers)??(0,Pt.nanoid)(),s=await Tn(e),c=On(s),f=(s.method??"get").toUpperCase(),y=e.signal;if(y?.aborted)throw{message:y.reason?.message??"Request aborted",code:"ECONNABORTED",config:e};let I;for(let T=0;T<=r;T++){let F=s.timeout??Ze(),C=AbortSignal.timeout(F),S=y?bn(y,C):C,P=Ve(),v={...Cn(s.headers),...fn,"accept-encoding":"gzip, deflate, br","x-currents-idempotency-key":o,"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),yn(e.headers,"content-type")||(v["content-type"]=v["content-type"]??"application/json");let Ur={...s,method:f,url:e.url,baseURL:t,headers:v},Nr=vt(t,e.url??""),_e={method:f,url:e.url,headers:v,data:Buffer.isBuffer(c)?"buffer":c};T?Et("network request retry: %o",St({..._e,isRetry:!0})):Et("network request: %o",St(_e));try{return await G(Nr,{method:f,headers:v,body:c,signal:S},Ur)}catch(Y){I=Y;let Fe=Y;if(!yt(Fe)||T>=r)throw Y;Ct(T+1,Fe,{...e,method:f}),await new Promise(Ar=>setTimeout(Ar,me(T+1)))}}throw I}function vn(){return{request:e=>xn(e)}}function Ut(){return K||(K=vn(),K)}function St(e){return{method:e.method,baseUrl:pe(),url:e.url,data:e.isRetry?"<retry>":Rn(e.data),headers:{...e.headers,"x-currents-key":"***"}}}function Rn(e){let t=e;return t?.results?.raw?{...t,results:{...t.results,raw:"***"}}:e}var Ce,Pt,It,Dt,kt,Et,gn,fn,mn,hn,K,Nt=a(()=>{"use strict";n();Ce=g(require("json-stringify-safe")),Pt=require("nanoid"),It=g(require("object-sizeof")),Dt=require("util"),kt=g(require("zlib"));M();b();ae();Qe();bt();ye();Et=d.extend("http"),gn=1024*1024*1,fn={"x-pw-version":"0.0.0","x-pwc-version":B},mn=(0,Dt.promisify)(kt.default.gzip),hn={enableCompression:!1,compressThresholdBytes:gn},K=null});async function Ft(e,t=Ut){try{let r=await t().request(e);return At("network response: %o",{..._t.default.omit(r,"request","config"),url:r.config.url,method:r.config.method}),r}catch(r){let o=r;throw At("network error: %o",{code:o.code,message:o.message,url:o.config?.url,method:o.config?.method,status:o.response?.status,headers:o.response?.headers,data:o.response?.data}),mt(o),o}}var _t,At,jt=a(()=>{"use strict";n();_t=g(require("lodash"));b();Nt();ge();At=d.extend("http")});var Lt=a(()=>{"use strict";n();jt();N()});var $t={};je($t,{getDebugUrl:()=>En});var En,Ht=a(()=>{"use strict";n();Lt();En=({runId:e,type:t})=>Ft({method:"POST",url:"runs/debug-logs",data:{type:t,runId:e}}).then(r=>r.data)});function Pn(e,t){return Gt({path:e,name:null,uploadUrl:t,contentType:"text/plain"},"text/plain")}async function Gt(e,t,r){let o=await Bt.default.readFile(e.path);return be("Uploading file %s",e.uploadUrl,{buffer:Buffer.byteLength(o)}),Kt(o,e.uploadUrl,t,r)}async function In(e,t,r){return be("Uploading buffer %s",e.name,{buffer:Buffer.byteLength(e.buffer)}),Kt(e.buffer,e.uploadUrl,t,r)}function Dn(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 kn(e,t,r,o){let s=Dn(t),c=e,f={"Content-Disposition":"inline","Content-Type":r};o?.compress&&(c=await Sn(e),f["Content-Encoding"]="gzip"),await G(s,{method:"PUT",headers:f,body:c},{method:"PUT",url:s,headers:f})}async function Kt(e,t,r,o){await(0,Mt.default)(async()=>{await kn(e,t,r,o)},{retries:5,onRetry:(s,c)=>{if(be(`Upload failed %d out of 5 attempts: %s
%o`,c,s.message,s.response?.data),c===5){x(`Cannot upload after ${c} times: ${s.message}`);return}u(`Upload failed ${c} out of 5 attempts: ${s.message}`)}})}var Mt,Bt,qt,Wt,be,Sn,zt,Vt=a(()=>{"use strict";n();Mt=g(require("async-retry")),Bt=g(require("fs/promises")),qt=require("util"),Wt=require("zlib");b();ye();O();be=d.extend("upload"),Sn=(0,qt.promisify)(Wt.gzip),zt=(s=>(s.PNG="image/png",s.WEBM="video/webm",s.TEXT="text/plain",s.ZIP="application/zip",s))(zt||{})});var Jt={};je(Jt,{ContentType:()=>zt,sendBuffer:()=>In,sendPath:()=>Gt,uploadText:()=>Pn});var Xt=a(()=>{"use strict";n();Vt()});async function W(e){let{getDebugUrl:t}=await Promise.resolve().then(()=>(Ht(),$t));try{let{readUrl:r,uploadUrl:o}=await t({runId:e.id,type:"pw-debug"}),{uploadText:s,sendBuffer:c}=await Promise.resolve().then(()=>(Xt(),Jt));return"text"in e&&await c({name:`${e.id}-discovery-debug.log`,buffer:Buffer.from(e.text,"utf-8"),contentType:"text/plain",uploadUrl:o},"text/plain"),"path"in e&&await s(e.path,o),r}catch{return null}}var Te,Oe=a(()=>{"use strict";n();Te=g(require("debug"))});function Un(e){return e==="false"?!1:e==="remote"?"remote":e==="full"?"full":!!e}var Yt,_,xe=a(()=>{"use strict";n();Yt=require("@commander-js/extra-typings"),_=new Yt.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(Un).env("CURRENTS_DEBUG")});var Zt,Qt,er=a(()=>{"use strict";n();Zt=require("@commander-js/extra-typings");xe();Qt=()=>new Zt.Command().allowUnknownOption().allowExcessArguments(!0).addOption(_).helpOption(!1)});var E,tr,Re,rr,nr,ve,V,Ee=a(()=>{"use strict";n();E=g(require("debug")),tr=g(require("fs")),Re=g(require("path")),rr=g(require("util")),nr=require("fs/promises");le();O();er();Oe();E.default.useColors=function(){return!1};ve=E.default.log,V=class e{constructor(t="core"){this.source=t;if(this.mode=Qt().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 o=k(),s=Re.default.resolve(".currents-debug"),c=Re.default.resolve(s,`${o}.log`);(0,nr.mkdir)(s,{recursive:!0}),H(l(`\u{1F47E} Initiated remote ${this.source} debug log collection:`),l(c));let f=tr.default.createWriteStream(c,{flags:"a"});return E.default.log=(...y)=>{this.mode&&(f.write(`${rr.default.formatWithOptions({colors:!1},...y)}
`),this.shouldMuteLocalStdout()||ve(...y))},this.pipelines[o]={id:o,writeStream:f,type:this.source,tempFilePath:c},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=ve);for(let o of r)await this.uploadDebug(o,t??k())}catch{}finally{E.default.log=ve}}async uploadDebug(t,r){let o=this.pipelines[t];if(!o){this.debug("No debug pipeline found for id %s",t);return}H(l(`\u{1F47E} ${o.type} debug log written:`),l(o?.tempFilePath));try{let s=await W({id:r,path:o.tempFilePath});o?.writeStream.end(),H(l(`\u{1F47E} ${o.type} debug log uploaded:`),l(s))}catch(s){u(`Failed to upload ${o.type}} debug log ${l(o.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";n();Oe();Ee()});var d,b=a(()=>{"use strict";n();fe();d=(0,Te.default)("currents")});n();var Fa=require("source-map-support/register"),kr=require("commander");b();n();var Se;async function or(){if(Se)return Se;let{execa:e}=await import("execa");return Se=e,e}O();Ee();n();var Ir=g(require("fs"));M();b();n();var Pe=g(require("fs")),sr=require("tmp-promise"),ir=async()=>{let{path:e}=await(0,sr.file)();return e};n();var Er=require("@commander-js/extra-typings"),ke=g(require("chalk")),Jn=require("commander");ae();O();n();var p=require("@commander-js/extra-typings"),Ie=require("commander");M();ne();xe();var ar=new p.Option("--pwc-config <path>","path to currents config file (currents.config.[ts|js])").env(m("currentsConfigFile")),pr=new p.Option("--ci-build-id <id>","the unique run identifier").env(m("ciBuildId")),cr=new p.Option("-k, --key <record-key>","your secret Record Key obtained from Currents").env(m("recordKey")),ur=new p.Option("-p, --project-id <project>","the project ID for results reporting obtained from Currents").env(m("projectId")),lr=new p.Option("-t, --tag <tag>","comma-separated tag(s) for recorded runs in Currents").argParser(De),dr=new p.Option("--pwc-environment <name>","run-level environment name for Currents (e.g. staging, prod)").env(m("environment")),gr=new p.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 p.Option("--pwc-disable-title-tags","[DEPRECATED] Use --pwc-disable-test-tags instead"),mr=new p.Option("--pwc-disable-test-tags","disable reporting tags defined on the test or suite level, or extracted from the test title"),hr=new p.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(m("cancelAfterFailures")).argParser(te),wr=new p.Option("--pwc-output-file <string>","path to the file where the run summary output will be written.").env(m("outputFile")),Nn=new p.Option("--pwc-discovery-file <file>","path to the test discovery file shared by `pwc-p discover` and `pwc-p run`").env(m("discoveryFile")),An=new p.Option("--list","ignored (discover always runs playwright with --list)").hideHelp(),_n=new p.Option("--reporter <reporters>","ignored (discover always runs playwright with --reporter=list)").hideHelp(),yr=new p.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(m("consoleOutput")),Cr=new p.Option("--pwc-test-suite-file <path>","path to the full test suite file for orchestration and reporting").env(m("testSuiteFile")).hideHelp(),br=new p.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(m("machineId")),Tr=new p.Option("--pwc-orchestration-id <string>","unique identifier of the orchestration session this run belongs to. See: https://docs.currents.dev/?q=orchestrationId").env(m("orchestrationId")).hideHelp();var Or=new p.Option("--pwc-inspect","enable inspect mode, run playwright with --inspect-brk flag or developments and debugging").default(!1).hideHelp(),Fn=new p.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(Ge),xr=new p.Option("--reporter <reporter>","Reporter to use, comma-separated").argParser(De).hideHelp(),jn=new p.Option("-c, --config <file>","Playwright configuration file path"),Ln=new p.Option("--tsconfig <path>","path to a single tsconfig applicable to all imported files"),ha=new p.Option("--test-list <file>","path to a file containing a list of tests to run (Playwright --test-list)"),wa=new p.Option("--project <name...>","only run tests from the specified Playwright projects (variadic)"),$n=new p.Option("-j, --workers <workers>","number of concurrent workers or percentage of logical CPU cores per shard"),Hn=new p.Option("--timeout <ms>","per-test timeout in milliseconds"),Mn=new p.Option("--headed","run tests in headed browsers"),Bn=new p.Option("--fully-parallel","run all tests in parallel (Playwright fullyParallel)"),qn=new p.Option("--output <dir>","directory for output artifacts"),Wn=new p.Option("--ignore-snapshots","ignore screenshot and snapshot expectations"),zn=new p.Option("--fail-on-flaky-tests","fail the run if any test is flagged as flaky");var Gn=new p.Option("--pwc-skip-reporter-injection","do not inject @currents/playwright reporter, use the reporters specified in the playwright configuration file");function De(e,t=[]){return e?t.concat(e.split(",").map(r=>r.trim())):t}var vr=new p.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(De),Rr=new p.Option("--pwc-coverage-dir <path>","directory path for reading coverage reports"),Kn=new p.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(m("batchSize")).argParser(e=>{if(e==="auto")return e;let t=Number(e);if(!isNaN(t)&&Number.isInteger(t)&&t>0)return t;throw new Ie.InvalidArgumentError('Provide either "auto" or a positive integer.')}),Vn=new p.Option("--pwc-pending-child-exit-timeout-ms <milliseconds>","force-exit pending Playwright child processes after orchestration finishes when they have not exited").env(m("pendingChildExitTimeoutMs")).argParser(e=>{let t=re(e);if(t===void 0)throw new Ie.InvalidArgumentError("Must be a non-negative integer.");return t});var Sr=(e=Ne())=>e.version(B),Ue=`----------------------------------------------------
\u{1F4D6} Documentation: https://docs.currents.dev
\u{1F919} Support: support@currents.dev
----------------------------------------------------`,Xn=`
${Ue}
${ke.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")}
`,Yn=`
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
${ke.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")}
`,va=`
${Ue}${Yn}`;var Ra=`
${Ue}
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 Pr(e){return e.code==="commander.helpDisplayed"||e.code==="commander.help"||e.code==="commander.version"}var Ne=()=>new Er.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
${Xn}`).addOption(pr).addOption(cr).addOption(ur).addOption(lr).addOption(dr).addOption(ar).addOption(gr).addOption(mr).addOption(fr).addOption(hr).addOption(wr).addOption(yr).addOption(Cr).addOption(br).addOption(Tr).addOption(Or).addOption(_).addOption(vr).addOption(Rr).addOption(xr).action(function(){this.opts().pwcDisableTitleTags&&u(`${l("--pwc-disable-title-tags")} has been renamed to ${l("--pwc-disable-test-tags")}.`)});var Ae=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=Sr(Ne()),this.cliOptions=this.program.parse().opts();Ae("CLI options: %o",this.cliOptions),this.parsedConfig=Ke(this.cliOptions),Ae("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 ir();return Ir.default.writeFileSync(t,JSON.stringify(this.parsedConfig)),Ae("CLI options temp file path: %s",t),this.configFilePath=t,this.configFilePath}};var Dr=d.extend("pwc");require("dotenv").config({quiet:!0});var X=V.factory("pwc");async function Zn(){let e=new J;return await(await or())("playwright",["test","--reporter",["@currents/playwright",...e.getCLIReporters()].join(","),...e.program.args],{stdio:"inherit",reject:!1,env:{...process.env,CURRENTS_DEBUG:String(X.getDebugMode()),CURRENTS_PWC_CLI_CONFIG_PATH:await e.getConfigFilePath()}})}Zn().then(async e=>{Dr("execa result: %o",e),await X.finalize(),process.exit(e.exitCode??0)}).catch(async e=>{e instanceof kr.CommanderError&&(Pr(e)||x(e.message),await X.finalize(),process.exit(e.exitCode)),Dr("execa failed: %o",e),await X.finalize(),process.exit(1)});
//# sourceMappingURL=pwc.js.map