@testrelic/playwright-analytics 2.16.4-next.191 → 2.16.4-next.230

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.
@@ -1,3 +1,4 @@
1
+ import { T as TestRelicFixtureMarker } from './fixture-marker-Buz_DCfv.cjs';
1
2
  import * as _playwright_test from '@playwright/test';
2
3
  import { expect as expect$1 } from '@playwright/test';
3
4
  import './visual.cjs';
@@ -41,7 +42,10 @@ declare function readApiConfig(testInfo: {
41
42
  }): ResolvedApiConfig;
42
43
  /**
43
44
  * Playwright-compatible fixture object for extending `test.extend()`.
44
- * Provides `page` (with navigation tracking) and `request` (with API tracking).
45
+ * Provides `page` (with navigation tracking) and `request` (with API tracking),
46
+ * plus `_testrelicFixture`, an automatic fixture that marks every test as
47
+ * having run through TestRelic so the reporter can tell an unused `page` from
48
+ * a missing import (see fixture-marker.ts).
45
49
  *
46
50
  * @example
47
51
  * import { test as base } from '\@playwright/test';
@@ -55,6 +59,7 @@ declare const testRelicFixture: {
55
59
  request: ({ request }: {
56
60
  request: _playwright_test.APIRequestContext;
57
61
  }, use: (request: _playwright_test.APIRequestContext) => Promise<void>, testInfo: _playwright_test.TestInfo) => Promise<void>;
62
+ _testrelicFixture: TestRelicFixtureMarker;
58
63
  };
59
64
  /**
60
65
  * Track a manually-created page for network requests, console logs, and navigations.
package/dist/fixture.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { T as TestRelicFixtureMarker } from './fixture-marker-Buz_DCfv.js';
1
2
  import * as _playwright_test from '@playwright/test';
2
3
  import { expect as expect$1 } from '@playwright/test';
3
4
  import './visual.js';
@@ -41,7 +42,10 @@ declare function readApiConfig(testInfo: {
41
42
  }): ResolvedApiConfig;
42
43
  /**
43
44
  * Playwright-compatible fixture object for extending `test.extend()`.
44
- * Provides `page` (with navigation tracking) and `request` (with API tracking).
45
+ * Provides `page` (with navigation tracking) and `request` (with API tracking),
46
+ * plus `_testrelicFixture`, an automatic fixture that marks every test as
47
+ * having run through TestRelic so the reporter can tell an unused `page` from
48
+ * a missing import (see fixture-marker.ts).
45
49
  *
46
50
  * @example
47
51
  * import { test as base } from '\@playwright/test';
@@ -55,6 +59,7 @@ declare const testRelicFixture: {
55
59
  request: ({ request }: {
56
60
  request: _playwright_test.APIRequestContext;
57
61
  }, use: (request: _playwright_test.APIRequestContext) => Promise<void>, testInfo: _playwright_test.TestInfo) => Promise<void>;
62
+ _testrelicFixture: TestRelicFixtureMarker;
58
63
  };
59
64
  /**
60
65
  * Track a manually-created page for network requests, console logs, and navigations.
package/dist/fixture.js CHANGED
@@ -1,8 +1,8 @@
1
- import {expect,test}from'@playwright/test';import {statSync,writeFileSync,existsSync,mkdirSync,openSync,writeSync,closeSync,unlinkSync,readFileSync}from'fs';import {join,extname,basename,dirname}from'path';import {tmpdir}from'os';import {randomUUID}from'crypto';import'readline';import {performance}from'perf_hooks';import {fileURLToPath}from'url';import {PAYLOAD_VERSION,ATTACHMENT_NAME,ATTACHMENT_CONTENT_TYPE}from'@testrelic/core';var ct=join(tmpdir(),"testrelic-data"),D=class{constructor(t){this.count=0;this.closed=false;mkdirSync(ct,{recursive:true}),this.filePath=join(ct,`${t}-${randomUUID().substring(0,8)}.jsonl`),this.fd=openSync(this.filePath,"w");}append(t){if(this.closed)return;let n=JSON.stringify(t)+`
2
- `;writeSync(this.fd,n),this.count++;}getPath(){return this.filePath}getCount(){return this.count}close(){if(!this.closed){this.closed=true;try{closeSync(this.fd);}catch{}}}cleanup(){try{unlinkSync(this.filePath);}catch{}}};var $t=["text/","application/json","application/xml","application/javascript","application/x-www-form-urlencoded","application/graphql"];function Xt(e){let t=e.toLowerCase();return $t.some(n=>t.includes(n))}var _=class e{constructor(t,n){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=n?.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 D("network")),this.consoleWriter=new D("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(n=>({url:n.url,navigationType:n.navigationType,timestamp:n.timestamp,domContentLoadedAt:n.domContentLoadedAt,networkIdleAt:n.networkIdleAt,networkStats:n.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(){let t=e.asPatchable(this.page);t.goto=this.origGoto,t.goBack=this.origGoBack,t.goForward=this.origGoForward,t.reload=this.origReload;for(let{event:n,handler:r}of this.listeners)this.page.off(n,r);this.listeners=[],this.records=[],this.pendingRequests.clear(),this.pendingBodyReads=[],this.networkWriter?.close(),this.consoleWriter?.close();}getRecords(){return this.assembleNetworkStats(),this.records}static asPatchable(t){return t}interceptMethods(){let t=this.page,n=e.asPatchable(t);n.goto=async(r,o)=>(this.recordNavigation(r,"goto"),this.origGoto(r,o)),n.goBack=async r=>{let o=await this.origGoBack(r);return this.recordNavigation(t.url(),"back"),o},n.goForward=async r=>{let o=await this.origGoForward(r);return this.recordNavigation(t.url(),"forward"),o},n.reload=async r=>(this.recordNavigation(t.url(),"refresh"),this.origReload(r));}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 n=o=>{try{let s=o;if(typeof s.parentFrame=="function"&&s.parentFrame()!==null)return;let d=s.url(),l=this.records[this.records.length-1];if(l&&Date.now()-new Date(l.timestamp).getTime()<50&&l.url===d)return;this.recordNavigation(d,"navigation");}catch{}};this.page.on("framenavigated",n),this.listeners.push({event:"framenavigated",handler:n});let r=o=>{try{let s=o,d=s.type(),l=s.text();if(d==="debug"&&l.startsWith("__testrelic_nav:")){try{let u=JSON.parse(l.slice(16));u.type&&u.url&&this.recordNavigation(u.url,u.type);}catch{}return}{let u=null;try{let c=s.location();c&&c.url&&(u=`${c.url}:${c.lineNumber}:${c.columnNumber}`);}catch{}let f=e.mapConsoleType(d);this.consoleWriter&&(this.consoleWriter.append({level:f,text:l,timestamp:new Date().toISOString(),location:u}),this.consoleLogCount++);}}catch{}};if(this.page.on("console",r),this.listeners.push({event:"console",handler:r}),this.includeNetworkStats){let o=l=>{let u=this.records.length-1,f=this.counterForNav(u);f&&f.totalRequests++;try{let c=l,i=String(this.requestIdCounter++),a=c.postData()??null,p={url:c.url(),method:c.method(),resourceType:this.mapResourceType(c.resourceType()),headers:c.headers(),postData:a,postDataTruncated:!1,startedAt:new Date().toISOString(),startTimeMs:Date.now(),navIndex:u};this.pendingRequests.set(i,p),l.__testrelic_id=i;}catch{}};this.page.on("request",o),this.listeners.push({event:"request",handler:o});let s=l=>{try{let u=l,f=u.request().__testrelic_id,c=f?this.pendingRequests.get(f):void 0,i=this.counterForNav(c?c.navIndex:this.records.length-1);if(i){let b=u.status();b>=400&&(i.failedRequests++,i.failedRequestUrls.push(b+" "+u.url()));let C=u.headers()["content-length"];C&&(i.totalBytes+=parseInt(C,10)||0);let A=u.request().resourceType(),v=this.mapResourceType(A);i.byType[v]++;}if(!f||!c)return;this.pendingRequests.delete(f);let a=Date.now()-c.startTimeMs,p=u.headers(),g=p["content-type"]??null,h=parseInt(p["content-length"]??"0",10)||0,w=g?!Xt(g):!1,k=(async()=>{let b=null;if(!w)try{b=(await u.body()).toString("utf-8");}catch{}let C={url:c.url,method:c.method,resourceType:c.resourceType,statusCode:u.status(),responseTimeMs:a,startedAt:c.startedAt,requestHeaders:c.headers,requestBody:c.postData,responseBody:b,responseHeaders:p,contentType:g,responseSize:h,requestBodyTruncated:c.postDataTruncated,responseBodyTruncated:!1,isBinary:w,error:null};this.networkWriter&&(this.networkWriter.append(C),this.networkRequestCount++);})();this.pendingBodyReads.push(k);}catch{}};this.page.on("response",s),this.listeners.push({event:"response",handler:s});let d=l=>{let u=l.__testrelic_id,f=u?this.pendingRequests.get(u):void 0,c=this.counterForNav(f?f.navIndex:this.records.length-1);if(c){c.failedRequests++;try{let i=l;c.failedRequestUrls.push("ERR "+i.url());}catch{}}try{let i=l;if(!u||!f)return;this.pendingRequests.delete(u);let a={url:f.url,method:f.method,resourceType:f.resourceType,statusCode:0,responseTimeMs:Date.now()-f.startTimeMs,startedAt:f.startedAt,requestHeaders:f.headers,requestBody:f.postData,responseBody:null,responseHeaders:null,contentType:null,responseSize:0,requestBodyTruncated:f.postDataTruncated,responseBodyTruncated:!1,isBinary:!1,error:i.failure()?.errorText??"Unknown error"};this.networkWriter&&(this.networkWriter.append(a),this.networkRequestCount++);}catch{}};this.page.on("requestfailed",d),this.listeners.push({event:"requestfailed",handler:d});}}async injectSPADetection(){try{await this.page.addInitScript(()=>{let t=history.pushState.bind(history),n=history.replaceState.bind(history);history.pushState=function(...r){t(...r),console.debug("__testrelic_nav:"+JSON.stringify({type:"spa_route",url:location.href}));},history.replaceState=function(...r){n(...r),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,n){this.records.push({url:t,navigationType:n,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 n=this.navCounters[t];n&&(this.records[t].networkStats={totalRequests:n.totalRequests,failedRequests:n.failedRequests,failedRequestUrls:[...n.failedRequestUrls],totalBytes:n.totalBytes,byType:{...n.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 Yt=new RegExp("[\x1B\x9B][[\\]()#;?]*(?:\\d{1,4}(?:;\\d{0,4})*)?[0-9A-PR-TZcf-nqry=><]","g");function dt(e){return !e||e.indexOf("\x1B")===-1&&e.indexOf("\x9B")===-1?e:e.replace(Yt,"")}var U=Symbol.for("__testrelic_call_id"),Zt="__testrelic_api_assertions",N=new WeakMap,I=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:Zt,description:JSON.stringify(this.assertions)});}dispose(){this.assertions=[],this.currentCallId=null;}},pt=new Map;function Qt(e){let t=pt.get(e);if(t)return t;try{let n=e.startsWith("file://")?fileURLToPath(e):e,o=readFileSync(n,"utf-8").split(`
1
+ import {expect,test}from'@playwright/test';import {statSync,writeFileSync,existsSync,mkdirSync,openSync,writeSync,closeSync,unlinkSync,readFileSync}from'fs';import {join,extname,basename,dirname}from'path';import {tmpdir}from'os';import {randomUUID}from'crypto';import'readline';import {performance}from'perf_hooks';import {fileURLToPath}from'url';import {PAYLOAD_VERSION,ATTACHMENT_NAME,ATTACHMENT_CONTENT_TYPE}from'@testrelic/core';var ct=join(tmpdir(),"testrelic-data"),N=class{constructor(t){this.count=0;this.closed=false;mkdirSync(ct,{recursive:true}),this.filePath=join(ct,`${t}-${randomUUID().substring(0,8)}.jsonl`),this.fd=openSync(this.filePath,"w");}append(t){if(this.closed)return;let n=JSON.stringify(t)+`
2
+ `;writeSync(this.fd,n),this.count++;}getPath(){return this.filePath}getCount(){return this.count}close(){if(!this.closed){this.closed=true;try{closeSync(this.fd);}catch{}}}cleanup(){try{unlinkSync(this.filePath);}catch{}}};var Xt=["text/","application/json","application/xml","application/javascript","application/x-www-form-urlencoded","application/graphql"];function Yt(e){let t=e.toLowerCase();return Xt.some(n=>t.includes(n))}var B=class e{constructor(t,n){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=n?.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 N("network")),this.consoleWriter=new N("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(n=>({url:n.url,navigationType:n.navigationType,timestamp:n.timestamp,domContentLoadedAt:n.domContentLoadedAt,networkIdleAt:n.networkIdleAt,networkStats:n.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(){let t=e.asPatchable(this.page);t.goto=this.origGoto,t.goBack=this.origGoBack,t.goForward=this.origGoForward,t.reload=this.origReload;for(let{event:n,handler:r}of this.listeners)this.page.off(n,r);this.listeners=[],this.records=[],this.pendingRequests.clear(),this.pendingBodyReads=[],this.networkWriter?.close(),this.consoleWriter?.close();}getRecords(){return this.assembleNetworkStats(),this.records}static asPatchable(t){return t}interceptMethods(){let t=this.page,n=e.asPatchable(t);n.goto=async(r,o)=>(this.recordNavigation(r,"goto"),this.origGoto(r,o)),n.goBack=async r=>{let o=await this.origGoBack(r);return this.recordNavigation(t.url(),"back"),o},n.goForward=async r=>{let o=await this.origGoForward(r);return this.recordNavigation(t.url(),"forward"),o},n.reload=async r=>(this.recordNavigation(t.url(),"refresh"),this.origReload(r));}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 n=o=>{try{let s=o;if(typeof s.parentFrame=="function"&&s.parentFrame()!==null)return;let d=s.url(),l=this.records[this.records.length-1];if(l&&Date.now()-new Date(l.timestamp).getTime()<50&&l.url===d)return;this.recordNavigation(d,"navigation");}catch{}};this.page.on("framenavigated",n),this.listeners.push({event:"framenavigated",handler:n});let r=o=>{try{let s=o,d=s.type(),l=s.text();if(d==="debug"&&l.startsWith("__testrelic_nav:")){try{let u=JSON.parse(l.slice(16));u.type&&u.url&&this.recordNavigation(u.url,u.type);}catch{}return}{let u=null;try{let c=s.location();c&&c.url&&(u=`${c.url}:${c.lineNumber}:${c.columnNumber}`);}catch{}let f=e.mapConsoleType(d);this.consoleWriter&&(this.consoleWriter.append({level:f,text:l,timestamp:new Date().toISOString(),location:u}),this.consoleLogCount++);}}catch{}};if(this.page.on("console",r),this.listeners.push({event:"console",handler:r}),this.includeNetworkStats){let o=l=>{let u=this.records.length-1,f=this.counterForNav(u);f&&f.totalRequests++;try{let c=l,i=String(this.requestIdCounter++),a=c.postData()??null,p={url:c.url(),method:c.method(),resourceType:this.mapResourceType(c.resourceType()),headers:c.headers(),postData:a,postDataTruncated:!1,startedAt:new Date().toISOString(),startTimeMs:Date.now(),navIndex:u};this.pendingRequests.set(i,p),l.__testrelic_id=i;}catch{}};this.page.on("request",o),this.listeners.push({event:"request",handler:o});let s=l=>{try{let u=l,f=u.request().__testrelic_id,c=f?this.pendingRequests.get(f):void 0,i=this.counterForNav(c?c.navIndex:this.records.length-1);if(i){let b=u.status();b>=400&&(i.failedRequests++,i.failedRequestUrls.push(b+" "+u.url()));let C=u.headers()["content-length"];C&&(i.totalBytes+=parseInt(C,10)||0);let A=u.request().resourceType(),v=this.mapResourceType(A);i.byType[v]++;}if(!f||!c)return;this.pendingRequests.delete(f);let a=Date.now()-c.startTimeMs,p=u.headers(),g=p["content-type"]??null,h=parseInt(p["content-length"]??"0",10)||0,w=g?!Yt(g):!1,k=(async()=>{let b=null;if(!w)try{b=(await u.body()).toString("utf-8");}catch{}let C={url:c.url,method:c.method,resourceType:c.resourceType,statusCode:u.status(),responseTimeMs:a,startedAt:c.startedAt,requestHeaders:c.headers,requestBody:c.postData,responseBody:b,responseHeaders:p,contentType:g,responseSize:h,requestBodyTruncated:c.postDataTruncated,responseBodyTruncated:!1,isBinary:w,error:null};this.networkWriter&&(this.networkWriter.append(C),this.networkRequestCount++);})();this.pendingBodyReads.push(k);}catch{}};this.page.on("response",s),this.listeners.push({event:"response",handler:s});let d=l=>{let u=l.__testrelic_id,f=u?this.pendingRequests.get(u):void 0,c=this.counterForNav(f?f.navIndex:this.records.length-1);if(c){c.failedRequests++;try{let i=l;c.failedRequestUrls.push("ERR "+i.url());}catch{}}try{let i=l;if(!u||!f)return;this.pendingRequests.delete(u);let a={url:f.url,method:f.method,resourceType:f.resourceType,statusCode:0,responseTimeMs:Date.now()-f.startTimeMs,startedAt:f.startedAt,requestHeaders:f.headers,requestBody:f.postData,responseBody:null,responseHeaders:null,contentType:null,responseSize:0,requestBodyTruncated:f.postDataTruncated,responseBodyTruncated:!1,isBinary:!1,error:i.failure()?.errorText??"Unknown error"};this.networkWriter&&(this.networkWriter.append(a),this.networkRequestCount++);}catch{}};this.page.on("requestfailed",d),this.listeners.push({event:"requestfailed",handler:d});}}async injectSPADetection(){try{await this.page.addInitScript(()=>{let t=history.pushState.bind(history),n=history.replaceState.bind(history);history.pushState=function(...r){t(...r),console.debug("__testrelic_nav:"+JSON.stringify({type:"spa_route",url:location.href}));},history.replaceState=function(...r){n(...r),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,n){this.records.push({url:t,navigationType:n,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 n=this.navCounters[t];n&&(this.records[t].networkStats={totalRequests:n.totalRequests,failedRequests:n.failedRequests,failedRequestUrls:[...n.failedRequestUrls],totalBytes:n.totalBytes,byType:{...n.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 Kt=new RegExp("[\x1B\x9B][[\\]()#;?]*(?:\\d{1,4}(?:;\\d{0,4})*)?[0-9A-PR-TZcf-nqry=><]","g");function dt(e){return !e||e.indexOf("\x1B")===-1&&e.indexOf("\x9B")===-1?e:e.replace(Kt,"")}var U=Symbol.for("__testrelic_call_id"),Qt="__testrelic_api_assertions",D=new WeakMap,E=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:Qt,description:JSON.stringify(this.assertions)});}dispose(){this.assertions=[],this.currentCallId=null;}},pt=new Map;function te(e){let t=pt.get(e);if(t)return t;try{let n=e.startsWith("file://")?fileURLToPath(e):e,o=readFileSync(n,"utf-8").split(`
3
3
  `);return pt.set(e,o),o}catch{return null}}var ft=(()=>{let e=new Error().stack;if(!e)return null;for(let t of e.split(`
4
- `)){let n=t.match(/at\s+(?:.*?\s+\()?(.+?):\d+:\d+\)?$/);if(!n||n[1].startsWith("node:"))continue;let r=Math.max(n[1].lastIndexOf("/"),n[1].lastIndexOf("\\"));return r>0?n[1].slice(0,r+1):null}return null})();function te(e){if(!e.startsWith("file:"))return e;try{return fileURLToPath(e)}catch{return e}}function ee(){let t=new Error().stack;if(!t)return null;let n=t.split(`
5
- `);return gt(n,true)??gt(n,false)}function gt(e,t){for(let n of e){if(t&&ft!==null&&n.includes(ft)||n.includes("node_modules")||n.includes("node:internal")||n.includes(" at new Error")||n.includes(" at captureAssertionLocation")||n.includes(" at findFrame")||n.includes(" at expectWrapper")||n.includes(" at wrappedMatcher"))continue;let r=n.match(/at\s+(?:.*?\s+\()?(.+?):(\d+):(\d+)\)?$/);if(r)return {file:te(r[1]),line:parseInt(r[2],10),column:parseInt(r[3],10)}}return null}function ne(e,t){if(!e)return "custom";let n=e.toLowerCase();return n.includes(".status()")&&!n.includes(".statustext()")?n.includes(".ok()")?"statusOk":"status":n.includes(".ok()")?"statusOk":n.includes(".headers()")||n.includes(".headersarray()")?"header":n.includes("tomatchobject")||n.includes("toequal")?"bodyMatch":n.includes("tocontain")||n.includes("tostringcontaining")?"bodyContains":n.includes(".json()")||n.includes(".text()")?"bodyField":"custom"}function re(e,t,n){let r=function(l,...u){let f=e(),c=t();if(!f||!c)return n(l,...u);let i=null;if(l!=null&&typeof l=="object"){let h=l[U];typeof h=="string"&&(i=h);}if(!i&&l!==null&&l!==void 0&&typeof l=="object"&&(i=N.get(l)??null),i||(i=c.getCallIdForValue(l)),i||(i=f.getCurrentCallId()),!i)return n(l,...u);let a=ee(),p;if(a){let h=Qt(a.file);h&&a.line>0&&a.line<=h.length&&(p=h[a.line-1].trim());}let g=n(l,...u);return i?kt(g,{tracker:f,callId:i,received:l,location:a??{file:"unknown",line:0},expression:p}):g},o=n,s=r;for(let d of Object.keys(o))s[d]=o[d];return r}var ht=Symbol.for("testrelic.activeAssertionContext");function V(){let e=globalThis,t=e[ht];return t||(t={tracker:null,apiTracker:null},e[ht]=t),t}function z(e,t){let n=V();n.tracker=e,n.apiTracker=t;}function wt(e){return re(()=>V().tracker,()=>V().apiTracker,e)}function kt(e,t){return new Proxy(e,{get(n,r,o){let s=Reflect.get(n,r,o);return typeof s!="function"||typeof r=="symbol"?s:r==="not"?kt(s,t):function(...l){let u=l[0],f="passed",c=t.received,i=null;try{let a=s.apply(this??n,l);return a&&typeof a=="object"&&typeof a.then=="function"?a.then(()=>{W(t,r,u,c,"passed");},p=>{throw W(t,r,u,c,"failed"),p}):a}catch(a){if(f="failed",i=a,a instanceof Error&&a.message){let p=a.message.match(/Received:\s*(.+)/);p&&(c=p[1]);}throw a}finally{(i!==null||f==="passed")&&W(t,r,u,c,f);}}}})}function W(e,t,n,r,o){let s=ne(e.expression,e.received),d={callId:e.callId,type:s,expected:mt(n),actual:mt(r),status:o,location:e.location,expression:e.expression};e.tracker.recordAssertion(d);}function mt(e){if(e==null)return e;if(typeof e=="string")return dt(e);if(typeof e=="number"||typeof e=="boolean")return e;try{return JSON.stringify(e),e}catch{return String(e)}}var bt="[REDACTED]";function J(e,t){if(e===null||t.length===0)return e;let n=new Set(t.map(o=>o.toLowerCase())),r={};for(let o of Object.keys(e))Object.prototype.hasOwnProperty.call(e,o)&&(r[o]=n.has(o.toLowerCase())?bt:e[o]);return r}function E(e,t){if(e===null||t.length===0)return e;let n;try{n=JSON.parse(e);}catch{return e}if(typeof n!="object"||n===null)return e;let r=new Set(t.map(s=>s.toLowerCase())),o=G(n,r);return JSON.stringify(o)}function G(e,t){if(Array.isArray(e))return e.map(n=>G(n,t));if(typeof e=="object"&&e!==null){let n={};for(let r of Object.keys(e)){if(!Object.prototype.hasOwnProperty.call(e,r))continue;let o=e[r];t.has(r.toLowerCase())?n[r]=bt:n[r]=G(o,t);}return n}return e}var oe=new Set(["access_token","api_key","token","sig"]);function $(e){if(!e)return e;let t;try{t=new URL(e);}catch{return e}let n=false;for(let r of [...t.searchParams.keys()])oe.has(r.toLowerCase())&&(t.searchParams.delete(r),n=true);return n?t.toString():e}function Ct(e,t,n){if(n.length>0){for(let r of n)if(xt(e,r))return false}if(t.length>0){for(let r of t)if(xt(e,r))return true;return false}return true}function xt(e,t){try{return t instanceof RegExp?t.test(e):se(t).test(e)}catch{return process.stderr.write(`[testrelic] Invalid URL filter pattern: ${String(t)}
6
- `),false}}function se(e){let t="",n=0;for(;n<e.length;){let r=e[n];r==="*"&&e[n+1]==="*"?(t+=".*",n+=2,e[n]==="/"&&n++):r==="*"?(t+="[^/]*",n++):r==="?"?(t+="[^/]",n++):".+^${}()|[]\\".includes(r)?(t+="\\"+r,n++):(t+=r,n++);}return new RegExp(t)}var ie=["get","post","put","patch","delete","head","fetch"],ae=["text/","application/json","application/xml","application/javascript","application/x-www-form-urlencoded","application/graphql"];function ue(e){let t=e.toLowerCase();return ae.some(n=>t.includes(n))}function ce(e){if(!e)return null;if(e.data!==void 0&&e.data!==null){let t=e.data;return typeof t=="string"?t:Buffer.isBuffer(t)?t.toString("base64"):JSON.stringify(t)}if(e.form!==void 0&&e.form!==null)return JSON.stringify(e.form);if(e.multipart!==void 0&&e.multipart!==null){let t=e.multipart,n={};for(let[r,o]of Object.entries(t))typeof o=="string"||typeof o=="number"||typeof o=="boolean"?n[r]=String(o):o&&typeof o=="object"&&"name"in o?n[r]=`[file: ${o.name}]`:n[r]="[binary]";return JSON.stringify(n)}return null}function Rt(e){return e?"\u2022\u2022\u2022\u2022":""}function le(e){if(!e)return [];let t;for(let[r,o]of Object.entries(e))if(r.toLowerCase()==="cookie"){t=o;break}if(!t)return [];let n=[];for(let r of t.split(";")){let o=r.trim();if(!o)continue;let s=o.indexOf("="),d=s===-1?o:o.slice(0,s).trim(),l=s===-1?"":o.slice(s+1).trim();d&&n.push({name:d,value:Rt(l)});}return n}function de(e){let t=[];for(let n of e)for(let r of n.split(/,(?=\s*[A-Za-z0-9_.-]+=)/)){let o=r.trim();if(!o)continue;let s=o.split(";"),d=s[0].indexOf("=");if(d===-1)continue;let l=s[0].slice(0,d).trim(),u=s[0].slice(d+1).trim(),f=s.slice(1).map(c=>c.trim()).filter(Boolean).join(" \xB7 ")||void 0;l&&t.push({name:l,value:Rt(u),attributes:f});}return t}var L=class L{constructor(t,n,r){this.originals=new Map;this.apiCallWriter=null;this.statusMix={"2xx":0,"3xx":0,"4xx":0,"5xx":0,error:0};this.callCounter=0;this.apiCallCount=0;this.disposed=false;this._lastCallId=null;this.primitiveCallIds=new Map;this.context=t,this.assertionTracker=n??null,this.apiConfig=r??L.DEFAULT_API_CONFIG;try{this.apiCallWriter=new D("api-calls");}catch{}}get lastCallId(){return this._lastCallId}getCallIdForValue(t){return t!=null&&typeof t=="object"?N.get(t)??null:this.primitiveCallIds.get(t)??null}intercept(){for(let n of ie){let r=this.context[n].bind(this.context);this.originals.set(n,r),this.context[n]=this.createWrapper(n,r);}let t=this.context.dispose.bind(this.context);this.originals.set("dispose",t),this.context.dispose=async n=>(this.disposed=true,t(n));}tallyStatus(t){if(t===null||t<=0){this.statusMix.error++;return}if(t>=500){this.statusMix["5xx"]++;return}if(t>=400){this.statusMix["4xx"]++;return}if(t>=300){this.statusMix["3xx"]++;return}if(t>=200){this.statusMix["2xx"]++;return}this.statusMix.error++;}getFileData(){return this.apiCallWriter?.close(),{apiCallsFile:this.apiCallWriter?.getCount()?this.apiCallWriter.getPath():null,apiCallsCount:this.apiCallWriter?.getCount()??0,apiStatusMix:{...this.statusMix}}}flushLegacyAnnotations(t){}dispose(){for(let[t,n]of this.originals)this.context[t]=n;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,n){let{primitiveCallIds:r}=this,o=t.headers.bind(t);t.headers=function(){let p=o();return N.set(p,n),p};let s=t.headersArray.bind(t);t.headersArray=function(){let p=s();return N.set(p,n),p};let d=t.json.bind(t);t.json=async function(){let p=await d();return p!=null&&typeof p=="object"&&N.set(p,n),p};let l=t.status.bind(t);t.status=function(){let p=l();return r.set(p,n),p};let u=t.statusText.bind(t);t.statusText=function(){let p=u();return r.set(p,n),p};let f=t.ok.bind(t);t.ok=function(){let p=f();return r.set(p,n),p};let c=t.text.bind(t);t.text=async function(){let p=await c();return r.set(p,n),p};let i=t.body.bind(t);t.body=async function(){let p=await i();return N.set(p,n),p};}createWrapper(t,n){return async(r,o)=>{if(!Ct(r,this.apiConfig.apiIncludeUrls,this.apiConfig.apiExcludeUrls))return n(r,o);let s=`api-call-${this.callCounter++}`,d=new Date().toISOString(),l=t==="fetch"?(o?.method??"GET").toUpperCase():t.toUpperCase(),u=ce(o),f=performance.now();this._lastCallId=s,this.assertionTracker&&this.assertionTracker.setCurrentCallId(s);let c;try{c=await n(r,o);}catch(i){let a=performance.now();try{let p=this.apiConfig.captureRequestBody?E(u,this.apiConfig.redactBodyFields):null,g={id:s,timestamp:d,method:l,url:$(r),requestHeaders:null,requestBody:p,responseStatusCode:null,responseStatusText:null,responseHeaders:null,responseBody:null,responseTimeMs:Math.round((a-f)*100)/100,isBinary:!1,error:i instanceof Error?i.message:String(i)};this.apiCallWriter&&(this.apiCallWriter.append(g),this.apiCallCount++,this.tallyStatus(null));}catch{}throw i}try{let i=performance.now(),a=c.headers(),p=a["content-type"]??null,g=p?!ue(p):!1,h=null;this.apiConfig.captureRequestHeaders&&o?.headers&&(h=o.headers);let w=null;this.apiConfig.captureResponseHeaders&&(w=a);let k=this.apiConfig.captureRequestBody?u:null,b=null;if(this.apiConfig.captureResponseBody)try{g?b=(await c.body()).toString("base64"):b=await c.text();}catch{}let C=[],A=[];try{if(this.apiConfig.captureRequestHeaders&&(C=le(o?.headers)),this.apiConfig.captureResponseHeaders){let P=c.headersArray().filter(y=>y.name.toLowerCase()==="set-cookie").map(y=>y.value);A=de(P);}}catch{}h=J(h,this.apiConfig.redactHeaders),w=J(w,this.apiConfig.redactHeaders),k=E(k,this.apiConfig.redactBodyFields),b=E(b,this.apiConfig.redactBodyFields);let v={id:s,timestamp:d,method:l,url:$(c.url()),requestHeaders:h,requestBody:k,responseStatusCode:c.status(),responseStatusText:c.statusText(),responseHeaders:w,responseBody:b,requestCookies:C.length?C:null,responseCookies:A.length?A:null,responseTimeMs:Math.round((i-f)*100)/100,isBinary:g,error:null};this.apiCallWriter&&(this.apiCallWriter.append(v),this.apiCallCount++,this.tallyStatus(v.responseStatusCode));}catch{}try{c[U]=s,this.tagResponseMethods(c,s);}catch{}return c}}};L.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 O=L;Buffer.from([137,80,78,71,13,10,26,10]);function St(e){let{styleProps:t,defaults:n,inherited:r,maxNodes:o,maxText:s,maskBoxes:d,viewportBox:l,fullPage:u}=e,f={};for(let y=0;y<r.length;y++)f[r[y]]=true;let c=window.scrollX||window.pageXOffset||0,i=window.scrollY||window.pageYOffset||0,a=[],p=0,g=[];for(let y=0;y<d.length;y++){let m=d[y];g.push([m[0]+c,m[1]+i,m[2],m[3]]);}function h(y,m,R,T){for(let x=0;x<g.length;x++){let S=g[x];if(y<S[0]+S[2]&&y+R>S[0]&&m<S[1]+S[3]&&m+T>S[1])return true}return false}function w(y){let m=y.parentElement;if(!m)return 0;let R=m.children,T=0;for(let x=0;x<R.length;x++){let S=R[x];if(S===y)break;S.tagName===y.tagName&&T++;}return T}function k(y){let m="",R=y.childNodes;for(let T=0;T<R.length;T++){let x=R[T];x.nodeType===3&&(m+=x.nodeValue??"");}return m=m.replace(/\s+/g," ").trim(),m.length>s?m.slice(0,s):m}function b(y,m){let R;for(let T=0;T<t.length;T++){let x=t[T],S=y.getPropertyValue(x);if(S){if(f[x]){if(m&&m.getPropertyValue(x)===S)continue}else if(n[x]===S)continue;R||(R={}),R[x]=S;}}return R}let C=[{el:document.body,parentPath:"",parentComputed:null}];for(;C.length>0;){let y=C.pop(),m=y.el,R=window.getComputedStyle(m);if(R.display==="none")continue;let T=m.tagName.toLowerCase(),x=m.id?"#"+m.id:y.parentPath?y.parentPath+">"+T+"["+w(m)+"]":T,S=m.children;for(let H=S.length-1;H>=0;H--)C.push({el:S[H],parentPath:x,parentComputed:R});if(R.visibility==="hidden")continue;let M=m.getBoundingClientRect();if(M.width<=0||M.height<=0)continue;if(a.length>=o){p++;continue}let nt=Math.round(M.left+c),rt=Math.round(M.top+i),ot=Math.round(M.width),st=Math.round(M.height),B={p:x,t:T,r:[nt,rt,ot,st]};m.id&&(B.i=m.id);let it=m.getAttribute("class");it&&(B.c=it.replace(/\s+/g," ").trim());let at=k(m);at&&(B.x=at);let ut=b(R,y.parentComputed);ut&&(B.s=ut),h(nt,rt,ot,st)&&(B.m=1),a.push(B);}let A=Math.max(document.documentElement.scrollWidth,window.innerWidth),v=Math.max(document.documentElement.scrollHeight,window.innerHeight),P;return l?P=[Math.round(l[0]+c),Math.round(l[1]+i),Math.round(l[2]),Math.round(l[3])]:u?P=[0,0,A,v]:P=[Math.round(c),Math.round(i),window.innerWidth,window.innerHeight],{version:"1.0",url:location.href,viewport:{width:window.innerWidth,height:window.innerHeight},content:{width:A,height:v},captureBox:P,nodes:a,truncatedNodes:p}}var ye=["display","position","color","background-color","background-image","border-top-width","border-right-width","border-bottom-width","border-left-width","border-color","border-style","border-radius","box-shadow","opacity","transform","margin-top","margin-right","margin-bottom","margin-left","padding-top","padding-right","padding-bottom","padding-left","font-family","font-size","font-weight","line-height","letter-spacing","text-align","text-decoration-line","text-transform","flex-direction","justify-content","align-items","gap","z-index","overflow"],we={position:"static","background-color":"rgba(0, 0, 0, 0)","background-image":"none","border-top-width":"0px","border-right-width":"0px","border-bottom-width":"0px","border-left-width":"0px","border-style":"none","border-radius":"0px","box-shadow":"none",opacity:"1",transform:"none","margin-top":"0px","margin-right":"0px","margin-bottom":"0px","margin-left":"0px","padding-top":"0px","padding-right":"0px","padding-bottom":"0px","padding-left":"0px","text-decoration-line":"none","flex-direction":"row","justify-content":"normal","align-items":"normal",gap:"normal","z-index":"auto",overflow:"visible"},ke=["color","font-family","font-size","font-weight","line-height","letter-spacing","text-align","text-transform"],be=1024*1024,xe=1500,Ce=200;async function Re(e){let t=[];for(let n of e)try{let r=await n.boundingBox();r&&t.push([r.x,r.y,r.width,r.height]);}catch{}return t}async function Tt(e){let t=e.config??{};try{let n=e.maskLocators?.length?await Re(e.maskLocators):[],r=null;if(e.bounded){let s=await e.bounded.boundingBox();s&&(r=[s.x,s.y,s.width,s.height]);}let o={styleProps:ye,defaults:we,inherited:ke,maxNodes:t.maxNodes??xe,maxText:t.maxText??Ce,maskBoxes:n,viewportBox:r,fullPage:e.fullPage===!0};return await e.target.evaluate(St,o)}catch{return null}}function At(e,t=be){let n=JSON.stringify(e);if(Buffer.byteLength(n,"utf-8")<=t)return {json:n,truncatedBytes:false};let r=e.nodes.slice(),o=0;for(;r.length>0&&Buffer.byteLength(n,"utf-8")>t;){let s=Math.max(1,Math.floor(r.length*.1));r.splice(-s,s),o+=s,n=JSON.stringify({...e,nodes:r,truncatedNodes:e.truncatedNodes+o});}return {json:n,truncatedBytes:true}}function vt(e){return e.replace(/\.[A-Za-z0-9]+$/,"")+".dom.json"}function Pt(e){try{if(!existsSync(e))return null;let t=JSON.parse(readFileSync(e,"utf-8"));return Se(t)?t:null}catch{return null}}function Dt(e,t){try{return mkdirSync(dirname(e),{recursive:!0}),writeFileSync(e,t,"utf-8"),!0}catch{return false}}function Se(e){if(typeof e!="object"||e===null)return false;let t=e;return typeof t.version=="string"&&Array.isArray(t.nodes)&&Array.isArray(t.captureBox)&&t.captureBox.length===4}var Te=new Set(["moved","resized"]);function q(e){return e.some(t=>!Te.has(t))}function Y(e){let t=e.t;if(e.i&&(t+="#"+e.i),e.c){let n=e.c.split(" ").filter(Boolean).slice(0,3);n.length>0&&(t+="."+n.join("."));}return t}function Ae(e,t){let n=[],r=Math.abs(e.r[0]-t.r[0]),o=Math.abs(e.r[1]-t.r[1]),s=Math.abs(e.r[2]-t.r[2]),d=Math.abs(e.r[3]-t.r[3]);return (r>1||o>1)&&n.push("moved"),(s>1||d>1)&&n.push("resized"),n}function ve(e,t){let n=e.s??{},r=t.s??{},o=new Set([...Object.keys(n),...Object.keys(r)]),s=[];for(let d of o){let l=n[d],u=r[d];l!==u&&s.push({prop:d,from:l??"(initial)",to:u??"(initial)"});}return s.sort((d,l)=>d.prop.localeCompare(l.prop)),s}function Nt(e){return e.i?"i:"+e.t+"#"+e.i:e.c?"c:"+e.t+"."+e.c:null}function Pe(e,t){let n=new Map;for(let i of e)n.set(i.p,i);let r=[],o=[],s=new Set;for(let i of t){let a=n.get(i.p);if(a&&a.t!==i.t){o.push(i);continue}a&&!s.has(a)?(s.add(a),r.push({before:a,after:i})):o.push(i);}let d=e.filter(i=>!s.has(i)),l=new Map;for(let i of d){let a=Nt(i);if(!a)continue;let p=l.get(a);p?p.push(i):l.set(a,[i]);}let u=[],f=new Set;for(let i of o){let a=Nt(i),g=(a?l.get(a):void 0)?.find(h=>!f.has(h));g?(f.add(g),r.push({before:g,after:i})):u.push(i);}let c=d.filter(i=>!f.has(i));return {pairs:r,removed:c,added:u}}function De(e,t){let n=[];return (e.i??"")!==(t.i??"")&&n.push({prop:"id",from:e.i??"(none)",to:t.i??"(none)"}),(e.c??"")!==(t.c??"")&&n.push({prop:"class",from:e.c??"(none)",to:t.c??"(none)"}),n}function K(e,t){let n=(t[2]??0)*(t[3]??0);return n<=0?0:Math.min(1,e.r[2]*e.r[3]/n)}function Mt(e,t,n={}){let r=n.maxChanges??50,o=n.includeText!==false,s=n.includeStyles!==false,d=e.nodes.filter(g=>g.m!==1),l=t.nodes.filter(g=>g.m!==1),{pairs:u,removed:f,added:c}=Pe(d,l),i=[];for(let{before:g,after:h}of u){let w=Ae(g,h),k=s?ve(g,h):[];k.length>0&&w.push("restyled");let b=De(g,h);b.length>0&&w.push("attrs");let C=o&&(g.x??"")!==(h.x??"");if(C&&w.push("text"),w.length===0)continue;let A=K(h,t.captureBox);i.push({score:A,change:{path:h.p,label:Y(h),kinds:w,rect:h.r,baselineRect:g.r,areaPct:A,...b.length>0?{attrs:b}:{},...k.length>0?{styles:k}:{},...C?{text:{from:g.x??"",to:h.x??""}}:{}}});}for(let g of c){let h=K(g,t.captureBox);i.push({score:h,change:{path:g.p,label:Y(g),kinds:["added"],rect:g.r,areaPct:h}});}for(let g of f){let h=K(g,e.captureBox);i.push({score:h,change:{path:g.p,label:Y(g),kinds:["removed"],baselineRect:g.r,areaPct:h}});}let a=i.filter(g=>q(g.change.kinds)).length;return i.sort((g,h)=>{if(a>0){let w=q(g.change.kinds)?1:0,k=q(h.change.kinds)?1:0;if(w!==k)return k-w}return h.score-g.score}),{changes:i.slice(0,r).map((g,h)=>({rank:h+1,...g.change,...a>0&&!q(g.change.kinds)?{consequence:true}:{}})),total:i.length,rootCauses:a}}var Ne="__testrelic_snapshot_path_probe__.png",Bt=Symbol.for("testrelic.snapshotPathWarned");function Me(){let e=globalThis,t=e[Bt];return t||(t={warned:false},e[Bt]=t),t}function F(e){try{let t=e.snapshotPath(Ne,{kind:"screenshot"});return typeof t=="string"&&!t.includes("[object Object]")}catch{return false}}function j(e){let t=Me();t.warned||(t.warned=true,process.stderr.write(`[testrelic] ${e} needs Playwright >= 1.51 for testInfo.snapshotPath(name, { kind }); this project's Playwright resolves that call the older way. Everything else in the reporter is unaffected \u2014 upgrade Playwright to enable it.
7
- `));}var _t="testrelic-visual-dom",Oe=new Set(["toHaveScreenshot","toMatchVisualBaseline"]);function It(e){if(typeof e!="object"||e===null)return false;let t=e;return typeof t.boundingBox=="function"&&typeof t.page=="function"}function Le(e){if(typeof e!="object"||e===null)return false;let t=e;return typeof t.evaluate=="function"&&typeof t.screenshot=="function"}function qe(e){let t=e[0];if(typeof t=="string")return t;if(Array.isArray(t))return t.join("/");if(typeof t=="object"&&t!==null){let n=t.name;if(typeof n=="string")return n}return null}function Fe(e){for(let t of e)if(typeof t=="object"&&t!==null&&!Array.isArray(t))return t;return {}}function je(e){let t=e.mask;return Array.isArray(t)?t.filter(n=>typeof n=="object"&&n!==null&&typeof n.boundingBox=="function"):[]}function He(e){return /\.(png|jpg|jpeg)$/i.test(e)?e:`${e}.png`}var We=/^(.+)-(expected|actual|diff|previous)\.[A-Za-z0-9]+$/;function Ve(e,t,n){let r=e.attachments;for(let o=t;o<r.length;o++){let s=We.exec(r[o]?.name??"");if(s)return s[1]}return n}async function Ue(e){let t=Fe(e.args),n=It(e.received)?e.received:null,r=n?n.page():e.received;return Tt({target:r,bounded:n,maskLocators:je(t),fullPage:t.fullPage===true})}function ze(e){let t=e.config?.updateSnapshots;return t==="all"||t==="changed"}async function Ge(e,t){let n=qe(e.args);if(!n)return;if(!F(e.testInfo)){j("DOM comparison");return}let r=e.testInfo.snapshotPath(He(n),{kind:"screenshot"}),o=vt(r),s=Ve(e.testInfo,e.attachedBefore,basename(r,extname(r))),d=At(t),u=ze(e.testInfo)?null:Pt(o);if(!u){Dt(o,d.json);return}let{changes:f,total:c,rootCauses:i}=Mt(u,t),a;try{a=e.testInfo.outputPath(`${s}.actual.dom.json`),writeFileSync(a,d.json,"utf-8");}catch{a=void 0;}let p={stem:s,changes:f,total:c,rootCauses:i,truncated:d.truncatedBytes||t.truncatedNodes>0,captureBox:t.captureBox,...existsSync(o)?{baselineDomPath:o}:{},...a?{actualDomPath:a}:{}};await e.testInfo.attach(_t,{body:Buffer.from(JSON.stringify([p])),contentType:"application/json"});}function Et(e,t){let n=function(d,...l){let u=e(d,...l);return !(It(d)||Le(d))||typeof u!="object"||u===null?u:new Proxy(u,{get(c,i,a){let p=Reflect.get(c,i,a);if(typeof i!="string"||!Oe.has(i)||typeof p!="function")return p;let g=p;return async function(...w){let k=t(),b=null,C=k?.attachments.length??0;if(k)try{b=await Ue({received:d,args:w,testInfo:k,attachedBefore:C});}catch{}try{return await g.apply(c,w)}finally{if(k&&b)try{await Ge({received:d,args:w,testInfo:k,attachedBefore:C},b);}catch{}}}}})},r=e,o=n;for(let s of Object.keys(r))o[s]=r[s];return n}var Ot="testrelic-visual";var Ye=[".png",".jpg",".jpeg"],Ke=/A snapshot doesn't exist at /;function Ze(e){return e.wrote?e.existedBefore?"updated":"new":e.pass?"passed":"failed"}function Qe(e){return e.status==="failed"&&!e.hadBaseline}function Lt(e){if(!e)return null;try{let t=statSync(e);return {size:t.size,mtimeMs:t.mtimeMs}}catch{return null}}function tn(e,t){if(!F(e))return null;try{return e.snapshotPath(t,{kind:"screenshot"})}catch{return null}}function en(e){let t=e.toLowerCase();return Ye.some(n=>t.endsWith(n))?e:`${e}.png`}function nn(){try{return test.info()}catch{return null}}function rn(e,t,n){let r=s=>/^(.+)-(expected|actual|diff|previous)\.[A-Za-z0-9]+$/.exec(s)?.[1]??null,o=e.slice(t);if(n){for(let s of o)if(s.path===n&&/-expected\.[A-Za-z0-9]+$/.test(s.name))return r(s.name)}for(let s of o){let d=r(s.name);if(d)return d}return null}function on(e,t){return t?basename(t,extname(t)||".png"):e.replace(/\.[A-Za-z0-9]+$/,"")}async function sn(e,t){if(t===null)return j("Attaching the baseline of a passing comparison"),null;try{let n=extname(t)||".png",r=basename(t,n);return await e.attach(`${r}-expected${n}`,{path:t}),r}catch{return null}}async function an(e,t){try{await e.attach(Ot,{body:Buffer.from(JSON.stringify([t])),contentType:"application/json"});}catch{}}async function Z(e,t,n={}){let r={...n};delete r.tags;let o=en(t),s=nn(),d=s?.attachments.length??0,l=s?.errors?.length??0,u=s?tn(s,o):null,f=Lt(u),c=true,i="";try{await expect(e).toHaveScreenshot(o,r);}catch(a){c=false,i=a instanceof Error?a.message:String(a);}if(s){let a=Lt(u),p=u!==null?a!==null&&(f===null||f.size!==a.size||f.mtimeMs!==a.mtimeMs):(s.errors??[]).slice(l).some(k=>Ke.test(k.message??"")),g=Ze({pass:c,wrote:p,existedBefore:f!==null}),w=(g==="passed"||g==="updated"?await sn(s,u):rn(s.attachments,d,u))??(Qe({status:g,hadBaseline:f!==null})?on(o,u):null);w&&await an(s,{stem:w,name:t,status:g,...u?{committedPath:u}:{}});}return {pass:c,name:"toMatchVisualBaseline",message:()=>c?`Expected "${t}" to differ from its visual baseline, but it matched.`:i}}expect.extend({toMatchVisualBaseline:Z});function ln(){try{return test.info()}catch{return null}}var Rr=Et(wt(expect),ln),dn="__testrelic_api_config",pn="__testrelic_config_trackApiCalls";function fn(e){let t=e.annotations.find(r=>r.type===dn&&r.description!==void 0);if(t)try{return JSON.parse(t.description,gn)}catch{}let n=e.annotations.find(r=>r.type===pn&&r.description!==void 0);return n?{trackApiCalls:n.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 gn(e,t){if(typeof t=="object"&&t!==null&&t.__regexp===true&&typeof t.source=="string"){let{source:n,flags:r}=t;return new RegExp(n,r)}return t}var hn={page:async({page:e},t,n)=>{let r=new _(e);try{await r.init();}catch{}await t(e);try{let{navigations:o,networkRequestsFile:s,networkRequestsCount:d,consoleLogsFile:l,consoleLogsCount:u}=await r.getFileData(),f={testRelicData:!0,version:PAYLOAD_VERSION,navigations:o,apiAssertions:[],networkRequestsFile:s,networkRequestsCount:d,consoleLogsFile:l,consoleLogsCount:u,apiCallsFile:null,apiCallsCount:0};await n.attach(ATTACHMENT_NAME,{body:Buffer.from(JSON.stringify(f)),contentType:ATTACHMENT_CONTENT_TYPE});}catch{}r.dispose();},request:async({request:e},t,n)=>{let r=fn(n);if(!r.trackApiCalls){await t(e);return}let o=new I,s=new O(e,o,r);s.intercept(),z(o,s);try{await t(e);}finally{z(null,null);}try{let{apiCallsFile:d,apiCallsCount:l,apiStatusMix:u}=s.getFileData(),f=r.captureAssertions?o.getData():[],c={testRelicData:!0,version:PAYLOAD_VERSION,navigations:[],apiAssertions:f,networkRequestsFile:null,networkRequestsCount:0,consoleLogsFile:null,consoleLogsCount:0,apiCallsFile:d,apiCallsCount:l,apiStatusMix:u};await n.attach(ATTACHMENT_NAME,{body:Buffer.from(JSON.stringify(c)),contentType:ATTACHMENT_CONTENT_TYPE});}catch{}s.dispose(),o.dispose();}};async function Sr(e,t){let n=new _(e);try{await n.init();}catch{}return async()=>{try{let{navigations:r,networkRequestsFile:o,networkRequestsCount:s,consoleLogsFile:d,consoleLogsCount:l}=await n.getFileData(),u={testRelicData:!0,version:PAYLOAD_VERSION,navigations:r,apiAssertions:[],networkRequestsFile:o,networkRequestsCount:s,consoleLogsFile:d,consoleLogsCount:l,apiCallsFile:null,apiCallsCount:0};await t.attach(ATTACHMENT_NAME,{body:Buffer.from(JSON.stringify(u)),contentType:ATTACHMENT_CONTENT_TYPE});}catch{}n.dispose();}}var Tr=test.extend(hn);export{Rr as expect,fn as readApiConfig,Tr as test,hn as testRelicFixture,Sr as trackPage};//# sourceMappingURL=fixture.js.map
4
+ `)){let n=t.match(/at\s+(?:.*?\s+\()?(.+?):\d+:\d+\)?$/);if(!n||n[1].startsWith("node:"))continue;let r=Math.max(n[1].lastIndexOf("/"),n[1].lastIndexOf("\\"));return r>0?n[1].slice(0,r+1):null}return null})();function ee(e){if(!e.startsWith("file:"))return e;try{return fileURLToPath(e)}catch{return e}}function ne(){let t=new Error().stack;if(!t)return null;let n=t.split(`
5
+ `);return gt(n,true)??gt(n,false)}function gt(e,t){for(let n of e){if(t&&ft!==null&&n.includes(ft)||n.includes("node_modules")||n.includes("node:internal")||n.includes(" at new Error")||n.includes(" at captureAssertionLocation")||n.includes(" at findFrame")||n.includes(" at expectWrapper")||n.includes(" at wrappedMatcher"))continue;let r=n.match(/at\s+(?:.*?\s+\()?(.+?):(\d+):(\d+)\)?$/);if(r)return {file:ee(r[1]),line:parseInt(r[2],10),column:parseInt(r[3],10)}}return null}function re(e,t){if(!e)return "custom";let n=e.toLowerCase();return n.includes(".status()")&&!n.includes(".statustext()")?n.includes(".ok()")?"statusOk":"status":n.includes(".ok()")?"statusOk":n.includes(".headers()")||n.includes(".headersarray()")?"header":n.includes("tomatchobject")||n.includes("toequal")?"bodyMatch":n.includes("tocontain")||n.includes("tostringcontaining")?"bodyContains":n.includes(".json()")||n.includes(".text()")?"bodyField":"custom"}function oe(e,t,n){let r=function(l,...u){let f=e(),c=t();if(!f||!c)return n(l,...u);let i=null;if(l!=null&&typeof l=="object"){let h=l[U];typeof h=="string"&&(i=h);}if(!i&&l!==null&&l!==void 0&&typeof l=="object"&&(i=D.get(l)??null),i||(i=c.getCallIdForValue(l)),i||(i=f.getCurrentCallId()),!i)return n(l,...u);let a=ne(),p;if(a){let h=te(a.file);h&&a.line>0&&a.line<=h.length&&(p=h[a.line-1].trim());}let g=n(l,...u);return kt(g,{tracker:f,callId:i,received:l,location:a??{file:"unknown",line:0},expression:p})},o=n,s=r;for(let d of Object.keys(o))s[d]=o[d];return r}var ht=Symbol.for("testrelic.activeAssertionContext");function V(){let e=globalThis,t=e[ht];return t||(t={tracker:null,apiTracker:null},e[ht]=t),t}function z(e,t){let n=V();n.tracker=e,n.apiTracker=t;}function wt(e){return oe(()=>V().tracker,()=>V().apiTracker,e)}function kt(e,t){return new Proxy(e,{get(n,r,o){let s=Reflect.get(n,r,o);return typeof s!="function"||typeof r=="symbol"?s:r==="not"?kt(s,t):function(...l){let u=l[0],f="passed",c=t.received,i=null;try{let a=s.apply(this??n,l);return a&&typeof a=="object"&&typeof a.then=="function"?a.then(()=>{W(t,r,u,c,"passed");},p=>{throw W(t,r,u,c,"failed"),p}):a}catch(a){if(f="failed",i=a,a instanceof Error&&a.message){let p=a.message.match(/Received:\s*(.+)/);p&&(c=p[1]);}throw a}finally{(i!==null||f==="passed")&&W(t,r,u,c,f);}}}})}function W(e,t,n,r,o){let s=re(e.expression,e.received),d={callId:e.callId,type:s,expected:mt(n),actual:mt(r),status:o,location:e.location,expression:e.expression};e.tracker.recordAssertion(d);}function mt(e){if(e==null)return e;if(typeof e=="string")return dt(e);if(typeof e=="number"||typeof e=="boolean")return e;try{return JSON.stringify(e),e}catch{return String(e)}}var bt="[REDACTED]";function G(e,t){if(e===null||t.length===0)return e;let n=new Set(t.map(o=>o.toLowerCase())),r={};for(let o of Object.keys(e))Object.prototype.hasOwnProperty.call(e,o)&&(r[o]=n.has(o.toLowerCase())?bt:e[o]);return r}function I(e,t){if(e===null||t.length===0)return e;let n;try{n=JSON.parse(e);}catch{return e}if(typeof n!="object"||n===null)return e;let r=new Set(t.map(s=>s.toLowerCase())),o=J(n,r);return JSON.stringify(o)}function J(e,t){if(Array.isArray(e))return e.map(n=>J(n,t));if(typeof e=="object"&&e!==null){let n={};for(let r of Object.keys(e)){if(!Object.prototype.hasOwnProperty.call(e,r))continue;let o=e[r];t.has(r.toLowerCase())?n[r]=bt:n[r]=J(o,t);}return n}return e}var se=new Set(["access_token","api_key","token","sig"]);function $(e){if(!e)return e;let t;try{t=new URL(e);}catch{return e}let n=false;for(let r of [...t.searchParams.keys()])se.has(r.toLowerCase())&&(t.searchParams.delete(r),n=true);return n?t.toString():e}function Ct(e,t,n){if(n.length>0){for(let r of n)if(xt(e,r))return false}if(t.length>0){for(let r of t)if(xt(e,r))return true;return false}return true}function xt(e,t){try{return t instanceof RegExp?t.test(e):ie(t).test(e)}catch{return process.stderr.write(`[testrelic] Invalid URL filter pattern: ${String(t)}
6
+ `),false}}function ie(e){let t="",n=0;for(;n<e.length;){let r=e[n];r==="*"&&e[n+1]==="*"?(t+=".*",n+=2,e[n]==="/"&&n++):r==="*"?(t+="[^/]*",n++):r==="?"?(t+="[^/]",n++):".+^${}()|[]\\".includes(r)?(t+="\\"+r,n++):(t+=r,n++);}return new RegExp(t)}var ae=["get","post","put","patch","delete","head","fetch"],ue=["text/","application/json","application/xml","application/javascript","application/x-www-form-urlencoded","application/graphql"];function ce(e){let t=e.toLowerCase();return ue.some(n=>t.includes(n))}function le(e){if(!e)return null;if(e.data!==void 0&&e.data!==null){let t=e.data;return typeof t=="string"?t:Buffer.isBuffer(t)?t.toString("base64"):JSON.stringify(t)}if(e.form!==void 0&&e.form!==null)return JSON.stringify(e.form);if(e.multipart!==void 0&&e.multipart!==null){let t=e.multipart,n={};for(let[r,o]of Object.entries(t))typeof o=="string"||typeof o=="number"||typeof o=="boolean"?n[r]=String(o):o&&typeof o=="object"&&"name"in o?n[r]=`[file: ${o.name}]`:n[r]="[binary]";return JSON.stringify(n)}return null}function Rt(e){return e?"\u2022\u2022\u2022\u2022":""}function de(e){if(!e)return [];let t;for(let[r,o]of Object.entries(e))if(r.toLowerCase()==="cookie"){t=o;break}if(!t)return [];let n=[];for(let r of t.split(";")){let o=r.trim();if(!o)continue;let s=o.indexOf("="),d=s===-1?o:o.slice(0,s).trim(),l=s===-1?"":o.slice(s+1).trim();d&&n.push({name:d,value:Rt(l)});}return n}function pe(e){let t=[];for(let n of e)for(let r of n.split(/,(?=\s*[A-Za-z0-9_.-]+=)/)){let o=r.trim();if(!o)continue;let s=o.split(";"),d=s[0].indexOf("=");if(d===-1)continue;let l=s[0].slice(0,d).trim(),u=s[0].slice(d+1).trim(),f=s.slice(1).map(c=>c.trim()).filter(Boolean).join(" \xB7 ")||void 0;l&&t.push({name:l,value:Rt(u),attributes:f});}return t}var L=class L{constructor(t,n,r){this.originals=new Map;this.apiCallWriter=null;this.statusMix={"2xx":0,"3xx":0,"4xx":0,"5xx":0,error:0};this.callCounter=0;this.apiCallCount=0;this.disposed=false;this._lastCallId=null;this.primitiveCallIds=new Map;this.context=t,this.assertionTracker=n??null,this.apiConfig=r??L.DEFAULT_API_CONFIG;try{this.apiCallWriter=new N("api-calls");}catch{}}get lastCallId(){return this._lastCallId}getCallIdForValue(t){return t!=null&&typeof t=="object"?D.get(t)??null:this.primitiveCallIds.get(t)??null}intercept(){for(let n of ae){let r=this.context[n].bind(this.context);this.originals.set(n,r),this.context[n]=this.createWrapper(n,r);}let t=this.context.dispose.bind(this.context);this.originals.set("dispose",t),this.context.dispose=async n=>(this.disposed=true,t(n));}tallyStatus(t){if(t===null||t<=0){this.statusMix.error++;return}if(t>=500){this.statusMix["5xx"]++;return}if(t>=400){this.statusMix["4xx"]++;return}if(t>=300){this.statusMix["3xx"]++;return}if(t>=200){this.statusMix["2xx"]++;return}this.statusMix.error++;}getFileData(){return this.apiCallWriter?.close(),{apiCallsFile:this.apiCallWriter?.getCount()?this.apiCallWriter.getPath():null,apiCallsCount:this.apiCallWriter?.getCount()??0,apiStatusMix:{...this.statusMix}}}flushLegacyAnnotations(t){}dispose(){for(let[t,n]of this.originals)this.context[t]=n;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,n){let{primitiveCallIds:r}=this,o=t.headers.bind(t);t.headers=function(){let p=o();return D.set(p,n),p};let s=t.headersArray.bind(t);t.headersArray=function(){let p=s();return D.set(p,n),p};let d=t.json.bind(t);t.json=async function(){let p=await d();return p!=null&&typeof p=="object"&&D.set(p,n),p};let l=t.status.bind(t);t.status=function(){let p=l();return r.set(p,n),p};let u=t.statusText.bind(t);t.statusText=function(){let p=u();return r.set(p,n),p};let f=t.ok.bind(t);t.ok=function(){let p=f();return r.set(p,n),p};let c=t.text.bind(t);t.text=async function(){let p=await c();return r.set(p,n),p};let i=t.body.bind(t);t.body=async function(){let p=await i();return D.set(p,n),p};}createWrapper(t,n){return async(r,o)=>{if(!Ct(r,this.apiConfig.apiIncludeUrls,this.apiConfig.apiExcludeUrls))return n(r,o);let s=`api-call-${this.callCounter++}`,d=new Date().toISOString(),l=t==="fetch"?(o?.method??"GET").toUpperCase():t.toUpperCase(),u=le(o),f=performance.now();this._lastCallId=s,this.assertionTracker&&this.assertionTracker.setCurrentCallId(s);let c;try{c=await n(r,o);}catch(i){let a=performance.now();try{let p=this.apiConfig.captureRequestBody?I(u,this.apiConfig.redactBodyFields):null,g={id:s,timestamp:d,method:l,url:$(r),requestHeaders:null,requestBody:p,responseStatusCode:null,responseStatusText:null,responseHeaders:null,responseBody:null,responseTimeMs:Math.round((a-f)*100)/100,isBinary:!1,error:i instanceof Error?i.message:String(i)};this.apiCallWriter&&(this.apiCallWriter.append(g),this.apiCallCount++,this.tallyStatus(null));}catch{}throw i}try{let i=performance.now(),a=c.headers(),p=a["content-type"]??null,g=p?!ce(p):!1,h=null;this.apiConfig.captureRequestHeaders&&o?.headers&&(h=o.headers);let w=null;this.apiConfig.captureResponseHeaders&&(w=a);let k=this.apiConfig.captureRequestBody?u:null,b=null;if(this.apiConfig.captureResponseBody)try{g?b=(await c.body()).toString("base64"):b=await c.text();}catch{}let C=[],A=[];try{if(this.apiConfig.captureRequestHeaders&&(C=de(o?.headers)),this.apiConfig.captureResponseHeaders){let P=c.headersArray().filter(y=>y.name.toLowerCase()==="set-cookie").map(y=>y.value);A=pe(P);}}catch{}h=G(h,this.apiConfig.redactHeaders),w=G(w,this.apiConfig.redactHeaders),k=I(k,this.apiConfig.redactBodyFields),b=I(b,this.apiConfig.redactBodyFields);let v={id:s,timestamp:d,method:l,url:$(c.url()),requestHeaders:h,requestBody:k,responseStatusCode:c.status(),responseStatusText:c.statusText(),responseHeaders:w,responseBody:b,requestCookies:C.length?C:null,responseCookies:A.length?A:null,responseTimeMs:Math.round((i-f)*100)/100,isBinary:g,error:null};this.apiCallWriter&&(this.apiCallWriter.append(v),this.apiCallCount++,this.tallyStatus(v.responseStatusCode));}catch{}try{c[U]=s,this.tagResponseMethods(c,s);}catch{}return c}}};L.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 O=L;Buffer.from([137,80,78,71,13,10,26,10]);function Tt(e){let{styleProps:t,defaults:n,inherited:r,maxNodes:o,maxText:s,maskBoxes:d,viewportBox:l,fullPage:u}=e,f={};for(let y=0;y<r.length;y++)f[r[y]]=true;let c=window.scrollX||window.pageXOffset||0,i=window.scrollY||window.pageYOffset||0,a=[],p=0,g=[];for(let y=0;y<d.length;y++){let m=d[y];g.push([m[0]+c,m[1]+i,m[2],m[3]]);}function h(y,m,R,S){for(let x=0;x<g.length;x++){let T=g[x];if(y<T[0]+T[2]&&y+R>T[0]&&m<T[1]+T[3]&&m+S>T[1])return true}return false}function w(y){let m=y.parentElement;if(!m)return 0;let R=m.children,S=0;for(let x=0;x<R.length;x++){let T=R[x];if(T===y)break;T.tagName===y.tagName&&S++;}return S}function k(y){let m="",R=y.childNodes;for(let S=0;S<R.length;S++){let x=R[S];x.nodeType===3&&(m+=x.nodeValue??"");}return m=m.replace(/\s+/g," ").trim(),m.length>s?m.slice(0,s):m}function b(y,m){let R;for(let S=0;S<t.length;S++){let x=t[S],T=y.getPropertyValue(x);if(T){if(f[x]){if(m&&m.getPropertyValue(x)===T)continue}else if(n[x]===T)continue;R||(R={}),R[x]=T;}}return R}let C=[{el:document.body,parentPath:"",parentComputed:null}];for(;C.length>0;){let y=C.pop(),m=y.el,R=window.getComputedStyle(m);if(R.display==="none")continue;let S=m.tagName.toLowerCase(),x=m.id?"#"+m.id:y.parentPath?y.parentPath+">"+S+"["+w(m)+"]":S,T=m.children;for(let H=T.length-1;H>=0;H--)C.push({el:T[H],parentPath:x,parentComputed:R});if(R.visibility==="hidden")continue;let M=m.getBoundingClientRect();if(M.width<=0||M.height<=0)continue;if(a.length>=o){p++;continue}let nt=Math.round(M.left+c),rt=Math.round(M.top+i),ot=Math.round(M.width),st=Math.round(M.height),_={p:x,t:S,r:[nt,rt,ot,st]};m.id&&(_.i=m.id);let it=m.getAttribute("class");it&&(_.c=it.replace(/\s+/g," ").trim());let at=k(m);at&&(_.x=at);let ut=b(R,y.parentComputed);ut&&(_.s=ut),h(nt,rt,ot,st)&&(_.m=1),a.push(_);}let A=Math.max(document.documentElement.scrollWidth,window.innerWidth),v=Math.max(document.documentElement.scrollHeight,window.innerHeight),P;return l?P=[Math.round(l[0]+c),Math.round(l[1]+i),Math.round(l[2]),Math.round(l[3])]:u?P=[0,0,A,v]:P=[Math.round(c),Math.round(i),window.innerWidth,window.innerHeight],{version:"1.0",url:location.href,viewport:{width:window.innerWidth,height:window.innerHeight},content:{width:A,height:v},captureBox:P,nodes:a,truncatedNodes:p}}var we=["display","position","color","background-color","background-image","border-top-width","border-right-width","border-bottom-width","border-left-width","border-color","border-style","border-radius","box-shadow","opacity","transform","margin-top","margin-right","margin-bottom","margin-left","padding-top","padding-right","padding-bottom","padding-left","font-family","font-size","font-weight","line-height","letter-spacing","text-align","text-decoration-line","text-transform","flex-direction","justify-content","align-items","gap","z-index","overflow"],ke={position:"static","background-color":"rgba(0, 0, 0, 0)","background-image":"none","border-top-width":"0px","border-right-width":"0px","border-bottom-width":"0px","border-left-width":"0px","border-style":"none","border-radius":"0px","box-shadow":"none",opacity:"1",transform:"none","margin-top":"0px","margin-right":"0px","margin-bottom":"0px","margin-left":"0px","padding-top":"0px","padding-right":"0px","padding-bottom":"0px","padding-left":"0px","text-decoration-line":"none","flex-direction":"row","justify-content":"normal","align-items":"normal",gap:"normal","z-index":"auto",overflow:"visible"},be=["color","font-family","font-size","font-weight","line-height","letter-spacing","text-align","text-transform"],xe=1024*1024,Ce=1500,Re=200;async function Te(e){let t=[];for(let n of e)try{let r=await n.boundingBox();r&&t.push([r.x,r.y,r.width,r.height]);}catch{}return t}async function St(e){let t=e.config??{};try{let n=e.maskLocators?.length?await Te(e.maskLocators):[],r=null;if(e.bounded){let s=await e.bounded.boundingBox();s&&(r=[s.x,s.y,s.width,s.height]);}let o={styleProps:we,defaults:ke,inherited:be,maxNodes:t.maxNodes??Ce,maxText:t.maxText??Re,maskBoxes:n,viewportBox:r,fullPage:e.fullPage===!0};return await e.target.evaluate(Tt,o)}catch{return null}}function At(e,t=xe){let n=JSON.stringify(e);if(Buffer.byteLength(n,"utf-8")<=t)return {json:n,truncatedBytes:false};let r=e.nodes.slice(),o=0;for(;r.length>0&&Buffer.byteLength(n,"utf-8")>t;){let s=Math.max(1,Math.floor(r.length*.1));r.splice(-s,s),o+=s,n=JSON.stringify({...e,nodes:r,truncatedNodes:e.truncatedNodes+o});}return {json:n,truncatedBytes:true}}function vt(e){return e.replace(/\.[A-Za-z0-9]+$/,"")+".dom.json"}function Pt(e){try{if(!existsSync(e))return null;let t=JSON.parse(readFileSync(e,"utf-8"));return Se(t)?t:null}catch{return null}}function Nt(e,t){try{return mkdirSync(dirname(e),{recursive:!0}),writeFileSync(e,t,"utf-8"),!0}catch{return false}}function Se(e){if(typeof e!="object"||e===null)return false;let t=e;return typeof t.version=="string"&&Array.isArray(t.nodes)&&Array.isArray(t.captureBox)&&t.captureBox.length===4}var Ae=new Set(["moved","resized"]);function F(e){return e.some(t=>!Ae.has(t))}function Y(e){let t=e.t;if(e.i&&(t+="#"+e.i),e.c){let n=e.c.split(" ").filter(Boolean).slice(0,3);n.length>0&&(t+="."+n.join("."));}return t}function ve(e,t){let n=[],r=Math.abs(e.r[0]-t.r[0]),o=Math.abs(e.r[1]-t.r[1]),s=Math.abs(e.r[2]-t.r[2]),d=Math.abs(e.r[3]-t.r[3]);return (r>1||o>1)&&n.push("moved"),(s>1||d>1)&&n.push("resized"),n}function Pe(e,t){let n=e.s??{},r=t.s??{},o=new Set([...Object.keys(n),...Object.keys(r)]),s=[];for(let d of o){let l=n[d],u=r[d];l!==u&&s.push({prop:d,from:l??"(initial)",to:u??"(initial)"});}return s.sort((d,l)=>d.prop.localeCompare(l.prop)),s}function Dt(e){return e.i?"i:"+e.t+"#"+e.i:e.c?"c:"+e.t+"."+e.c:null}function Ne(e,t){let n=new Map;for(let i of e)n.set(i.p,i);let r=[],o=[],s=new Set;for(let i of t){let a=n.get(i.p);if(a&&a.t!==i.t){o.push(i);continue}a&&!s.has(a)?(s.add(a),r.push({before:a,after:i})):o.push(i);}let d=e.filter(i=>!s.has(i)),l=new Map;for(let i of d){let a=Dt(i);if(!a)continue;let p=l.get(a);p?p.push(i):l.set(a,[i]);}let u=[],f=new Set;for(let i of o){let a=Dt(i),g=(a?l.get(a):void 0)?.find(h=>!f.has(h));g?(f.add(g),r.push({before:g,after:i})):u.push(i);}let c=d.filter(i=>!f.has(i));return {pairs:r,removed:c,added:u}}function De(e,t){let n=[];return (e.i??"")!==(t.i??"")&&n.push({prop:"id",from:e.i??"(none)",to:t.i??"(none)"}),(e.c??"")!==(t.c??"")&&n.push({prop:"class",from:e.c??"(none)",to:t.c??"(none)"}),n}function K(e,t){let n=(t[2]??0)*(t[3]??0);return n<=0?0:Math.min(1,e.r[2]*e.r[3]/n)}function Mt(e,t,n={}){let r=n.maxChanges??50,o=n.includeText!==false,s=n.includeStyles!==false,d=e.nodes.filter(g=>g.m!==1),l=t.nodes.filter(g=>g.m!==1),{pairs:u,removed:f,added:c}=Ne(d,l),i=[];for(let{before:g,after:h}of u){let w=ve(g,h),k=s?Pe(g,h):[];k.length>0&&w.push("restyled");let b=De(g,h);b.length>0&&w.push("attrs");let C=o&&(g.x??"")!==(h.x??"");if(C&&w.push("text"),w.length===0)continue;let A=K(h,t.captureBox);i.push({score:A,change:{path:h.p,label:Y(h),kinds:w,rect:h.r,baselineRect:g.r,areaPct:A,...b.length>0?{attrs:b}:{},...k.length>0?{styles:k}:{},...C?{text:{from:g.x??"",to:h.x??""}}:{}}});}for(let g of c){let h=K(g,t.captureBox);i.push({score:h,change:{path:g.p,label:Y(g),kinds:["added"],rect:g.r,areaPct:h}});}for(let g of f){let h=K(g,e.captureBox);i.push({score:h,change:{path:g.p,label:Y(g),kinds:["removed"],baselineRect:g.r,areaPct:h}});}let a=i.filter(g=>F(g.change.kinds)).length;return i.sort((g,h)=>{if(a>0){let w=F(g.change.kinds)?1:0,k=F(h.change.kinds)?1:0;if(w!==k)return k-w}return h.score-g.score}),{changes:i.slice(0,r).map((g,h)=>({rank:h+1,...g.change,...a>0&&!F(g.change.kinds)?{consequence:true}:{}})),total:i.length,rootCauses:a}}var Me="__testrelic_snapshot_path_probe__.png",_t=Symbol.for("testrelic.snapshotPathWarned");function _e(){let e=globalThis,t=e[_t];return t||(t={warned:false},e[_t]=t),t}function q(e){try{let t=e.snapshotPath(Me,{kind:"screenshot"});return typeof t=="string"&&!t.includes("[object Object]")}catch{return false}}function j(e){let t=_e();t.warned||(t.warned=true,process.stderr.write(`[testrelic] ${e} needs Playwright >= 1.51 for testInfo.snapshotPath(name, { kind }); this project's Playwright resolves that call the older way. Everything else in the reporter is unaffected \u2014 upgrade Playwright to enable it.
7
+ `));}var Bt="testrelic-visual-dom",Le=new Set(["toHaveScreenshot","toMatchVisualBaseline"]);function Et(e){if(typeof e!="object"||e===null)return false;let t=e;return typeof t.boundingBox=="function"&&typeof t.page=="function"}function Fe(e){if(typeof e!="object"||e===null)return false;let t=e;return typeof t.evaluate=="function"&&typeof t.screenshot=="function"}function qe(e){let t=e[0];if(typeof t=="string")return t;if(Array.isArray(t))return t.join("/");if(typeof t=="object"&&t!==null){let n=t.name;if(typeof n=="string")return n}return null}function je(e){for(let t of e)if(typeof t=="object"&&t!==null&&!Array.isArray(t))return t;return {}}function He(e){let t=e.mask;return Array.isArray(t)?t.filter(n=>typeof n=="object"&&n!==null&&typeof n.boundingBox=="function"):[]}function We(e){return /\.(png|jpg|jpeg)$/i.test(e)?e:`${e}.png`}var Ve=/^(.+)-(expected|actual|diff|previous)\.[A-Za-z0-9]+$/;function Ue(e,t,n){let r=e.attachments;for(let o=t;o<r.length;o++){let s=Ve.exec(r[o]?.name??"");if(s)return s[1]}return n}async function ze(e){let t=je(e.args),n=Et(e.received)?e.received:null,r=n?n.page():e.received;return St({target:r,bounded:n,maskLocators:He(t),fullPage:t.fullPage===true})}function Je(e){let t=e.config?.updateSnapshots;return t==="all"||t==="changed"}async function Ge(e,t){let n=qe(e.args);if(!n)return;if(!q(e.testInfo)){j("DOM comparison");return}let r=e.testInfo.snapshotPath(We(n),{kind:"screenshot"}),o=vt(r),s=Ue(e.testInfo,e.attachedBefore,basename(r,extname(r))),d=At(t),u=Je(e.testInfo)?null:Pt(o);if(!u){Nt(o,d.json);return}let{changes:f,total:c,rootCauses:i}=Mt(u,t),a;try{a=e.testInfo.outputPath(`${s}.actual.dom.json`),writeFileSync(a,d.json,"utf-8");}catch{a=void 0;}let p={stem:s,changes:f,total:c,rootCauses:i,truncated:d.truncatedBytes||t.truncatedNodes>0,captureBox:t.captureBox,...existsSync(o)?{baselineDomPath:o}:{},...a?{actualDomPath:a}:{}};await e.testInfo.attach(Bt,{body:Buffer.from(JSON.stringify([p])),contentType:"application/json"});}function It(e,t){let n=function(d,...l){let u=e(d,...l);return !(Et(d)||Fe(d))||typeof u!="object"||u===null?u:new Proxy(u,{get(c,i,a){let p=Reflect.get(c,i,a);if(typeof i!="string"||!Le.has(i)||typeof p!="function")return p;let g=p;return async function(...w){let k=t(),b=null,C=k?.attachments.length??0;if(k)try{b=await ze({received:d,args:w,testInfo:k,attachedBefore:C});}catch{}try{return await g.apply(c,w)}finally{if(k&&b)try{await Ge({received:d,args:w,testInfo:k,attachedBefore:C},b);}catch{}}}}})},r=e,o=n;for(let s of Object.keys(r))o[s]=r[s];return n}var Ot="testrelic-visual";var Ke=[".png",".jpg",".jpeg"],Ze=/A snapshot doesn't exist at /;function Qe(e){return e.wrote?e.existedBefore?"updated":"new":e.pass?"passed":"failed"}function tn(e){return e.status==="failed"&&!e.hadBaseline}function Lt(e){if(!e)return null;try{let t=statSync(e);return {size:t.size,mtimeMs:t.mtimeMs}}catch{return null}}function en(e,t){if(!q(e))return null;try{return e.snapshotPath(t,{kind:"screenshot"})}catch{return null}}function nn(e){let t=e.toLowerCase();return Ke.some(n=>t.endsWith(n))?e:`${e}.png`}function rn(){try{return test.info()}catch{return null}}function on(e,t,n){let r=s=>/^(.+)-(expected|actual|diff|previous)\.[A-Za-z0-9]+$/.exec(s)?.[1]??null,o=e.slice(t);if(n){for(let s of o)if(s.path===n&&/-expected\.[A-Za-z0-9]+$/.test(s.name))return r(s.name)}for(let s of o){let d=r(s.name);if(d)return d}return null}function sn(e,t){return t?basename(t,extname(t)||".png"):e.replace(/\.[A-Za-z0-9]+$/,"")}async function an(e,t){if(t===null)return j("Attaching the baseline of a passing comparison"),null;try{let n=extname(t)||".png",r=basename(t,n);return await e.attach(`${r}-expected${n}`,{path:t}),r}catch{return null}}async function un(e,t){try{await e.attach(Ot,{body:Buffer.from(JSON.stringify([t])),contentType:"application/json"});}catch{}}async function Z(e,t,n={}){let r={...n};delete r.tags;let o=nn(t),s=rn(),d=s?.attachments.length??0,l=s?.errors?.length??0,u=s?en(s,o):null,f=Lt(u),c=true,i="";try{await expect(e).toHaveScreenshot(o,r);}catch(a){c=false,i=a instanceof Error?a.message:String(a);}if(s){let a=Lt(u),p=u!==null?a!==null&&(f===null||f.size!==a.size||f.mtimeMs!==a.mtimeMs):(s.errors??[]).slice(l).some(k=>Ze.test(k.message??"")),g=Qe({pass:c,wrote:p,existedBefore:f!==null}),w=(g==="passed"||g==="updated"?await an(s,u):on(s.attachments,d,u))??(tn({status:g,hadBaseline:f!==null})?sn(o,u):null);w&&await un(s,{stem:w,name:t,status:g,...u?{committedPath:u}:{}});}return {pass:c,name:"toMatchVisualBaseline",message:()=>c?`Expected "${t}" to differ from its visual baseline, but it matched.`:i}}expect.extend({toMatchVisualBaseline:Z});var ln="_testrelic-fixture",dn="application/json",pn='{"testRelicFixture":true}';async function fn({},e,t){try{await t.attach(ln,{body:Buffer.from(pn),contentType:dn});}catch{}await e();}var jt=[fn,{auto:true,box:true}];function hn(){try{return test.info()}catch{return null}}var Mr=It(wt(expect),hn),mn="__testrelic_api_config",yn="__testrelic_config_trackApiCalls";function wn(e){let t=e.annotations.find(r=>r.type===mn&&r.description!==void 0);if(t)try{return JSON.parse(t.description,kn)}catch{}let n=e.annotations.find(r=>r.type===yn&&r.description!==void 0);return n?{trackApiCalls:n.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 kn(e,t){if(typeof t=="object"&&t!==null&&t.__regexp===true&&typeof t.source=="string"){let{source:n,flags:r}=t;return new RegExp(n,r)}return t}var bn={page:async({page:e},t,n)=>{let r=new B(e);try{await r.init();}catch{}await t(e);try{let{navigations:o,networkRequestsFile:s,networkRequestsCount:d,consoleLogsFile:l,consoleLogsCount:u}=await r.getFileData(),f={testRelicData:!0,version:PAYLOAD_VERSION,navigations:o,apiAssertions:[],networkRequestsFile:s,networkRequestsCount:d,consoleLogsFile:l,consoleLogsCount:u,apiCallsFile:null,apiCallsCount:0};await n.attach(ATTACHMENT_NAME,{body:Buffer.from(JSON.stringify(f)),contentType:ATTACHMENT_CONTENT_TYPE});}catch{}r.dispose();},request:async({request:e},t,n)=>{let r=wn(n);if(!r.trackApiCalls){await t(e);return}let o=new E,s=new O(e,o,r);s.intercept(),z(o,s);try{await t(e);}finally{z(null,null);}try{let{apiCallsFile:d,apiCallsCount:l,apiStatusMix:u}=s.getFileData(),f=r.captureAssertions?o.getData():[],c={testRelicData:!0,version:PAYLOAD_VERSION,navigations:[],apiAssertions:f,networkRequestsFile:null,networkRequestsCount:0,consoleLogsFile:null,consoleLogsCount:0,apiCallsFile:d,apiCallsCount:l,apiStatusMix:u};await n.attach(ATTACHMENT_NAME,{body:Buffer.from(JSON.stringify(c)),contentType:ATTACHMENT_CONTENT_TYPE});}catch{}s.dispose(),o.dispose();},_testrelicFixture:jt};async function _r(e,t){let n=new B(e);try{await n.init();}catch{}return async()=>{try{let{navigations:r,networkRequestsFile:o,networkRequestsCount:s,consoleLogsFile:d,consoleLogsCount:l}=await n.getFileData(),u={testRelicData:!0,version:PAYLOAD_VERSION,navigations:r,apiAssertions:[],networkRequestsFile:o,networkRequestsCount:s,consoleLogsFile:d,consoleLogsCount:l,apiCallsFile:null,apiCallsCount:0};await t.attach(ATTACHMENT_NAME,{body:Buffer.from(JSON.stringify(u)),contentType:ATTACHMENT_CONTENT_TYPE});}catch{}n.dispose();}}var Br=test.extend(bn);export{Mr as expect,wn as readApiConfig,Br as test,bn as testRelicFixture,_r as trackPage};//# sourceMappingURL=fixture.js.map
8
8
  //# sourceMappingURL=fixture.js.map