@testrelic/playwright-analytics 2.9.0-next.65 → 2.9.0-next.66

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/fixture.cjs CHANGED
@@ -1,5 +1,5 @@
1
- 'use strict';var test=require('@playwright/test'),fs=require('fs'),path=require('path'),os=require('os'),crypto=require('crypto');require('readline');var perf_hooks=require('perf_hooks'),url=require('url'),core=require('@testrelic/core');var D=path.join(os.tmpdir(),"testrelic-data"),k=class{constructor(t){this.count=0;this.closed=false;fs.mkdirSync(D,{recursive:true}),this.filePath=path.join(D,`${t}-${crypto.randomUUID().substring(0,8)}.jsonl`),this.fd=fs.openSync(this.filePath,"w");}append(t){if(this.closed)return;let e=JSON.stringify(t)+`
2
- `;fs.writeSync(this.fd,e),this.count++;}getPath(){return this.filePath}getCount(){return this.count}close(){if(!this.closed){this.closed=true;try{fs.closeSync(this.fd);}catch{}}}cleanup(){try{fs.unlinkSync(this.filePath);}catch{}}};var nt=["text/","application/json","application/xml","application/javascript","application/x-www-form-urlencoded","application/graphql"];function rt(r){let t=r.toLowerCase();return nt.some(e=>t.includes(e))}var A=class r{constructor(t,e){this.page=t;this.records=[];this.listeners=[];this.currentNetworkCounter=null;this.pendingRequests=new Map;this.networkWriter=null;this.consoleWriter=null;this.pendingBodyReads=[];this.requestIdCounter=0;this.networkRequestCount=0;this.consoleLogCount=0;this.includeNetworkStats=e?.includeNetworkStats??true,this.origGoto=t.goto.bind(t),this.origGoBack=t.goBack.bind(t),this.origGoForward=t.goForward.bind(t),this.origReload=t.reload.bind(t);try{this.includeNetworkStats&&(this.networkWriter=new k("network")),this.consoleWriter=new k("console");}catch{}this.interceptMethods(),this.attachListeners();}async init(){await this.injectSPADetection();}async finalizeCapturedRequests(){await Promise.allSettled(this.pendingBodyReads),this.pendingBodyReads=[];for(let[,t]of this.pendingRequests)this.networkWriter&&(this.networkWriter.append({url:t.url,method:t.method,resourceType:t.resourceType,statusCode:0,responseTimeMs:Date.now()-t.startTimeMs,startedAt:t.startedAt,requestHeaders:t.headers,requestBody:t.postData,responseBody:null,responseHeaders:null,contentType:null,responseSize:0,requestBodyTruncated:t.postDataTruncated,responseBodyTruncated:false,isBinary:false,error:"incomplete"}),this.networkRequestCount++);this.pendingRequests.clear(),this.networkWriter?.close(),this.consoleWriter?.close();}static mapConsoleType(t){switch(t){case "log":return "log";case "warning":return "warn";case "error":return "error";case "info":return "info";case "debug":return "debug";default:return "log"}}async getFileData(){this.includeNetworkStats&&this.currentNetworkCounter&&this.records.length>0&&(this.records[this.records.length-1].networkStats={totalRequests:this.currentNetworkCounter.totalRequests,failedRequests:this.currentNetworkCounter.failedRequests,failedRequestUrls:[...this.currentNetworkCounter.failedRequestUrls],totalBytes:this.currentNetworkCounter.totalBytes,byType:{...this.currentNetworkCounter.byType}});let t=this.records.map(e=>({url:e.url,navigationType:e.navigationType,timestamp:e.timestamp,domContentLoadedAt:e.domContentLoadedAt,networkIdleAt:e.networkIdleAt,networkStats:e.networkStats}));return this.includeNetworkStats?await this.finalizeCapturedRequests():this.consoleWriter?.close(),{navigations:t,networkRequestsFile:this.networkWriter?.getCount()?this.networkWriter.getPath():null,networkRequestsCount:this.networkWriter?.getCount()??0,consoleLogsFile:this.consoleWriter?.getCount()?this.consoleWriter.getPath():null,consoleLogsCount:this.consoleWriter?.getCount()??0}}async flushLegacyAnnotations(t){}dispose(){this.page.goto=this.origGoto,this.page.goBack=this.origGoBack,this.page.goForward=this.origGoForward,this.page.reload=this.origReload;for(let{event:t,handler:e}of this.listeners)this.page.off(t,e);this.listeners=[],this.records=[],this.pendingRequests.clear(),this.pendingBodyReads=[],this.networkWriter?.close(),this.consoleWriter?.close();}getRecords(){return this.records}interceptMethods(){let t=this,e=this.page;e.goto=async function(n,s){return t.recordNavigation(n,"goto"),t.origGoto(n,s)},e.goBack=async function(n){let s=await t.origGoBack(n);return t.recordNavigation(e.url(),"back"),s},e.goForward=async function(n){let s=await t.origGoForward(n);return t.recordNavigation(e.url(),"forward"),s},e.reload=async function(n){return t.recordNavigation(e.url(),"refresh"),t.origReload(n)};}attachListeners(){let t=()=>{this.lastDomContentLoaded=new Date().toISOString(),this.records.length>0&&(this.records[this.records.length-1].domContentLoadedAt=this.lastDomContentLoaded);};this.page.on("domcontentloaded",t),this.listeners.push({event:"domcontentloaded",handler:t});let e=s=>{try{let i=s;if(typeof i.parentFrame=="function"&&i.parentFrame()!==null)return;let p=i.url(),c=this.records[this.records.length-1];if(c&&Date.now()-new Date(c.timestamp).getTime()<50&&c.url===p)return;this.recordNavigation(p,"navigation");}catch{}};this.page.on("framenavigated",e),this.listeners.push({event:"framenavigated",handler:e});let n=s=>{try{let i=s,p=i.type(),c=i.text();if(p==="debug"&&c.startsWith("__testrelic_nav:")){try{let a=JSON.parse(c.slice(16));a.type&&a.url&&this.recordNavigation(a.url,a.type);}catch{}return}{let a=null;try{let u=i.location();u&&u.url&&(a=`${u.url}:${u.lineNumber}:${u.columnNumber}`);}catch{}let d=r.mapConsoleType(p);this.consoleWriter&&(this.consoleWriter.append({level:d,text:c,timestamp:new Date().toISOString(),location:a}),this.consoleLogCount++);}}catch{}};if(this.page.on("console",n),this.listeners.push({event:"console",handler:n}),this.includeNetworkStats){let s=c=>{this.currentNetworkCounter&&this.currentNetworkCounter.totalRequests++;try{let a=c,d=String(this.requestIdCounter++),u=a.postData()??null,g={url:a.url(),method:a.method(),resourceType:this.mapResourceType(a.resourceType()),headers:a.headers(),postData:u,postDataTruncated:!1,startedAt:new Date().toISOString(),startTimeMs:Date.now()};this.pendingRequests.set(d,g),c.__testrelic_id=d;}catch{}};this.page.on("request",s),this.listeners.push({event:"request",handler:s});let i=c=>{try{let a=c;if(this.currentNetworkCounter){let f=a.status();f>=400&&(this.currentNetworkCounter.failedRequests++,this.currentNetworkCounter.failedRequestUrls.push(f+" "+a.url()));let h=a.headers()["content-length"];h&&(this.currentNetworkCounter.totalBytes+=parseInt(h,10)||0);let T=a.request().resourceType(),w=this.mapResourceType(T);this.currentNetworkCounter.byType[w]++;}let d=a.request().__testrelic_id;if(!d)return;let u=this.pendingRequests.get(d);if(!u)return;this.pendingRequests.delete(d);let g=Date.now()-u.startTimeMs,l=a.headers(),o=l["content-type"]??null,C=parseInt(l["content-length"]??"0",10)||0,y=o?!rt(o):!1,R=(async()=>{let f=null;if(!y)try{f=(await a.body()).toString("utf-8");}catch{}let h={url:u.url,method:u.method,resourceType:u.resourceType,statusCode:a.status(),responseTimeMs:g,startedAt:u.startedAt,requestHeaders:u.headers,requestBody:u.postData,responseBody:f,responseHeaders:l,contentType:o,responseSize:C,requestBodyTruncated:u.postDataTruncated,responseBodyTruncated:!1,isBinary:y,error:null};this.networkWriter&&(this.networkWriter.append(h),this.networkRequestCount++);})();this.pendingBodyReads.push(R);}catch{}};this.page.on("response",i),this.listeners.push({event:"response",handler:i});let p=c=>{if(this.currentNetworkCounter){this.currentNetworkCounter.failedRequests++;try{let a=c;this.currentNetworkCounter.failedRequestUrls.push("ERR "+a.url());}catch{}}try{let a=c,d=a.__testrelic_id;if(!d)return;let u=this.pendingRequests.get(d);if(!u)return;this.pendingRequests.delete(d);let g={url:u.url,method:u.method,resourceType:u.resourceType,statusCode:0,responseTimeMs:Date.now()-u.startTimeMs,startedAt:u.startedAt,requestHeaders:u.headers,requestBody:u.postData,responseBody:null,responseHeaders:null,contentType:null,responseSize:0,requestBodyTruncated:u.postDataTruncated,responseBodyTruncated:!1,isBinary:!1,error:a.failure()?.errorText??"Unknown error"};this.networkWriter&&(this.networkWriter.append(g),this.networkRequestCount++);}catch{}};this.page.on("requestfailed",p),this.listeners.push({event:"requestfailed",handler:p});}}async injectSPADetection(){try{await this.page.addInitScript(()=>{let t=history.pushState.bind(history),e=history.replaceState.bind(history);history.pushState=function(...n){t(...n),console.debug("__testrelic_nav:"+JSON.stringify({type:"spa_route",url:location.href}));},history.replaceState=function(...n){e(...n),console.debug("__testrelic_nav:"+JSON.stringify({type:"spa_replace",url:location.href}));},window.addEventListener("popstate",()=>{console.debug("__testrelic_nav:"+JSON.stringify({type:"popstate",url:location.href}));}),window.addEventListener("hashchange",()=>{console.debug("__testrelic_nav:"+JSON.stringify({type:"hash_change",url:location.href}));});});}catch{}}recordNavigation(t,e){this.includeNetworkStats&&this.currentNetworkCounter&&this.records.length>0&&(this.records[this.records.length-1].networkStats={totalRequests:this.currentNetworkCounter.totalRequests,failedRequests:this.currentNetworkCounter.failedRequests,failedRequestUrls:[...this.currentNetworkCounter.failedRequestUrls],totalBytes:this.currentNetworkCounter.totalBytes,byType:{...this.currentNetworkCounter.byType}}),this.records.push({url:t,navigationType:e,timestamp:new Date().toISOString()}),this.includeNetworkStats&&(this.currentNetworkCounter=this.createNetworkCounter());}createNetworkCounter(){return {totalRequests:0,failedRequests:0,failedRequestUrls:[],totalBytes:0,byType:{xhr:0,document:0,script:0,stylesheet:0,image:0,font:0,other:0}}}mapResourceType(t){switch(t){case "xhr":case "fetch":return "xhr";case "document":return "document";case "script":return "script";case "stylesheet":return "stylesheet";case "image":return "image";case "font":return "font";default:return "other"}}};var S=Symbol.for("__testrelic_call_id"),it="__testrelic_api_assertions",m=new WeakMap,v=class{constructor(){this.assertions=[];this.currentCallId=null;}recordAssertion(t){this.assertions.push(t);}getAssertions(){return this.assertions}setCurrentCallId(t){this.currentCallId=t;}getCurrentCallId(){return this.currentCallId}getData(){return [...this.assertions]}flushLegacyAnnotations(t){this.assertions.length!==0&&t.annotations.push({type:it,description:JSON.stringify(this.assertions)});}dispose(){this.assertions=[],this.currentCallId=null;}},M=new Map;function at(r){let t=M.get(r);if(t)return t;try{let e=r.startsWith("file://")?url.fileURLToPath(r):r,s=fs.readFileSync(e,"utf-8").split(`
3
- `);return M.set(r,s),s}catch{return null}}function ut(){let t=new Error().stack;if(!t)return null;let e=t.split(`
4
- `);for(let n of e){if(n.includes("/assertion-tracker.")||n.includes("/api-request-tracker.")||n.includes("node:internal")||n.includes(" at new Error")||n.includes(" at captureAssertionLocation")||n.includes(" at expectWrapper")||n.includes(" at wrappedMatcher"))continue;let s=n.match(/at\s+(?:.*?\s+\()?(.+?):(\d+):(\d+)\)?$/);if(s)return {file:s[1],line:parseInt(s[2],10),column:parseInt(s[3],10)}}return null}function ct(r,t){if(!r)return "custom";let e=r.toLowerCase();return e.includes(".status()")&&!e.includes(".statustext()")?e.includes(".ok()")?"statusOk":"status":e.includes(".ok()")?"statusOk":e.includes(".headers()")||e.includes(".headersarray()")?"header":e.includes("tomatchobject")||e.includes("toequal")?"bodyMatch":e.includes("tocontain")||e.includes("tostringcontaining")?"bodyContains":e.includes(".json()")||e.includes(".text()")?"bodyField":"custom"}function lt(r,t,e){let n=function(i,...p){let c=r(),a=t();if(!c||!a)return e(i,...p);let d=null;if(i!=null&&typeof i=="object"){let o=i[S];typeof o=="string"&&(d=o);}if(!d&&i!==null&&i!==void 0&&typeof i=="object"&&(d=m.get(i)??null),d||(d=a.getCallIdForValue(i)),d||(d=c.getCurrentCallId()),!d)return e(i,...p);let u=ut(),g;if(u){let o=at(u.file);o&&u.line>0&&u.line<=o.length&&(g=o[u.line-1].trim());}let l=e(i,...p);return d?J(l,{tracker:c,callId:d,received:i,location:u??{file:"unknown",line:0},expression:g}):l};for(let s of Object.keys(e))n[s]=e[s];return n}var j=null,H=null;function _(r,t){j=r,H=t;}function U(r){return lt(()=>j,()=>H,r)}function J(r,t){return new Proxy(r,{get(e,n,s){let i=Reflect.get(e,n,s);return typeof i!="function"||typeof n=="symbol"?i:n==="not"?J(i,t):function(...c){let a=c[0],d="passed",u=t.received,g=null;try{let l=i.apply(this??e,c);return l&&typeof l=="object"&&typeof l.then=="function"?l.then(()=>{x(t,n,a,u,"passed");},o=>{throw x(t,n,a,u,"failed"),o}):l}catch(l){if(d="failed",g=l,l instanceof Error&&l.message){let o=l.message.match(/Received:\s*(.+)/);o&&(u=o[1]);}throw l}finally{(g!==null||d==="passed")&&x(t,n,a,u,d);}}}})}function x(r,t,e,n,s){let i=ct(r.expression,r.received),p={callId:r.callId,type:i,expected:W(e),actual:W(n),status:s,location:r.location,expression:r.expression};r.tracker.recordAssertion(p);}function W(r){if(r==null||typeof r=="string"||typeof r=="number"||typeof r=="boolean")return r;try{return JSON.stringify(r),r}catch{return String(r)}}var G="[REDACTED]";function I(r,t){if(r===null||t.length===0)return r;let e=new Set(t.map(s=>s.toLowerCase())),n={};for(let s of Object.keys(r))Object.hasOwn(r,s)&&(n[s]=e.has(s.toLowerCase())?G:r[s]);return n}function b(r,t){if(r===null||t.length===0)return r;let e;try{e=JSON.parse(r);}catch{return r}if(typeof e!="object"||e===null)return r;let n=new Set(t),s=P(e,n);return JSON.stringify(s)}function P(r,t){if(Array.isArray(r))return r.map(e=>P(e,t));if(typeof r=="object"&&r!==null){let e={};for(let n of Object.keys(r)){if(!Object.hasOwn(r,n))continue;let s=r[n];t.has(n)?e[n]=G:e[n]=P(s,t);}return e}return r}function Y(r,t,e){if(e.length>0){for(let n of e)if($(r,n))return false}if(t.length>0){for(let n of t)if($(r,n))return true;return false}return true}function $(r,t){try{return t instanceof RegExp?t.test(r):dt(t).test(r)}catch{return console.warn(`[testrelic] Invalid URL filter pattern: ${String(t)}`),false}}function dt(r){let t="",e=0;for(;e<r.length;){let n=r[e];n==="*"&&r[e+1]==="*"?(t+=".*",e+=2,r[e]==="/"&&e++):n==="*"?(t+="[^/]*",e++):n==="?"?(t+="[^/]",e++):".+^${}()|[]\\".includes(n)?(t+="\\"+n,e++):(t+=n,e++);}return new RegExp(t)}var pt=["get","post","put","patch","delete","head","fetch"],gt=["text/","application/json","application/xml","application/javascript","application/x-www-form-urlencoded","application/graphql"];function ft(r){let t=r.toLowerCase();return gt.some(e=>t.includes(e))}function ht(r){if(!r)return null;if(r.data!==void 0&&r.data!==null){let t=r.data;return typeof t=="string"?t:Buffer.isBuffer(t)?t.toString("base64"):JSON.stringify(t)}if(r.form!==void 0&&r.form!==null)return JSON.stringify(r.form);if(r.multipart!==void 0&&r.multipart!==null){let t=r.multipart,e={};for(let[n,s]of Object.entries(t))typeof s=="string"||typeof s=="number"||typeof s=="boolean"?e[n]=String(s):s&&typeof s=="object"&&"name"in s?e[n]=`[file: ${s.name}]`:e[n]="[binary]";return JSON.stringify(e)}return null}var q=class q{constructor(t,e,n){this.originals=new Map;this.apiCallWriter=null;this.callCounter=0;this.apiCallCount=0;this.disposed=false;this._lastCallId=null;this.primitiveCallIds=new Map;this.context=t,this.assertionTracker=e??null,this.apiConfig=n??q.DEFAULT_API_CONFIG;try{this.apiCallWriter=new k("api-calls");}catch{}}get lastCallId(){return this._lastCallId}getCallIdForValue(t){return t!=null&&typeof t=="object"?m.get(t)??null:this.primitiveCallIds.get(t)??null}intercept(){for(let e of pt){let n=this.context[e].bind(this.context);this.originals.set(e,n),this.context[e]=this.createWrapper(e,n);}let t=this.context.dispose.bind(this.context);this.originals.set("dispose",t),this.context.dispose=async e=>(this.disposed=true,t(e));}getFileData(){return this.apiCallWriter?.close(),{apiCallsFile:this.apiCallWriter?.getCount()?this.apiCallWriter.getPath():null,apiCallsCount:this.apiCallWriter?.getCount()??0}}flushLegacyAnnotations(t){}dispose(){for(let[t,e]of this.originals)this.context[t]=e;this.originals.clear(),this.apiCallWriter?.close(),this.callCounter=0,this.apiCallCount=0,this._lastCallId=null,this.primitiveCallIds.clear();}get isDisposed(){return this.disposed}getCapturedCallCount(){return this.apiCallCount}tagResponseMethods(t,e){let n=this,s=t.headers.bind(t);t.headers=function(){let o=s();return m.set(o,e),o};let i=t.headersArray.bind(t);t.headersArray=function(){let o=i();return m.set(o,e),o};let p=t.json.bind(t);t.json=async function(){let o=await p();return o!=null&&typeof o=="object"&&m.set(o,e),o};let c=t.status.bind(t);t.status=function(){let o=c();return n.primitiveCallIds.set(o,e),o};let a=t.statusText.bind(t);t.statusText=function(){let o=a();return n.primitiveCallIds.set(o,e),o};let d=t.ok.bind(t);t.ok=function(){let o=d();return n.primitiveCallIds.set(o,e),o};let u=t.text.bind(t);t.text=async function(){let o=await u();return n.primitiveCallIds.set(o,e),o};let g=t.body.bind(t);t.body=async function(){let o=await g();return m.set(o,e),o};}createWrapper(t,e){let n=this;return async function(i,p){if(!Y(i,n.apiConfig.apiIncludeUrls,n.apiConfig.apiExcludeUrls))return e(i,p);let c=`api-call-${n.callCounter++}`,a=new Date().toISOString(),d=t==="fetch"?(p?.method??"GET").toUpperCase():t.toUpperCase(),u=ht(p),g=perf_hooks.performance.now();n._lastCallId=c,n.assertionTracker&&n.assertionTracker.setCurrentCallId(c);let l;try{l=await e(i,p);}catch(o){let C=perf_hooks.performance.now();try{let y=n.apiConfig.captureRequestBody?b(u,n.apiConfig.redactBodyFields):null,R={id:c,timestamp:a,method:d,url:i,requestHeaders:null,requestBody:y,responseStatusCode:null,responseStatusText:null,responseHeaders:null,responseBody:null,responseTimeMs:Math.round((C-g)*100)/100,isBinary:!1,error:o instanceof Error?o.message:String(o)};n.apiCallWriter&&(n.apiCallWriter.append(R),n.apiCallCount++);}catch{}throw o}try{let o=perf_hooks.performance.now(),C=l.headers(),y=C["content-type"]??null,R=y?!ft(y):!1,f=null;n.apiConfig.captureRequestHeaders&&p?.headers&&(f=p.headers);let h=null;n.apiConfig.captureResponseHeaders&&(h=C);let T=n.apiConfig.captureRequestBody?u:null,w=null;if(n.apiConfig.captureResponseBody)try{R?w=(await l.body()).toString("base64"):w=await l.text();}catch{}f=I(f,n.apiConfig.redactHeaders),h=I(h,n.apiConfig.redactHeaders),T=b(T,n.apiConfig.redactBodyFields),w=b(w,n.apiConfig.redactBodyFields);let z={id:c,timestamp:a,method:d,url:l.url(),requestHeaders:f,requestBody:T,responseStatusCode:l.status(),responseStatusText:l.statusText(),responseHeaders:h,responseBody:w,responseTimeMs:Math.round((o-g)*100)/100,isBinary:R,error:null};n.apiCallWriter&&(n.apiCallWriter.append(z),n.apiCallCount++);}catch{}try{l[S]=c,n.tagResponseMethods(l,c);}catch{}return l}}};q.DEFAULT_API_CONFIG=Object.freeze({trackApiCalls:true,captureRequestHeaders:true,captureResponseHeaders:true,captureRequestBody:true,captureResponseBody:true,captureAssertions:true,redactHeaders:["authorization","cookie","set-cookie","x-api-key"],redactBodyFields:["password","secret","token","apiKey","api_key"],apiIncludeUrls:[],apiExcludeUrls:[]});var N=q;var Vt=U(test.expect),kt="__testrelic_api_config",mt="__testrelic_config_trackApiCalls";function Ct(r){let t=r.annotations.find(n=>n.type===kt&&n.description!==void 0);if(t)try{return JSON.parse(t.description,Rt)}catch{}let e=r.annotations.find(n=>n.type===mt&&n.description!==void 0);return e?{trackApiCalls:e.description!=="false",captureRequestHeaders:true,captureResponseHeaders:true,captureRequestBody:true,captureResponseBody:true,captureAssertions:true,redactHeaders:["authorization","cookie","set-cookie","x-api-key"],redactBodyFields:["password","secret","token","apiKey","api_key"],apiIncludeUrls:[],apiExcludeUrls:[]}:{trackApiCalls:true,captureRequestHeaders:true,captureResponseHeaders:true,captureRequestBody:true,captureResponseBody:true,captureAssertions:true,redactHeaders:["authorization","cookie","set-cookie","x-api-key"],redactBodyFields:["password","secret","token","apiKey","api_key"],apiIncludeUrls:[],apiExcludeUrls:[]}}function Rt(r,t){if(typeof t=="object"&&t!==null&&t.__regexp===true&&typeof t.source=="string"){let{source:e,flags:n}=t;return new RegExp(e,n)}return t}var Tt={page:async({page:r},t,e)=>{let n=new A(r);try{await n.init();}catch{}await t(r);try{let{navigations:s,networkRequestsFile:i,networkRequestsCount:p,consoleLogsFile:c,consoleLogsCount:a}=await n.getFileData(),d={testRelicData:!0,version:core.PAYLOAD_VERSION,navigations:s,apiAssertions:[],networkRequestsFile:i,networkRequestsCount:p,consoleLogsFile:c,consoleLogsCount:a,apiCallsFile:null,apiCallsCount:0};await e.attach(core.ATTACHMENT_NAME,{body:Buffer.from(JSON.stringify(d)),contentType:core.ATTACHMENT_CONTENT_TYPE});}catch{}n.dispose();},request:async({request:r},t,e)=>{let n=Ct(e);if(!n.trackApiCalls){await t(r);return}let s=new v,i=new N(r,s,n);i.intercept(),_(s,i);try{await t(r);}finally{_(null,null);}try{let{apiCallsFile:p,apiCallsCount:c}=i.getFileData(),a=n.captureAssertions?s.getData():[],d={testRelicData:!0,version:core.PAYLOAD_VERSION,navigations:[],apiAssertions:a,networkRequestsFile:null,networkRequestsCount:0,consoleLogsFile:null,consoleLogsCount:0,apiCallsFile:p,apiCallsCount:c};await e.attach(core.ATTACHMENT_NAME,{body:Buffer.from(JSON.stringify(d)),contentType:core.ATTACHMENT_CONTENT_TYPE});}catch{}i.dispose(),s.dispose();}};async function Xt(r,t){let e=new A(r);try{await e.init();}catch{}return async()=>{try{let{navigations:n,networkRequestsFile:s,networkRequestsCount:i,consoleLogsFile:p,consoleLogsCount:c}=await e.getFileData(),a={testRelicData:!0,version:core.PAYLOAD_VERSION,navigations:n,apiAssertions:[],networkRequestsFile:s,networkRequestsCount:i,consoleLogsFile:p,consoleLogsCount:c,apiCallsFile:null,apiCallsCount:0};await t.attach(core.ATTACHMENT_NAME,{body:Buffer.from(JSON.stringify(a)),contentType:core.ATTACHMENT_CONTENT_TYPE});}catch{}e.dispose();}}var Qt=test.test.extend(Tt);exports.expect=Vt;exports.readApiConfig=Ct;exports.test=Qt;exports.testRelicFixture=Tt;exports.trackPage=Xt;//# sourceMappingURL=fixture.cjs.map
1
+ 'use strict';var test=require('@playwright/test'),fs=require('fs'),path=require('path'),os=require('os'),crypto=require('crypto');require('readline');var perf_hooks=require('perf_hooks'),url=require('url'),core=require('@testrelic/core');var E=path.join(os.tmpdir(),"testrelic-data"),m=class{constructor(t){this.count=0;this.closed=false;fs.mkdirSync(E,{recursive:true}),this.filePath=path.join(E,`${t}-${crypto.randomUUID().substring(0,8)}.jsonl`),this.fd=fs.openSync(this.filePath,"w");}append(t){if(this.closed)return;let e=JSON.stringify(t)+`
2
+ `;fs.writeSync(this.fd,e),this.count++;}getPath(){return this.filePath}getCount(){return this.count}close(){if(!this.closed){this.closed=true;try{fs.closeSync(this.fd);}catch{}}}cleanup(){try{fs.unlinkSync(this.filePath);}catch{}}};var nt=["text/","application/json","application/xml","application/javascript","application/x-www-form-urlencoded","application/graphql"];function rt(r){let t=r.toLowerCase();return nt.some(e=>t.includes(e))}var v=class r{constructor(t,e){this.page=t;this.records=[];this.listeners=[];this.navCounters=[];this.pendingRequests=new Map;this.networkWriter=null;this.consoleWriter=null;this.pendingBodyReads=[];this.requestIdCounter=0;this.networkRequestCount=0;this.consoleLogCount=0;this.includeNetworkStats=e?.includeNetworkStats??true,this.origGoto=t.goto.bind(t),this.origGoBack=t.goBack.bind(t),this.origGoForward=t.goForward.bind(t),this.origReload=t.reload.bind(t);try{this.includeNetworkStats&&(this.networkWriter=new m("network")),this.consoleWriter=new m("console");}catch{}this.interceptMethods(),this.attachListeners();}async init(){await this.injectSPADetection();}async finalizeCapturedRequests(){await Promise.allSettled(this.pendingBodyReads),this.pendingBodyReads=[];for(let[,t]of this.pendingRequests)this.networkWriter&&(this.networkWriter.append({url:t.url,method:t.method,resourceType:t.resourceType,statusCode:0,responseTimeMs:Date.now()-t.startTimeMs,startedAt:t.startedAt,requestHeaders:t.headers,requestBody:t.postData,responseBody:null,responseHeaders:null,contentType:null,responseSize:0,requestBodyTruncated:t.postDataTruncated,responseBodyTruncated:false,isBinary:false,error:"incomplete"}),this.networkRequestCount++);this.pendingRequests.clear(),this.networkWriter?.close(),this.consoleWriter?.close();}static mapConsoleType(t){switch(t){case "log":return "log";case "warning":return "warn";case "error":return "error";case "info":return "info";case "debug":return "debug";default:return "log"}}async getFileData(){this.assembleNetworkStats();let t=this.records.map(e=>({url:e.url,navigationType:e.navigationType,timestamp:e.timestamp,domContentLoadedAt:e.domContentLoadedAt,networkIdleAt:e.networkIdleAt,networkStats:e.networkStats}));return this.includeNetworkStats?await this.finalizeCapturedRequests():this.consoleWriter?.close(),{navigations:t,networkRequestsFile:this.networkWriter?.getCount()?this.networkWriter.getPath():null,networkRequestsCount:this.networkWriter?.getCount()??0,consoleLogsFile:this.consoleWriter?.getCount()?this.consoleWriter.getPath():null,consoleLogsCount:this.consoleWriter?.getCount()??0}}async flushLegacyAnnotations(t){}dispose(){this.page.goto=this.origGoto,this.page.goBack=this.origGoBack,this.page.goForward=this.origGoForward,this.page.reload=this.origReload;for(let{event:t,handler:e}of this.listeners)this.page.off(t,e);this.listeners=[],this.records=[],this.pendingRequests.clear(),this.pendingBodyReads=[],this.networkWriter?.close(),this.consoleWriter?.close();}getRecords(){return this.assembleNetworkStats(),this.records}interceptMethods(){let t=this,e=this.page;e.goto=async function(n,s){return t.recordNavigation(n,"goto"),t.origGoto(n,s)},e.goBack=async function(n){let s=await t.origGoBack(n);return t.recordNavigation(e.url(),"back"),s},e.goForward=async function(n){let s=await t.origGoForward(n);return t.recordNavigation(e.url(),"forward"),s},e.reload=async function(n){return t.recordNavigation(e.url(),"refresh"),t.origReload(n)};}attachListeners(){let t=()=>{this.lastDomContentLoaded=new Date().toISOString(),this.records.length>0&&(this.records[this.records.length-1].domContentLoadedAt=this.lastDomContentLoaded);};this.page.on("domcontentloaded",t),this.listeners.push({event:"domcontentloaded",handler:t});let e=s=>{try{let i=s;if(typeof i.parentFrame=="function"&&i.parentFrame()!==null)return;let p=i.url(),d=this.records[this.records.length-1];if(d&&Date.now()-new Date(d.timestamp).getTime()<50&&d.url===p)return;this.recordNavigation(p,"navigation");}catch{}};this.page.on("framenavigated",e),this.listeners.push({event:"framenavigated",handler:e});let n=s=>{try{let i=s,p=i.type(),d=i.text();if(p==="debug"&&d.startsWith("__testrelic_nav:")){try{let c=JSON.parse(d.slice(16));c.type&&c.url&&this.recordNavigation(c.url,c.type);}catch{}return}{let c=null;try{let u=i.location();u&&u.url&&(c=`${u.url}:${u.lineNumber}:${u.columnNumber}`);}catch{}let a=r.mapConsoleType(p);this.consoleWriter&&(this.consoleWriter.append({level:a,text:d,timestamp:new Date().toISOString(),location:c}),this.consoleLogCount++);}}catch{}};if(this.page.on("console",n),this.listeners.push({event:"console",handler:n}),this.includeNetworkStats){let s=d=>{let c=this.records.length-1,a=this.counterForNav(c);a&&a.totalRequests++;try{let u=d,g=String(this.requestIdCounter++),l=u.postData()??null,o={url:u.url(),method:u.method(),resourceType:this.mapResourceType(u.resourceType()),headers:u.headers(),postData:l,postDataTruncated:!1,startedAt:new Date().toISOString(),startTimeMs:Date.now(),navIndex:c};this.pendingRequests.set(g,o),d.__testrelic_id=g;}catch{}};this.page.on("request",s),this.listeners.push({event:"request",handler:s});let i=d=>{try{let c=d,a=c.request().__testrelic_id,u=a?this.pendingRequests.get(a):void 0,g=this.counterForNav(u?u.navIndex:this.records.length-1);if(g){let f=c.status();f>=400&&(g.failedRequests++,g.failedRequestUrls.push(f+" "+c.url()));let y=c.headers()["content-length"];y&&(g.totalBytes+=parseInt(y,10)||0);let w=c.request().resourceType(),S=this.mapResourceType(w);g.byType[S]++;}if(!a||!u)return;this.pendingRequests.delete(a);let l=Date.now()-u.startTimeMs,o=c.headers(),h=o["content-type"]??null,C=parseInt(o["content-length"]??"0",10)||0,k=h?!rt(h):!1,T=(async()=>{let f=null;if(!k)try{f=(await c.body()).toString("utf-8");}catch{}let y={url:u.url,method:u.method,resourceType:u.resourceType,statusCode:c.status(),responseTimeMs:l,startedAt:u.startedAt,requestHeaders:u.headers,requestBody:u.postData,responseBody:f,responseHeaders:o,contentType:h,responseSize:C,requestBodyTruncated:u.postDataTruncated,responseBodyTruncated:!1,isBinary:k,error:null};this.networkWriter&&(this.networkWriter.append(y),this.networkRequestCount++);})();this.pendingBodyReads.push(T);}catch{}};this.page.on("response",i),this.listeners.push({event:"response",handler:i});let p=d=>{let c=d.__testrelic_id,a=c?this.pendingRequests.get(c):void 0,u=this.counterForNav(a?a.navIndex:this.records.length-1);if(u){u.failedRequests++;try{let g=d;u.failedRequestUrls.push("ERR "+g.url());}catch{}}try{let g=d;if(!c||!a)return;this.pendingRequests.delete(c);let l={url:a.url,method:a.method,resourceType:a.resourceType,statusCode:0,responseTimeMs:Date.now()-a.startTimeMs,startedAt:a.startedAt,requestHeaders:a.headers,requestBody:a.postData,responseBody:null,responseHeaders:null,contentType:null,responseSize:0,requestBodyTruncated:a.postDataTruncated,responseBodyTruncated:!1,isBinary:!1,error:g.failure()?.errorText??"Unknown error"};this.networkWriter&&(this.networkWriter.append(l),this.networkRequestCount++);}catch{}};this.page.on("requestfailed",p),this.listeners.push({event:"requestfailed",handler:p});}}async injectSPADetection(){try{await this.page.addInitScript(()=>{let t=history.pushState.bind(history),e=history.replaceState.bind(history);history.pushState=function(...n){t(...n),console.debug("__testrelic_nav:"+JSON.stringify({type:"spa_route",url:location.href}));},history.replaceState=function(...n){e(...n),console.debug("__testrelic_nav:"+JSON.stringify({type:"spa_replace",url:location.href}));},window.addEventListener("popstate",()=>{console.debug("__testrelic_nav:"+JSON.stringify({type:"popstate",url:location.href}));}),window.addEventListener("hashchange",()=>{console.debug("__testrelic_nav:"+JSON.stringify({type:"hash_change",url:location.href}));});});}catch{}}recordNavigation(t,e){this.records.push({url:t,navigationType:e,timestamp:new Date().toISOString()}),this.includeNetworkStats&&this.navCounters.push(this.createNetworkCounter());}createNetworkCounter(){return {totalRequests:0,failedRequests:0,failedRequestUrls:[],totalBytes:0,byType:{xhr:0,document:0,script:0,stylesheet:0,image:0,font:0,other:0}}}counterForNav(t){return t>=0?this.navCounters[t]:void 0}assembleNetworkStats(){if(this.includeNetworkStats)for(let t=0;t<this.records.length;t++){let e=this.navCounters[t];e&&(this.records[t].networkStats={totalRequests:e.totalRequests,failedRequests:e.failedRequests,failedRequestUrls:[...e.failedRequestUrls],totalBytes:e.totalBytes,byType:{...e.byType}});}}mapResourceType(t){switch(t){case "xhr":case "fetch":return "xhr";case "document":return "document";case "script":return "script";case "stylesheet":return "stylesheet";case "image":return "image";case "font":return "font";default:return "other"}}};var I=Symbol.for("__testrelic_call_id"),it="__testrelic_api_assertions",R=new WeakMap,A=class{constructor(){this.assertions=[];this.currentCallId=null;}recordAssertion(t){this.assertions.push(t);}getAssertions(){return this.assertions}setCurrentCallId(t){this.currentCallId=t;}getCurrentCallId(){return this.currentCallId}getData(){return [...this.assertions]}flushLegacyAnnotations(t){this.assertions.length!==0&&t.annotations.push({type:it,description:JSON.stringify(this.assertions)});}dispose(){this.assertions=[],this.currentCallId=null;}},W=new Map;function at(r){let t=W.get(r);if(t)return t;try{let e=r.startsWith("file://")?url.fileURLToPath(r):r,s=fs.readFileSync(e,"utf-8").split(`
3
+ `);return W.set(r,s),s}catch{return null}}function ut(){let t=new Error().stack;if(!t)return null;let e=t.split(`
4
+ `);for(let n of e){if(n.includes("/assertion-tracker.")||n.includes("/api-request-tracker.")||n.includes("node:internal")||n.includes(" at new Error")||n.includes(" at captureAssertionLocation")||n.includes(" at expectWrapper")||n.includes(" at wrappedMatcher"))continue;let s=n.match(/at\s+(?:.*?\s+\()?(.+?):(\d+):(\d+)\)?$/);if(s)return {file:s[1],line:parseInt(s[2],10),column:parseInt(s[3],10)}}return null}function ct(r,t){if(!r)return "custom";let e=r.toLowerCase();return e.includes(".status()")&&!e.includes(".statustext()")?e.includes(".ok()")?"statusOk":"status":e.includes(".ok()")?"statusOk":e.includes(".headers()")||e.includes(".headersarray()")?"header":e.includes("tomatchobject")||e.includes("toequal")?"bodyMatch":e.includes("tocontain")||e.includes("tostringcontaining")?"bodyContains":e.includes(".json()")||e.includes(".text()")?"bodyField":"custom"}function lt(r,t,e){let n=function(i,...p){let d=r(),c=t();if(!d||!c)return e(i,...p);let a=null;if(i!=null&&typeof i=="object"){let o=i[I];typeof o=="string"&&(a=o);}if(!a&&i!==null&&i!==void 0&&typeof i=="object"&&(a=R.get(i)??null),a||(a=c.getCallIdForValue(i)),a||(a=d.getCurrentCallId()),!a)return e(i,...p);let u=ut(),g;if(u){let o=at(u.file);o&&u.line>0&&u.line<=o.length&&(g=o[u.line-1].trim());}let l=e(i,...p);return a?G(l,{tracker:d,callId:a,received:i,location:u??{file:"unknown",line:0},expression:g}):l};for(let s of Object.keys(e))n[s]=e[s];return n}var H=null,J=null;function _(r,t){H=r,J=t;}function U(r){return lt(()=>H,()=>J,r)}function G(r,t){return new Proxy(r,{get(e,n,s){let i=Reflect.get(e,n,s);return typeof i!="function"||typeof n=="symbol"?i:n==="not"?G(i,t):function(...d){let c=d[0],a="passed",u=t.received,g=null;try{let l=i.apply(this??e,d);return l&&typeof l=="object"&&typeof l.then=="function"?l.then(()=>{N(t,n,c,u,"passed");},o=>{throw N(t,n,c,u,"failed"),o}):l}catch(l){if(a="failed",g=l,l instanceof Error&&l.message){let o=l.message.match(/Received:\s*(.+)/);o&&(u=o[1]);}throw l}finally{(g!==null||a==="passed")&&N(t,n,c,u,a);}}}})}function N(r,t,e,n,s){let i=ct(r.expression,r.received),p={callId:r.callId,type:i,expected:j(e),actual:j(n),status:s,location:r.location,expression:r.expression};r.tracker.recordAssertion(p);}function j(r){if(r==null||typeof r=="string"||typeof r=="number"||typeof r=="boolean")return r;try{return JSON.stringify(r),r}catch{return String(r)}}var $="[REDACTED]";function B(r,t){if(r===null||t.length===0)return r;let e=new Set(t.map(s=>s.toLowerCase())),n={};for(let s of Object.keys(r))Object.hasOwn(r,s)&&(n[s]=e.has(s.toLowerCase())?$:r[s]);return n}function b(r,t){if(r===null||t.length===0)return r;let e;try{e=JSON.parse(r);}catch{return r}if(typeof e!="object"||e===null)return r;let n=new Set(t),s=P(e,n);return JSON.stringify(s)}function P(r,t){if(Array.isArray(r))return r.map(e=>P(e,t));if(typeof r=="object"&&r!==null){let e={};for(let n of Object.keys(r)){if(!Object.hasOwn(r,n))continue;let s=r[n];t.has(n)?e[n]=$:e[n]=P(s,t);}return e}return r}function z(r,t,e){if(e.length>0){for(let n of e)if(Y(r,n))return false}if(t.length>0){for(let n of t)if(Y(r,n))return true;return false}return true}function Y(r,t){try{return t instanceof RegExp?t.test(r):dt(t).test(r)}catch{return console.warn(`[testrelic] Invalid URL filter pattern: ${String(t)}`),false}}function dt(r){let t="",e=0;for(;e<r.length;){let n=r[e];n==="*"&&r[e+1]==="*"?(t+=".*",e+=2,r[e]==="/"&&e++):n==="*"?(t+="[^/]*",e++):n==="?"?(t+="[^/]",e++):".+^${}()|[]\\".includes(n)?(t+="\\"+n,e++):(t+=n,e++);}return new RegExp(t)}var pt=["get","post","put","patch","delete","head","fetch"],gt=["text/","application/json","application/xml","application/javascript","application/x-www-form-urlencoded","application/graphql"];function ft(r){let t=r.toLowerCase();return gt.some(e=>t.includes(e))}function ht(r){if(!r)return null;if(r.data!==void 0&&r.data!==null){let t=r.data;return typeof t=="string"?t:Buffer.isBuffer(t)?t.toString("base64"):JSON.stringify(t)}if(r.form!==void 0&&r.form!==null)return JSON.stringify(r.form);if(r.multipart!==void 0&&r.multipart!==null){let t=r.multipart,e={};for(let[n,s]of Object.entries(t))typeof s=="string"||typeof s=="number"||typeof s=="boolean"?e[n]=String(s):s&&typeof s=="object"&&"name"in s?e[n]=`[file: ${s.name}]`:e[n]="[binary]";return JSON.stringify(e)}return null}var x=class x{constructor(t,e,n){this.originals=new Map;this.apiCallWriter=null;this.callCounter=0;this.apiCallCount=0;this.disposed=false;this._lastCallId=null;this.primitiveCallIds=new Map;this.context=t,this.assertionTracker=e??null,this.apiConfig=n??x.DEFAULT_API_CONFIG;try{this.apiCallWriter=new m("api-calls");}catch{}}get lastCallId(){return this._lastCallId}getCallIdForValue(t){return t!=null&&typeof t=="object"?R.get(t)??null:this.primitiveCallIds.get(t)??null}intercept(){for(let e of pt){let n=this.context[e].bind(this.context);this.originals.set(e,n),this.context[e]=this.createWrapper(e,n);}let t=this.context.dispose.bind(this.context);this.originals.set("dispose",t),this.context.dispose=async e=>(this.disposed=true,t(e));}getFileData(){return this.apiCallWriter?.close(),{apiCallsFile:this.apiCallWriter?.getCount()?this.apiCallWriter.getPath():null,apiCallsCount:this.apiCallWriter?.getCount()??0}}flushLegacyAnnotations(t){}dispose(){for(let[t,e]of this.originals)this.context[t]=e;this.originals.clear(),this.apiCallWriter?.close(),this.callCounter=0,this.apiCallCount=0,this._lastCallId=null,this.primitiveCallIds.clear();}get isDisposed(){return this.disposed}getCapturedCallCount(){return this.apiCallCount}tagResponseMethods(t,e){let n=this,s=t.headers.bind(t);t.headers=function(){let o=s();return R.set(o,e),o};let i=t.headersArray.bind(t);t.headersArray=function(){let o=i();return R.set(o,e),o};let p=t.json.bind(t);t.json=async function(){let o=await p();return o!=null&&typeof o=="object"&&R.set(o,e),o};let d=t.status.bind(t);t.status=function(){let o=d();return n.primitiveCallIds.set(o,e),o};let c=t.statusText.bind(t);t.statusText=function(){let o=c();return n.primitiveCallIds.set(o,e),o};let a=t.ok.bind(t);t.ok=function(){let o=a();return n.primitiveCallIds.set(o,e),o};let u=t.text.bind(t);t.text=async function(){let o=await u();return n.primitiveCallIds.set(o,e),o};let g=t.body.bind(t);t.body=async function(){let o=await g();return R.set(o,e),o};}createWrapper(t,e){let n=this;return async function(i,p){if(!z(i,n.apiConfig.apiIncludeUrls,n.apiConfig.apiExcludeUrls))return e(i,p);let d=`api-call-${n.callCounter++}`,c=new Date().toISOString(),a=t==="fetch"?(p?.method??"GET").toUpperCase():t.toUpperCase(),u=ht(p),g=perf_hooks.performance.now();n._lastCallId=d,n.assertionTracker&&n.assertionTracker.setCurrentCallId(d);let l;try{l=await e(i,p);}catch(o){let h=perf_hooks.performance.now();try{let C=n.apiConfig.captureRequestBody?b(u,n.apiConfig.redactBodyFields):null,k={id:d,timestamp:c,method:a,url:i,requestHeaders:null,requestBody:C,responseStatusCode:null,responseStatusText:null,responseHeaders:null,responseBody:null,responseTimeMs:Math.round((h-g)*100)/100,isBinary:!1,error:o instanceof Error?o.message:String(o)};n.apiCallWriter&&(n.apiCallWriter.append(k),n.apiCallCount++);}catch{}throw o}try{let o=perf_hooks.performance.now(),h=l.headers(),C=h["content-type"]??null,k=C?!ft(C):!1,T=null;n.apiConfig.captureRequestHeaders&&p?.headers&&(T=p.headers);let f=null;n.apiConfig.captureResponseHeaders&&(f=h);let y=n.apiConfig.captureRequestBody?u:null,w=null;if(n.apiConfig.captureResponseBody)try{k?w=(await l.body()).toString("base64"):w=await l.text();}catch{}T=B(T,n.apiConfig.redactHeaders),f=B(f,n.apiConfig.redactHeaders),y=b(y,n.apiConfig.redactBodyFields),w=b(w,n.apiConfig.redactBodyFields);let S={id:d,timestamp:c,method:a,url:l.url(),requestHeaders:T,requestBody:y,responseStatusCode:l.status(),responseStatusText:l.statusText(),responseHeaders:f,responseBody:w,responseTimeMs:Math.round((o-g)*100)/100,isBinary:k,error:null};n.apiCallWriter&&(n.apiCallWriter.append(S),n.apiCallCount++);}catch{}try{l[I]=d,n.tagResponseMethods(l,d);}catch{}return l}}};x.DEFAULT_API_CONFIG=Object.freeze({trackApiCalls:true,captureRequestHeaders:true,captureResponseHeaders:true,captureRequestBody:true,captureResponseBody:true,captureAssertions:true,redactHeaders:["authorization","cookie","set-cookie","x-api-key"],redactBodyFields:["password","secret","token","apiKey","api_key"],apiIncludeUrls:[],apiExcludeUrls:[]});var q=x;var Vt=U(test.expect),kt="__testrelic_api_config",mt="__testrelic_config_trackApiCalls";function Rt(r){let t=r.annotations.find(n=>n.type===kt&&n.description!==void 0);if(t)try{return JSON.parse(t.description,Ct)}catch{}let e=r.annotations.find(n=>n.type===mt&&n.description!==void 0);return e?{trackApiCalls:e.description!=="false",captureRequestHeaders:true,captureResponseHeaders:true,captureRequestBody:true,captureResponseBody:true,captureAssertions:true,redactHeaders:["authorization","cookie","set-cookie","x-api-key"],redactBodyFields:["password","secret","token","apiKey","api_key"],apiIncludeUrls:[],apiExcludeUrls:[]}:{trackApiCalls:true,captureRequestHeaders:true,captureResponseHeaders:true,captureRequestBody:true,captureResponseBody:true,captureAssertions:true,redactHeaders:["authorization","cookie","set-cookie","x-api-key"],redactBodyFields:["password","secret","token","apiKey","api_key"],apiIncludeUrls:[],apiExcludeUrls:[]}}function Ct(r,t){if(typeof t=="object"&&t!==null&&t.__regexp===true&&typeof t.source=="string"){let{source:e,flags:n}=t;return new RegExp(e,n)}return t}var Tt={page:async({page:r},t,e)=>{let n=new v(r);try{await n.init();}catch{}await t(r);try{let{navigations:s,networkRequestsFile:i,networkRequestsCount:p,consoleLogsFile:d,consoleLogsCount:c}=await n.getFileData(),a={testRelicData:!0,version:core.PAYLOAD_VERSION,navigations:s,apiAssertions:[],networkRequestsFile:i,networkRequestsCount:p,consoleLogsFile:d,consoleLogsCount:c,apiCallsFile:null,apiCallsCount:0};await e.attach(core.ATTACHMENT_NAME,{body:Buffer.from(JSON.stringify(a)),contentType:core.ATTACHMENT_CONTENT_TYPE});}catch{}n.dispose();},request:async({request:r},t,e)=>{let n=Rt(e);if(!n.trackApiCalls){await t(r);return}let s=new A,i=new q(r,s,n);i.intercept(),_(s,i);try{await t(r);}finally{_(null,null);}try{let{apiCallsFile:p,apiCallsCount:d}=i.getFileData(),c=n.captureAssertions?s.getData():[],a={testRelicData:!0,version:core.PAYLOAD_VERSION,navigations:[],apiAssertions:c,networkRequestsFile:null,networkRequestsCount:0,consoleLogsFile:null,consoleLogsCount:0,apiCallsFile:p,apiCallsCount:d};await e.attach(core.ATTACHMENT_NAME,{body:Buffer.from(JSON.stringify(a)),contentType:core.ATTACHMENT_CONTENT_TYPE});}catch{}i.dispose(),s.dispose();}};async function Xt(r,t){let e=new v(r);try{await e.init();}catch{}return async()=>{try{let{navigations:n,networkRequestsFile:s,networkRequestsCount:i,consoleLogsFile:p,consoleLogsCount:d}=await e.getFileData(),c={testRelicData:!0,version:core.PAYLOAD_VERSION,navigations:n,apiAssertions:[],networkRequestsFile:s,networkRequestsCount:i,consoleLogsFile:p,consoleLogsCount:d,apiCallsFile:null,apiCallsCount:0};await t.attach(core.ATTACHMENT_NAME,{body:Buffer.from(JSON.stringify(c)),contentType:core.ATTACHMENT_CONTENT_TYPE});}catch{}e.dispose();}}var Qt=test.test.extend(Tt);exports.expect=Vt;exports.readApiConfig=Rt;exports.test=Qt;exports.testRelicFixture=Tt;exports.trackPage=Xt;//# sourceMappingURL=fixture.cjs.map
5
5
  //# sourceMappingURL=fixture.cjs.map