aria-ease 7.2.0 → 7.3.0
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/README.md +2 -13
- package/dist/AccordionComponentStrategy-T5YODP3A.js +1 -0
- package/dist/buildContracts-NGEEUCN3.js +13 -0
- package/dist/cli.cjs +4 -4
- package/dist/cli.js +1 -1
- package/dist/{contractTestRunnerPlaywright-RUKMUY5P.js → contractTestRunnerPlaywright-IFI5BPGV.js} +3 -3
- package/dist/{contractTestRunnerPlaywright-2CEH3GPM.js → contractTestRunnerPlaywright-SJIHHZ3Y.js} +3 -3
- package/dist/index.cjs +14 -14
- package/dist/index.d.cts +1 -3
- package/dist/index.d.ts +1 -3
- package/dist/index.js +11 -11
- package/dist/src/utils/test/AccordionComponentStrategy-S35ZYITU.js +1 -0
- package/dist/src/utils/test/{contractTestRunnerPlaywright-LUWM3RIL.js → contractTestRunnerPlaywright-Y7N2W6AK.js} +3 -3
- package/dist/src/utils/test/dsl/index.cjs +1 -1
- package/dist/src/utils/test/dsl/index.d.cts +1 -3
- package/dist/src/utils/test/dsl/index.d.ts +1 -3
- package/dist/src/utils/test/dsl/index.js +1 -1
- package/dist/src/utils/test/index.cjs +3 -3
- package/dist/src/utils/test/index.js +1 -1
- package/dist/{test-PCRWMQUO.js → test-2XAMHIKD.js} +1 -1
- package/package.json +1 -1
- package/dist/AccordionComponentStrategy-2SWMNUR6.js +0 -1
- package/dist/buildContracts-T4XQZBDU.js +0 -13
- package/dist/src/utils/test/AccordionComponentStrategy-X2GSQ5KT.js +0 -1
package/dist/{contractTestRunnerPlaywright-2CEH3GPM.js → contractTestRunnerPlaywright-SJIHHZ3Y.js}
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{a as j}from"./chunk-WIWSYIGK.js";import{a as Te,c as Q,d as Se,e as ke}from"./chunk-APUMBDOT.js";import{a as N}from"./chunk-SM6ZKEDR.js";import"./chunk-CNU4N4AY.js";import{readFileSync as de}from"fs";import he from"path";import{readFileSync as fe}from"fs";import ge from"path";import Ce from"path";import{pathToFileURL as Pe}from"url";var oe=class{builtInStrategies=new Map;constructor(){this.registerBuiltInStrategies()}registerBuiltInStrategies(){this.builtInStrategies.set("menu",()=>import("./MenuComponentStrategy-L3QXLC6S.js").then(t=>t.MenuComponentStrategy)),this.builtInStrategies.set("accordion",()=>import("./AccordionComponentStrategy-
|
|
1
|
+
import{a as j}from"./chunk-WIWSYIGK.js";import{a as Te,c as Q,d as Se,e as ke}from"./chunk-APUMBDOT.js";import{a as N}from"./chunk-SM6ZKEDR.js";import"./chunk-CNU4N4AY.js";import{readFileSync as de}from"fs";import he from"path";import{readFileSync as fe}from"fs";import ge from"path";import Ce from"path";import{pathToFileURL as Pe}from"url";var oe=class{builtInStrategies=new Map;constructor(){this.registerBuiltInStrategies()}registerBuiltInStrategies(){this.builtInStrategies.set("menu",()=>import("./MenuComponentStrategy-L3QXLC6S.js").then(t=>t.MenuComponentStrategy)),this.builtInStrategies.set("accordion",()=>import("./AccordionComponentStrategy-T5YODP3A.js").then(t=>t.AccordionComponentStrategy)),this.builtInStrategies.set("combobox",()=>import("./ComboboxComponentStrategy-DHZS4NW6.js").then(t=>t.ComboboxComponentStrategy)),this.builtInStrategies.set("tabs",()=>import("./TabsComponentStrategy-LKV6D2B7.js").then(t=>t.TabsComponentStrategy))}async loadStrategy(t,s,r){try{if(s)try{let n=Ce.isAbsolute(s)?s:Ce.resolve(r||process.cwd(),s),u=await import(Pe(n).href),i=u.default||u;if(!i)throw new Error(`No default export found in ${s}`);return i}catch(n){throw new Error(`Failed to load custom strategy from ${s}: ${n instanceof Error?n.message:String(n)}`)}let o=this.builtInStrategies.get(t);return o?o():null}catch(o){throw new Error(`Strategy loading failed for ${t}: ${o instanceof Error?o.message:String(o)}`)}}has(t,s){return!!s||this.builtInStrategies.has(t)}};var ae=class{static strategyRegistry=new oe;static isComponentConfig(t){return typeof t=="object"&&t!==null}static async detect(t,s,r=400,o=400,n){let u=this.isComponentConfig(s)?s:void 0,i=u?.contractPath;if(!i)throw new Error(`Contract path not found for component: ${t}`);let R=(()=>{if(ge.isAbsolute(i))return i;if(n){let ie=ge.resolve(n,i);try{return fe(ie,"utf-8"),ie}catch{}}let X=ge.resolve(process.cwd(),i);try{return fe(X,"utf-8"),X}catch{return new URL(i,import.meta.url).pathname}})(),C=fe(R,"utf-8"),te=JSON.parse(C).selectors,_=await this.strategyRegistry.loadStrategy(t,u?.strategyPath,n);if(!_)return null;let z=te.main;return t==="tabs"?new _(z,te):new _(z,te,r,o)}};var ce=class{startTime=0;componentName="";staticPasses=0;staticFailures=0;staticWarnings=0;dynamicResults=[];totalTests=0;skipped=0;warnings=0;isPlaywright=!1;isCustomContract=!1;apgUrl="https://www.w3.org/WAI/ARIA/apg/";hasPrintedStaticSection=!1;hasPrintedDynamicSection=!1;constructor(t=!1,s=!1){this.isPlaywright=t,this.isCustomContract=s}log(t){process.stderr.write(t+`
|
|
2
2
|
`)}start(t,s,r){this.startTime=Date.now(),this.componentName=t,this.totalTests=s,this.hasPrintedStaticSection=!1,this.hasPrintedDynamicSection=!1,r&&(this.apgUrl=r);let o="Playwright (Real Browser)";this.log(`
|
|
3
3
|
${"\u2550".repeat(60)}`),this.log(`\u{1F50D} Testing ${t.charAt(0).toUpperCase()+t.slice(1)} Component - ${o}`),this.log(`${"\u2550".repeat(60)}
|
|
4
4
|
`)}reportStatic(t,s,r=0){this.staticPasses=t,this.staticFailures=s,this.staticWarnings=r}reportStaticTest(t,s,r,o){this.hasPrintedStaticSection||(this.log(`${"\u2500".repeat(60)}`),this.log("\u{1F9EA} Static Assertions"),this.log(`${"\u2500".repeat(60)}`),this.hasPrintedStaticSection=!0);let n=s==="pass"?"\u2713":s==="warn"?"\u26A0":s==="skip"?"\u25CB":"\u2717";this.log(` ${n} ${t}`),o&&this.log(` \u21B3 level=${o}`),(s==="fail"||s==="warn"||s==="skip")&&r&&this.log(` \u21B3 ${r}`)}reportTest(t,s,r){this.hasPrintedDynamicSection||(this.log(""),this.log(`${"\u2500".repeat(60)}`),this.log("\u2328\uFE0F Dynamic Interaction Tests"),this.log(`${"\u2500".repeat(60)}`),this.hasPrintedDynamicSection=!0);let o={description:t.description,status:s,failureMessage:r,level:t.level};s==="skip"&&(o.skipReason="Requires real browser (addEventListener events)"),this.dynamicResults.push(o);let n={pass:"\u2713",fail:"\u2717",warn:"\u26A0",skip:"\u25CB"},u=t.level?`[${t.level.toUpperCase()}] `:"";this.log(` ${n[s]} ${u}${t.description}`),s==="skip"&&!this.isPlaywright&&this.log(" \u21B3 Skipped (runs only in Playwright)"),s==="fail"&&r&&this.log(` \u21B3 ${r}`),s==="warn"&&r&&this.log(` \u21B3 ${r}`),s==="skip"&&r&&this.log(` \u21B3 ${r}`)}reportFailures(t){t.length!==0&&(this.log(`
|
|
@@ -19,13 +19,13 @@ ${"\u2550".repeat(60)}`),this.log(`\u{1F4CA} Summary
|
|
|
19
19
|
`),i>0?(this.log("\u{1F527} Next Steps:"),this.log(" 1. Review the failures above"),this.log(" 2. Fix ARIA attributes and keyboard handlers"),this.log(` 3. Re-run tests to verify fixes
|
|
20
20
|
`)):!this.isPlaywright&&this.skipped>0&&this.log(`\u2728 Optional: Run Playwright tests for complete validation
|
|
21
21
|
`),{passes:u,failures:i,skipped:this.skipped,duration:s}}error(t,s){this.log(`
|
|
22
|
-
\u274C Error: ${t}`),s&&this.log(` Context: ${s}`),this.log("")}};var ee=class{constructor(t,s,r=400){this.page=t;this.selectors=s;this.timeoutMs=r}isBrowserClosedError(t){return t instanceof Error&&t.message.includes("Target page, context or browser has been closed")}async focus(t,s,r){try{if(t==="virtual"&&r){let n=this.selectors.main;if(!n)return{success:!1,error:"Main selector not defined for virtual focus."};let u=this.page.locator(n).first();return await u.count()?(await u.evaluate((R,C)=>{R.setAttribute("aria-activedescendant",C)},r),{success:!0}):{success:!1,error:"Main element not found for virtual focus."}}if(t==="relative"&&s){let n=this.selectors.relative;if(!n)return{success:!1,error:"Relative selector not defined for focus action."};let u=await j.resolve(this.page,n,s);return u?(await u.focus({timeout:this.timeoutMs}),{success:!0}):{success:!1,error:`Could not resolve relative target ${s} for focus.`}}let o=this.selectors[t];return o?(await this.page.locator(o).first().focus({timeout:this.timeoutMs}),{success:!0}):{success:!1,error:`Selector for focus target ${t} not found.`}}catch(o){return this.isBrowserClosedError(o)?{success:!1,error:"CRITICAL: Browser/page closed during test execution. Remaining actions skipped.",shouldBreak:!0}:{success:!1,error:`Failed to focus ${t}: ${o instanceof Error?o.message:String(o)}`}}}async type(t,s){try{let r=this.selectors[t];return r?(await this.page.locator(r).first().fill(s,{timeout:this.timeoutMs}),{success:!0}):{success:!1,error:`Selector for type target ${t} not found.`}}catch(r){return this.isBrowserClosedError(r)?{success:!1,error:"CRITICAL: Browser/page closed during test execution. Remaining actions skipped.",shouldBreak:!0}:{success:!1,error:`Failed to type into ${t}: ${r instanceof Error?r.message:String(r)}`}}}async click(t,s){try{if(t==="document")return await this.page.mouse.click(10,10),{success:!0};if(t==="relative"&&s){let o=this.selectors.relative;if(!o)return{success:!1,error:"Relative selector not defined for click action."};let n=await j.resolve(this.page,o,s);return n?(await n.click({timeout:this.timeoutMs}),{success:!0}):{success:!1,error:`Could not resolve relative target ${s} for click.`}}let r=this.selectors[t];return r?(await this.page.locator(r).first().click({timeout:this.timeoutMs}),{success:!0}):{success:!1,error:`Selector for action target ${t} not found.`}}catch(r){return this.isBrowserClosedError(r)?{success:!1,error:"CRITICAL: Browser/page closed during test execution. Remaining actions skipped.",shouldBreak:!0}:{success:!1,error:`Failed to click ${t}: ${r instanceof Error?r.message:String(r)}`}}}async keypress(t,s,r){try{let n={Space:"Space",Enter:"Enter",Escape:"Escape","Arrow Up":"ArrowUp","Arrow Down":"ArrowDown","Arrow Left":"ArrowLeft","Arrow Right":"ArrowRight",Home:"Home",End:"End",Tab:"Tab"}[s]||s;if(n==="Space"?n=" ":n.includes(" ")&&(n=n.replace(/ /g,"")),t==="relative"){if(r==null)return{success:!1,error:"relativeTarget must be provided for relative keypress."};let C=this.selectors.relative;if(!C)return{success:!1,error:"Relative selector not defined for keypress action."};let A=await j.resolve(this.page,C,r);return A?(await A.press(n,{timeout:this.timeoutMs}),{success:!0}):{success:!1,error:`Could not resolve relative target ${r} for keypress.`}}let u=this.selectors[t];if(!u)return{success:!1,error:`Selector for keypress target ${t} not found.`};let i=this.page.locator(u).first();return await i.count()===0?{success:!1,error:`${t} element not found.`,shouldBreak:!0}:(await i.press(n,{timeout:this.timeoutMs}),{success:!0})}catch(o){return this.isBrowserClosedError(o)?{success:!1,error:"CRITICAL: Browser/page closed during test execution. Remaining actions skipped.",shouldBreak:!0}:{success:!1,error:`Failed to press ${s} on ${t}: ${o instanceof Error?o.message:String(o)}`}}}async hover(t,s){try{if(t==="relative"&&s){let o=this.selectors.relative;if(!o)return{success:!1,error:"Relative selector not defined for hover action."};let n=await j.resolve(this.page,o,s);return n?(await n.hover({timeout:this.timeoutMs}),{success:!0}):{success:!1,error:`Could not resolve relative target ${s} for hover.`}}let r=this.selectors[t];return r?(await this.page.locator(r).first().hover({timeout:this.timeoutMs}),{success:!0}):{success:!1,error:`Selector for hover target ${t} not found.`}}catch(r){return this.isBrowserClosedError(r)?{success:!1,error:"CRITICAL: Browser/page closed during test execution. Remaining actions skipped.",shouldBreak:!0}:{success:!1,error:`Failed to hover ${t}: ${r instanceof Error?r.message:String(r)}`}}}};var re=class{constructor(t,s,r=400){this.page=t;this.selectors=s;this.timeoutMs=r}async resolveTarget(t,s,r){try{if(t==="relative"){let n=r?this.selectors[r]:this.selectors.relative;if(!n)return{target:null,error:"Relative selector is not defined in the contract."};if(!s)return{target:null,error:"Relative target or expected value is not defined."};let u=await j.resolve(this.page,n,s);return u?{target:u}:{target:null,error:`Target ${t} not found.`}}let o=this.selectors[t];return o?{target:this.page.locator(o).first()}:{target:null,error:`Selector for assertion target ${t} not found.`}}catch(o){return{target:null,error:`Failed to resolve target ${t}: ${o instanceof Error?o.message:String(o)}`}}}async validateVisibility(t,s,r,o,n){try{return r?(await(0,N.expect)(t).toBeVisible({timeout:this.timeoutMs}),{success:!0,passMessage:`${s} is visible as expected. Test: "${n}".`}):(await(0,N.expect)(t).toBeHidden({timeout:this.timeoutMs}),{success:!0,passMessage:`${s} is not visible as expected. Test: "${n}".`})}catch{let u=this.selectors[s]||"",i=await this.page.evaluate(R=>{let C=R?document.querySelector(R):null;if(!C)return"element not found";let A=window.getComputedStyle(C);return`display:${A.display}, visibility:${A.visibility}, opacity:${A.opacity}`},u);return r?{success:!1,failMessage:`${o} (actual: ${i})`}:{success:!1,failMessage:`${o} ${s} is still visible (actual: ${i}).`}}}async validateAttribute(t,s,r,o,n,u){if(o==="!empty"){let C=await t.getAttribute(r);return C&&C.trim()!==""?{success:!0,passMessage:`${s} has non-empty "${r}". Test: "${u}".`}:{success:!1,failMessage:`${n} ${s} "${r}" should not be empty, found "${C}".`}}if(typeof o!="string")throw console.error("[AssertionRunner] expectedValue is not a string:",o),new Error(`AssertionRunner: expectedValue for attribute assertion must be a string, but got: ${JSON.stringify(o)}`);let i=o.split(" | ").map(C=>C.trim()),R=await t.getAttribute(r);return R!==null&&i.includes(R)?{success:!0,passMessage:`${s} has expected "${r}". Test: "${u}".`}:{success:!1,failMessage:`${n} ${s} "${r}" should be "${o}", found "${R}".`}}async validateValue(t,s,r,o,n){let u=await t.inputValue().catch(()=>"");return r==="!empty"?u&&u.trim()!==""?{success:!0,passMessage:`${s} has non-empty value. Test: "${n}".`}:{success:!1,failMessage:`${o} ${s} value should not be empty, found "${u}".`}:r===""?u===""?{success:!0,passMessage:`${s} has empty value. Test: "${n}".`}:{success:!1,failMessage:`${o} ${s} value should be empty, found "${u}".`}:u===r?{success:!0,passMessage:`${s} has expected value. Test: "${n}".`}:{success:!1,failMessage:`${o} ${s} value should be "${r}", found "${u}".`}}async validateFocus(t,s,r,o,n){try{return r?(await(0,N.expect)(t).toBeFocused({timeout:this.timeoutMs}),{success:!0,passMessage:`${s} has focus as expected. Test: "${n}".`}):(await(0,N.expect)(t).not.toBeFocused({timeout:this.timeoutMs}),{success:!0,passMessage:`${s} does not have focus as expected. Test: "${n}".`})}catch{let u=await this.page.evaluate(()=>{let i=document.activeElement;return i?`${i.tagName}#${i.id||"no-id"}.${i.className||"no-class"}`:"no element focused"});return{success:!1,failMessage:`${o} (actual focus: ${u})`}}}async validateRole(t,s,r,o,n){let u=await t.getAttribute("role");return u===r?{success:!0,passMessage:`${s} has role "${r}". Test: "${n}".`}:{success:!1,failMessage:`${o} Expected role "${r}", found "${u}".`}}async validate(t,s){if(this.page.isClosed())return{success:!1,failMessage:"CRITICAL: Browser/page closed before completing all tests. Increase test timeout or reduce test complexity."};let r=null,o;if(t.controlledBy){let n=t.controlledBy,u=this.selectors[n.target];if(!u)return{success:!1,failMessage:`Selector for controlledBy.target '${n.target}' not found.`,target:null};let i=null;if(n.relativeTarget?i=await j.resolve(this.page,u,n.relativeTarget):i=this.page.locator(u).first(),!i)return{success:!1,failMessage:"Controlling element for controlledBy not found.",target:null};let R=n.attribute||"aria-controls",C=await i.getAttribute(R);if(!C)return{success:!1,failMessage:`Controlling element does not have attribute '${R}'.`,target:null};if(r=this.page.locator(`#${C}`),!r||await r.count()===0)return{success:!1,failMessage:`Controlled element with id '${C}' not found.`,target:null}}else{let n=await this.resolveTarget(t.target,t.relativeTarget||t.expectedValue,t.selectorKey);if(r=n.target,o=n.error,o||!r)return{success:!1,failMessage:o||`Target ${t.target} not found.`,target:null}}if(t.target==="input"&&t.attribute==="aria-activedescendant"&&t.expectedValue==="!empty"&&t.relativeTarget&&t.selectorKey){let n=await j.resolve(this.page,this.selectors[t.selectorKey],t.relativeTarget),u=n?await n.getAttribute("id"):null,i=await r.getAttribute("aria-activedescendant");return u&&i===u?{success:!0,passMessage:`input[aria-activedescendant] matches id of ${t.relativeTarget}(${t.selectorKey}). Test: "${s}".`}:{success:!1,failMessage:`input[aria-activedescendant] should match id of ${t.relativeTarget}(${t.selectorKey}), found "${i}".`}}switch(t.assertion){case"toBeVisible":return this.validateVisibility(r,t.target,!0,t.failureMessage||"",s);case"notToBeVisible":return this.validateVisibility(r,t.target,!1,t.failureMessage||"",s);case"toHaveAttribute":return t.attribute&&t.expectedValue!==void 0?this.validateAttribute(r,t.target,t.attribute,t.expectedValue,t.failureMessage||"",s):{success:!1,failMessage:"Missing attribute or expectedValue for toHaveAttribute assertion"};case"toHaveValue":return t.expectedValue!==void 0?this.validateValue(r,t.target,t.expectedValue,t.failureMessage||"",s):{success:!1,failMessage:"Missing expectedValue for toHaveValue assertion"};case"toHaveFocus":return this.validateFocus(r,t.target,!0,t.failureMessage||"",s);case"notToHaveFocus":return this.validateFocus(r,t.target,!1,t.failureMessage||"",s);case"toHaveRole":return t.expectedValue!==void 0?this.validateRole(r,t.target,t.expectedValue,t.failureMessage||"",s):{success:!1,failMessage:"Missing expectedValue for toHaveRole assertion"};default:return{success:!1,failMessage:`Unknown assertion type: ${t.assertion}`}}}};async function tt(M,t,s,r,o){let n=r?.test?.components?.find(d=>d.name===M),u=!!n?.contractPath,i=new ce(!0,u),R={actionTimeoutMs:400,assertionTimeoutMs:400,navigationTimeoutMs:3e4,componentReadyTimeoutMs:5e3},C=r?.test?.disableTimeouts===!0,te=n?.disableTimeouts===!0||C,_=(d,H,O)=>{if(te)return 0;let F=d??H;return typeof F!="number"||!Number.isFinite(F)||F<0?O:F},z=_(n?.actionTimeoutMs,r?.test?.actionTimeoutMs,R.actionTimeoutMs),X=_(n?.assertionTimeoutMs,r?.test?.assertionTimeoutMs,R.assertionTimeoutMs),ie=_(n?.navigationTimeoutMs,r?.test?.navigationTimeoutMs,R.navigationTimeoutMs),le=_(n?.componentReadyTimeoutMs,r?.test?.componentReadyTimeoutMs,R.componentReadyTimeoutMs),me=Se(s),Y=n?.contractPath;if(!Y)throw new Error(`Contract path not found for component: ${M}`);let Re=(()=>{if(he.isAbsolute(Y))return Y;if(o){let H=he.resolve(o,Y);try{return de(H,"utf-8"),H}catch{}}let d=he.resolve(process.cwd(),Y);try{return de(d,"utf-8"),d}catch{return new URL(Y,import.meta.url).pathname}})(),Ae=de(Re,"utf-8"),b=JSON.parse(Ae),Me=(b.relationships?.length||0)+(b.static[0]?.assertions.length||0)+b.dynamic.length,Ee=b.meta?.source?.apg,V=[],K=[],q=[],x=[],y=null,E=(d,H)=>{let O=Q(H),F=ke(O,me);if(F==="error")return V.push(d),{status:"fail",level:O,detail:d};if(F==="warning")return K.push(d),{status:"warn",level:O,detail:d};let D=`${d} (ignored by strictness=${me}, level=${O})`;return x.push(D),{status:"skip",level:O,detail:D}};try{if(y=await Te(),t){try{await y.goto(t,{waitUntil:"domcontentloaded",timeout:ie})}catch(e){throw new Error(`Failed to navigate to ${t}. Ensure dev server is running and accessible. Original error: ${e instanceof Error?e.message:String(e)}`)}await y.addStyleTag({content:"* { transition: none !important; animation: none !important; }"})}let d=await ae.detect(M,n,z,X,o);if(!d)throw new Error(`Unsupported component: ${M}`);let H=d.getMainSelector();if(!H)throw new Error(`CRITICAL: No selector found in contract for ${M}`);try{await y.locator(H).first().waitFor({state:"attached",timeout:le})}catch(e){throw new Error(`
|
|
22
|
+
\u274C Error: ${t}`),s&&this.log(` Context: ${s}`),this.log("")}};var ee=class{constructor(t,s,r=400){this.page=t;this.selectors=s;this.timeoutMs=r}isBrowserClosedError(t){return t instanceof Error&&t.message.includes("Target page, context or browser has been closed")}async focus(t,s,r){try{if(t==="virtual"&&r){let n=this.selectors.main;if(!n)return{success:!1,error:"Main selector not defined for virtual focus."};let u=this.page.locator(n).first();return await u.count()?(await u.evaluate((R,C)=>{R.setAttribute("aria-activedescendant",C)},r),{success:!0}):{success:!1,error:"Main element not found for virtual focus."}}if(t==="relative"&&s){let n=this.selectors.relative;if(!n)return{success:!1,error:"Relative selector not defined for focus action."};let u=await j.resolve(this.page,n,s);return u?(await u.focus({timeout:this.timeoutMs}),{success:!0}):{success:!1,error:`Could not resolve relative target ${s} for focus.`}}let o=this.selectors[t];return o?(await this.page.locator(o).first().focus({timeout:this.timeoutMs}),{success:!0}):{success:!1,error:`Selector for focus target ${t} not found.`}}catch(o){return this.isBrowserClosedError(o)?{success:!1,error:"CRITICAL: Browser/page closed during test execution. Remaining actions skipped.",shouldBreak:!0}:{success:!1,error:`Failed to focus ${t}: ${o instanceof Error?o.message:String(o)}`}}}async type(t,s){try{let r=this.selectors[t];return r?(await this.page.locator(r).first().fill(s,{timeout:this.timeoutMs}),{success:!0}):{success:!1,error:`Selector for type target ${t} not found.`}}catch(r){return this.isBrowserClosedError(r)?{success:!1,error:"CRITICAL: Browser/page closed during test execution. Remaining actions skipped.",shouldBreak:!0}:{success:!1,error:`Failed to type into ${t}: ${r instanceof Error?r.message:String(r)}`}}}async click(t,s){try{if(t==="document")return await this.page.mouse.click(10,10),{success:!0};if(t==="relative"&&s){let o=this.selectors.relative;if(!o)return{success:!1,error:"Relative selector not defined for click action."};let n=await j.resolve(this.page,o,s);return n?(await n.click({timeout:this.timeoutMs}),{success:!0}):{success:!1,error:`Could not resolve relative target ${s} for click.`}}let r=this.selectors[t];return r?(await this.page.locator(r).first().click({timeout:this.timeoutMs}),{success:!0}):{success:!1,error:`Selector for action target ${t} not found.`}}catch(r){return this.isBrowserClosedError(r)?{success:!1,error:"CRITICAL: Browser/page closed during test execution. Remaining actions skipped.",shouldBreak:!0}:{success:!1,error:`Failed to click ${t}: ${r instanceof Error?r.message:String(r)}`}}}async keypress(t,s,r){try{let n={Space:"Space",Enter:"Enter",Escape:"Escape","Arrow Up":"ArrowUp","Arrow Down":"ArrowDown","Arrow Left":"ArrowLeft","Arrow Right":"ArrowRight",Home:"Home",End:"End",Tab:"Tab"}[s]||s;if(n==="Space"?n=" ":n.includes(" ")&&(n=n.replace(/ /g,"")),t==="relative"){if(r==null)return{success:!1,error:"relativeTarget must be provided for relative keypress."};let C=this.selectors.relative;if(!C)return{success:!1,error:"Relative selector not defined for keypress action."};let A=await j.resolve(this.page,C,r);return A?(await A.press(n,{timeout:this.timeoutMs}),{success:!0}):{success:!1,error:`Could not resolve relative target ${r} for keypress.`}}let u=this.selectors[t];if(!u)return{success:!1,error:`Selector for keypress target ${t} not found.`};let i=this.page.locator(u).first();return await i.count()===0?{success:!1,error:`${t} element not found.`,shouldBreak:!0}:(await i.press(n,{timeout:this.timeoutMs}),{success:!0})}catch(o){return this.isBrowserClosedError(o)?{success:!1,error:"CRITICAL: Browser/page closed during test execution. Remaining actions skipped.",shouldBreak:!0}:{success:!1,error:`Failed to press ${s} on ${t}: ${o instanceof Error?o.message:String(o)}`}}}async hover(t,s){try{if(t==="relative"&&s){let o=this.selectors.relative;if(!o)return{success:!1,error:"Relative selector not defined for hover action."};let n=await j.resolve(this.page,o,s);return n?(await n.hover({timeout:this.timeoutMs}),{success:!0}):{success:!1,error:`Could not resolve relative target ${s} for hover.`}}let r=this.selectors[t];return r?(await this.page.locator(r).first().hover({timeout:this.timeoutMs}),{success:!0}):{success:!1,error:`Selector for hover target ${t} not found.`}}catch(r){return this.isBrowserClosedError(r)?{success:!1,error:"CRITICAL: Browser/page closed during test execution. Remaining actions skipped.",shouldBreak:!0}:{success:!1,error:`Failed to hover ${t}: ${r instanceof Error?r.message:String(r)}`}}}};var re=class{constructor(t,s,r=400){this.page=t;this.selectors=s;this.timeoutMs=r}async resolveTarget(t,s,r){try{if(t==="relative"){let n=r?this.selectors[r]:this.selectors.relative;if(!n)return{target:null,error:"Relative selector is not defined in the contract."};if(!s)return{target:null,error:"Relative target or expected value is not defined."};let u=await j.resolve(this.page,n,s);return u?{target:u}:{target:null,error:`Target ${t} not found.`}}let o=this.selectors[t];return o?{target:this.page.locator(o).first()}:{target:null,error:`Selector for assertion target ${t} not found.`}}catch(o){return{target:null,error:`Failed to resolve target ${t}: ${o instanceof Error?o.message:String(o)}`}}}async validateVisibility(t,s,r,o,n){try{return r?(await(0,N.expect)(t).toBeVisible({timeout:this.timeoutMs}),{success:!0,passMessage:`${s} is visible as expected. Test: "${n}".`}):(await(0,N.expect)(t).toBeHidden({timeout:this.timeoutMs}),{success:!0,passMessage:`${s} is not visible as expected. Test: "${n}".`})}catch{let u=this.selectors[s]||"",i=await this.page.evaluate(R=>{let C=R?document.querySelector(R):null;if(!C)return"element not found";let A=window.getComputedStyle(C);return`display:${A.display}, visibility:${A.visibility}, opacity:${A.opacity}`},u);return r?{success:!1,failMessage:`${o} (actual: ${i})`}:{success:!1,failMessage:`${o} ${s} is still visible (actual: ${i}).`}}}async validateAttribute(t,s,r,o,n,u){if(o==="!empty"){let C=await t.getAttribute(r);return C&&C.trim()!==""?{success:!0,passMessage:`${s} has non-empty "${r}". Test: "${u}".`}:{success:!1,failMessage:`${n} ${s} "${r}" should not be empty, found "${C}".`}}if(typeof o!="string")throw console.error("[AssertionRunner] expectedValue is not a string:",o),new Error(`AssertionRunner: expectedValue for attribute assertion must be a string, but got: ${JSON.stringify(o)}`);let i=o.split(" | ").map(C=>C.trim()),R=await t.getAttribute(r);return R!==null&&i.includes(R)?{success:!0,passMessage:`${s} has expected "${r}". Test: "${u}".`}:{success:!1,failMessage:`${n} ${s} "${r}" should be "${o}", found "${R}".`}}async validateValue(t,s,r,o,n){let u=await t.inputValue().catch(()=>"");return r==="!empty"?u&&u.trim()!==""?{success:!0,passMessage:`${s} has non-empty value. Test: "${n}".`}:{success:!1,failMessage:`${o} ${s} value should not be empty, found "${u}".`}:r===""?u===""?{success:!0,passMessage:`${s} has empty value. Test: "${n}".`}:{success:!1,failMessage:`${o} ${s} value should be empty, found "${u}".`}:u===r?{success:!0,passMessage:`${s} has expected value. Test: "${n}".`}:{success:!1,failMessage:`${o} ${s} value should be "${r}", found "${u}".`}}async validateFocus(t,s,r,o,n){try{return r?(await(0,N.expect)(t).toBeFocused({timeout:this.timeoutMs}),{success:!0,passMessage:`${s} has focus as expected. Test: "${n}".`}):(await(0,N.expect)(t).not.toBeFocused({timeout:this.timeoutMs}),{success:!0,passMessage:`${s} does not have focus as expected. Test: "${n}".`})}catch{let u=await this.page.evaluate(()=>{let i=document.activeElement;return i?`${i.tagName}#${i.id||"no-id"}.${i.className||"no-class"}`:"no element focused"});return{success:!1,failMessage:`${o} (actual focus: ${u})`}}}async validateRole(t,s,r,o,n){let u=await t.getAttribute("role");return u===r?{success:!0,passMessage:`${s} has role "${r}". Test: "${n}".`}:{success:!1,failMessage:`${o} Expected role "${r}", found "${u}".`}}async validate(t,s){if(this.page.isClosed())return{success:!1,failMessage:"CRITICAL: Browser/page closed before completing all tests. Increase test timeout or reduce test complexity."};let r=null,o;if(t.controlledBy){let n=t.controlledBy,u=this.selectors[n.target];if(!u)return{success:!1,failMessage:`Selector for controlledBy.target '${n.target}' not found.`,target:null};let i=null;if(n.relativeTarget?i=await j.resolve(this.page,u,n.relativeTarget):i=this.page.locator(u).first(),!i)return{success:!1,failMessage:"Controlling element for controlledBy not found.",target:null};let R=n.attribute||"aria-controls",C=await i.getAttribute(R);if(!C)return{success:!1,failMessage:`Controlling element does not have attribute '${R}'.`,target:null};if(r=this.page.locator(`#${C}`),!r||await r.count()===0)return{success:!1,failMessage:`Controlled element with id '${C}' not found.`,target:null}}else{let n=await this.resolveTarget(t.target,t.relativeTarget||t.expectedValue,t.selectorKey);if(r=n.target,o=n.error,o||!r)return{success:!1,failMessage:o||`Target ${t.target} not found.`,target:null}}if(t.target==="input"&&t.attribute==="aria-activedescendant"&&t.expectedValue==="!empty"&&t.relativeTarget&&t.selectorKey){let n=await j.resolve(this.page,this.selectors[t.selectorKey],t.relativeTarget),u=n?await n.getAttribute("id"):null,i=await r.getAttribute("aria-activedescendant");return u&&i===u?{success:!0,passMessage:`input[aria-activedescendant] matches id of ${t.relativeTarget}(${t.selectorKey}). Test: "${s}".`}:{success:!1,failMessage:`input[aria-activedescendant] should match id of ${t.relativeTarget}(${t.selectorKey}), found "${i}".`}}switch(t.assertion){case"toBeVisible":return this.validateVisibility(r,t.target,!0,t.failureMessage||"",s);case"notToBeVisible":return this.validateVisibility(r,t.target,!1,t.failureMessage||"",s);case"toHaveAttribute":return t.attribute&&t.expectedValue!==void 0?this.validateAttribute(r,t.target,t.attribute,t.expectedValue,t.failureMessage||"",s):{success:!1,failMessage:"Missing attribute or expectedValue for toHaveAttribute assertion"};case"toHaveValue":return t.expectedValue!==void 0?this.validateValue(r,t.target,t.expectedValue,t.failureMessage||"",s):{success:!1,failMessage:"Missing expectedValue for toHaveValue assertion"};case"toHaveFocus":return this.validateFocus(r,t.target,!0,t.failureMessage||"",s);case"notToHaveFocus":return this.validateFocus(r,t.target,!1,t.failureMessage||"",s);case"toHaveRole":return t.expectedValue!==void 0?this.validateRole(r,t.target,t.expectedValue,t.failureMessage||"",s):{success:!1,failMessage:"Missing expectedValue for toHaveRole assertion"};default:return{success:!1,failMessage:`Unknown assertion type: ${t.assertion}`}}}};async function tt(M,t,s,r,o){let n=r?.test?.components?.find(d=>d.name===M),u=!!n?.contractPath,i=new ce(!0,u),R={actionTimeoutMs:400,assertionTimeoutMs:400,navigationTimeoutMs:3e4,componentReadyTimeoutMs:5e3},C=r?.test?.disableTimeouts===!0,te=n?.disableTimeouts===!0||C,_=(d,H,O)=>{if(te)return 0;let F=d??H;return typeof F!="number"||!Number.isFinite(F)||F<0?O:F},z=_(n?.actionTimeoutMs,r?.test?.actionTimeoutMs,R.actionTimeoutMs),X=_(n?.assertionTimeoutMs,r?.test?.assertionTimeoutMs,R.assertionTimeoutMs),ie=_(n?.navigationTimeoutMs,r?.test?.navigationTimeoutMs,R.navigationTimeoutMs),le=_(n?.componentReadyTimeoutMs,r?.test?.componentReadyTimeoutMs,R.componentReadyTimeoutMs),me=Se(s),Y=n?.contractPath;if(!Y)throw new Error(`Contract path not found for component: ${M}`);let Re=(()=>{if(he.isAbsolute(Y))return Y;if(o){let H=he.resolve(o,Y);try{return de(H,"utf-8"),H}catch{}}let d=he.resolve(process.cwd(),Y);try{return de(d,"utf-8"),d}catch{return new URL(Y,import.meta.url).pathname}})(),Ae=de(Re,"utf-8"),b=JSON.parse(Ae),Me=(b.relationships?.length||0)+(b.static.length||0)+b.dynamic.length,Ee=b.meta?.source?.apg,V=[],K=[],q=[],x=[],y=null,E=(d,H)=>{let O=Q(H),F=ke(O,me);if(F==="error")return V.push(d),{status:"fail",level:O,detail:d};if(F==="warning")return K.push(d),{status:"warn",level:O,detail:d};let D=`${d} (ignored by strictness=${me}, level=${O})`;return x.push(D),{status:"skip",level:O,detail:D}};try{if(y=await Te(),t){try{await y.goto(t,{waitUntil:"domcontentloaded",timeout:ie})}catch(e){throw new Error(`Failed to navigate to ${t}. Ensure dev server is running and accessible. Original error: ${e instanceof Error?e.message:String(e)}`)}await y.addStyleTag({content:"* { transition: none !important; animation: none !important; }"})}let d=await ae.detect(M,n,z,X,o);if(!d)throw new Error(`Unsupported component: ${M}`);let H=d.getMainSelector();if(!H)throw new Error(`CRITICAL: No selector found in contract for ${M}`);try{await y.locator(H).first().waitFor({state:"attached",timeout:le})}catch(e){throw new Error(`
|
|
23
23
|
\u274C CRITICAL: Component not found on page!
|
|
24
24
|
This usually means:
|
|
25
25
|
- The component didn't render
|
|
26
26
|
- The URL is incorrect
|
|
27
27
|
- The component selector '${H}' in the contract is wrong
|
|
28
|
-
- Original error: ${e}`)}i.start(M,Me,Ee),M==="menu"&&b.selectors.main&&await y.locator(b.selectors.main).first().waitFor({state:"visible",timeout:le}).catch(()=>{});let O=M==="menu"&&b.selectors.submenuTrigger?await y.locator(b.selectors.submenuTrigger).count()>0:!1,F=e=>e.type==="aria-reference"&&[e.from,e.to].some(p=>["submenu","submenuTrigger","submenuItems"].includes(p||""))||e.type==="contains"&&[e.parent,e.child].some(p=>["submenu","submenuTrigger","submenuItems"].includes(p||"")),D=0,P=0,I=0;for(let e of b.relationships||[]){if(d&&typeof d.resetState=="function")try{await d.resetState(y)}catch(g){K.push(`Warning: resetState failed before relationship test: ${g instanceof Error?g.message:String(g)}`)}let p=Q(e.level);if(Array.isArray(e.setup)&&e.setup.length>0){let w=function(l){return h.includes(l)};var ve=w;let g=new ee(y,b.selectors,z),S=e.type==="aria-reference"?`${e.from}.${e.attribute} references ${e.to}`:`${e.parent} contains ${e.child}`,h=["focus","type","click","keypress","hover"],m=l=>({...l,type:w(l.type)?l.type:"click"}),$=e.setup.map(m),k=await ue($,g,d,y,S,["submenu","submenuTrigger","submenuItems"]);if(k.skip){x.push(k.message||"Setup action skipped"),i.reportStaticTest(S,"skip",k.message,p);continue}if(!k.success){let l=`Relationship setup failed: ${k.error}`,c=E(l,e.level);c.status==="fail"&&(P+=1),c.status==="warn"&&(I+=1),i.reportStaticTest(S,c.status,c.detail,c.level);continue}}if(M==="menu"&&!O&&F(e)){let S=e.type==="aria-reference"?`${e.from}.${e.attribute} references ${e.to}`:`${e.parent} contains ${e.child}`,h="Skipping submenu relationship assertion: no submenu capability detected in rendered component.";x.push(h),i.reportStaticTest(S,"skip",h,p);continue}if(e.type==="aria-reference"){let g=`${e.from}.${e.attribute} references ${e.to}`,S=b.selectors[e.from],h=b.selectors[e.to];if(!S||!h){let f=E(`Relationship selector missing: from="${e.from}" or to="${e.to}" not found in selectors.`,e.level);f.status==="fail"&&(P+=1),f.status==="warn"&&(I+=1),i.reportStaticTest(g,f.status,f.detail,f.level);continue}let w=y.locator(S).first(),m=y.locator(h).first(),$=await w.count()>0,k=await m.count()>0;if(!$||!k){if(M==="menu"&&F(e)){let B="Skipping submenu relationship assertion in static phase: submenu elements are not present until submenu is opened.";x.push(B),i.reportStaticTest(g,"skip",B,p);continue}let f=E(`Relationship target not found: ${$?e.to:e.from}.`,e.level);f.status==="fail"&&(P+=1),f.status==="warn"&&(I+=1),i.reportStaticTest(g,f.status,f.detail,f.level);continue}let l=await w.getAttribute(e.attribute),c=await m.getAttribute("id");if(!c){let f=E(`Relationship target "${e.to}" must have an id for ${e.attribute} validation.`,e.level);f.status==="fail"&&(P+=1),f.status==="warn"&&(I+=1),i.reportStaticTest(g,f.status,f.detail,f.level);continue}if(!(l||"").split(/\s+/).filter(Boolean).includes(c)){let f=E(`Expected ${e.from} ${e.attribute} to reference id "${c}", found "${l||""}".`,e.level);f.status==="fail"&&(P+=1),f.status==="warn"&&(I+=1),i.reportStaticTest(g,f.status,f.detail,f.level);continue}q.push(`Relationship valid: ${e.from}.${e.attribute} -> ${e.to} (id=${c}).`),D+=1,i.reportStaticTest(g,"pass",void 0,p);continue}if(e.type==="contains"){let g=`${e.parent} contains ${e.child}`,S=b.selectors[e.parent],h=b.selectors[e.child];if(!S||!h){let l=E(`Relationship selector missing: parent="${e.parent}" or child="${e.child}" not found in selectors.`,e.level);l.status==="fail"&&(P+=1),l.status==="warn"&&(I+=1),i.reportStaticTest(g,l.status,l.detail,l.level);continue}let w=y.locator(S).first();if(!(await w.count()>0)){if(M==="menu"&&F(e)){let c="Skipping submenu relationship assertion in static phase: submenu container is not present until submenu is opened.";x.push(c),i.reportStaticTest(g,"skip",c,p);continue}let l=E(`Relationship parent target not found: ${e.parent}.`,e.level);l.status==="fail"&&(P+=1),l.status==="warn"&&(I+=1),i.reportStaticTest(g,l.status,l.detail,l.level);continue}if(await w.locator(h).count()<1){if(M==="menu"&&F(e)){let c="Skipping submenu relationship assertion in static phase: submenu descendants are not present until submenu is opened.";x.push(c),i.reportStaticTest(g,"skip",c,p);continue}let l=E(`Expected ${e.parent} to contain descendant matching selector for ${e.child}.`,e.level);l.status==="fail"&&(P+=1),l.status==="warn"&&(I+=1),i.reportStaticTest(g,l.status,l.detail,l.level);continue}q.push(`Relationship valid: ${e.parent} contains ${e.child}.`),D+=1,i.reportStaticTest(g,"pass",void 0,p)}}async function ye(e,p,g,S={}){if(!e||typeof e!="object"||!("ref"in e))return e;let h;if(e.ref==="relative"){if(!e.relativeTarget||!S.relativeBaseSelector)return;let w=g.locator(S.relativeBaseSelector),m=await w.count(),$=0;if(e.relativeTarget==="first"?$=0:e.relativeTarget==="second"?$=1:e.relativeTarget==="last"?$=m-1:isNaN(Number(e.relativeTarget))?$=0:$=Number(e.relativeTarget),$<0||$>=m)return;let k=w.nth($);return await we(k,e.property||e.attribute)}else{if(h=p[e.ref],!h)throw new Error(`Selector for ref '${e.ref}' not found in contract selectors.`);let w=g.locator(h).first();return await we(w,e.property||e.attribute)}}async function we(e,p){if(e)return!p||p==="id"?await e.getAttribute("id")??void 0:p==="class"?await e.getAttribute("class")??void 0:p==="textContent"?await e.evaluate(g=>g.textContent??void 0):p.startsWith("aria-")?await e.getAttribute(p)??void 0:p.endsWith("*")?await e.evaluate(S=>{let h=[];for(let w of Array.from(S.attributes))w.name.startsWith("aria-")&&h.push(`${w.name}=${w.value}`);return h.join(";")}):await e.getAttribute(p)??void 0}let xe=new re(y,b.selectors,X);async function ue(e,p,g,S,h,w=[]){if(!Array.isArray(e)||e.length===0)return{success:!0};g&&typeof g.resetState=="function"&&await g.resetState(S);for(let m of e){let $={success:!0};try{if(m.type==="focus")m.target==="relative"&&m.relativeTarget?$=await p.focus("relative",m.relativeTarget):$=await p.focus(m.target);else if(m.type==="type"&&m.value)$=await p.type(m.target,m.value);else if(m.type==="click")$=await p.click(m.target,m.relativeTarget);else if(m.type==="keypress"&&m.key)$=await p.keypress(m.target,m.key,m.relativeTarget);else if(m.type==="hover")$=await p.hover(m.target,m.relativeTarget);else continue}catch(k){$={success:!1,error:k instanceof Error?k.message:String(k)}}if(!$.success){let k=$.error||"Setup action failed";return w.some(c=>h.includes(c)||k.includes(c))?{success:!1,skip:!0,message:`Skipping test - capability not present: ${k}`}:{success:!1,error:k}}}return{success:!0}}for(let e of b.static[0]?.assertions||[]){if(d&&typeof d.resetState=="function")try{await d.resetState(y)}catch(l){K.push(`Warning: resetState failed before static test: ${l instanceof Error?l.message:String(l)}`)}if(e.target==="relative")continue;let p=`${e.target}${e.attribute?` (${e.attribute})`:""}`,g=Q(e.level);if(M==="menu"&&e.target==="submenuTrigger"&&!O){let l=`Skipping submenu static assertion for ${e.target}: no submenu capability detected in rendered component.`;x.push(l),i.reportStaticTest(p,"skip",l,g);continue}let S=[];if(e.target||S.push("target"),e.attribute||S.push("attribute"),typeof e.expectedValue>"u"&&S.push("expectedValue"),S.length>0){let l=`${e.target||""}${e.attribute?` (${e.attribute})`:""}`,c=`Static assertion missing required field(s): ${S.join(", ")}`,v=E(c,e.level);v.status==="fail"&&(P+=1),v.status==="warn"&&(I+=1),i.reportStaticTest(l,v.status,v.detail,v.level);continue}if(Array.isArray(e.setup)&&e.setup.length>0){let v=function(a){return c.includes(a)};var ve=v;let l=new ee(y,b.selectors,z),c=["focus","type","click","keypress","hover"],U=a=>({...a,type:v(a.type)?a.type:"click"}),f=e.setup.map(U),B=await ue(f,l,d,y,p,["submenu","submenuTrigger","submenuItems"]);if(B.skip){x.push(B.message||"Setup action skipped"),i.reportStaticTest(p,"skip",B.message,g);continue}if(!B.success){let a=`Static setup failed: ${B.error}`,T=E(a,e.level);T.status==="fail"&&(P+=1),T.status==="warn"&&(I+=1),i.reportStaticTest(p,T.status,T.detail,T.level);continue}}let h=b.selectors[e.target];if(!h){let l=`Selector for target ${e.target} not found.`,c=E(l,e.level);c.status==="fail"&&(P+=1),c.status==="warn"&&(I+=1),i.reportStaticTest(p,c.status,c.detail,c.level);continue}let w=y.locator(h).first();if(!(await w.count()>0)){let l=`Target ${e.target} not found.`,c=E(l,e.level);c.status==="fail"&&(P+=1),c.status==="warn"&&(I+=1),i.reportStaticTest(p,c.status,c.detail,c.level);continue}let $=(l,c,v)=>{let U=new RegExp(`\\[${c}(?:=["']?([^\\]"']+)["']?)?\\]`),f=l.match(U);if(!f)return!1;if(!v)return!0;let B=f[1];return B?v.split(" | ").includes(B):!1},k=e.expectedValue;if(e.expectedValue&&typeof e.expectedValue=="object"&&"ref"in e.expectedValue){let l={},c=e.relativeTarget;if(e.expectedValue.ref==="relative"&&e.target==="relative"&&c){let v=b.selectors[c];if(!v)throw new Error(`Selector for relativeTarget '${c}' not found in contract selectors.`);l.relativeBaseSelector=v}else if(e.expectedValue.ref==="relative"&&c){let v=b.selectors[c];if(!v)throw new Error(`Selector for relativeTarget '${c}' not found in contract selectors.`);l.relativeBaseSelector=v}k=await ye(e.expectedValue,b.selectors,y,l)}if(e.expectedValue)if($(h,e.attribute,typeof k=="string"?k:void 0))q.push(`${e.attribute}="${k}" on ${e.target} verified by selector (already present in: ${h}).`),D+=1,i.reportStaticTest(p,"pass",void 0,g);else{let l=k??"",c=await xe.validateAttribute(w,e.target,e.attribute,l,e.failureMessage,"Static ARIA Test");if(c.success&&c.passMessage)q.push(c.passMessage),D+=1,i.reportStaticTest(p,"pass",void 0,g);else if(!c.success&&c.failMessage){let v=E(c.failMessage,e.level);v.status==="fail"&&(P+=1),v.status==="warn"&&(I+=1),i.reportStaticTest(p,v.status,v.detail,v.level)}}else{let l=e.attribute.split(" | "),c=!1,v=!0;for(let U of l){let f=U.trim();if($(h,f)){q.push(`${f} on ${e.target} verified by selector (already present in: ${h}).`),c=!0;continue}if(v=!1,await w.getAttribute(f)!==null){c=!0;break}}if(!c&&!v){let U=e.failureMessage+` None of the attributes "${e.attribute}" are present.`,f=E(U,e.level);f.status==="fail"&&(P+=1),f.status==="warn"&&(I+=1),i.reportStaticTest(p,f.status,f.detail,f.level)}else!v&&c?(q.push(`At least one of the attributes "${e.attribute}" exists on the element.`),D+=1,i.reportStaticTest(p,"pass",void 0,g)):(D+=1,i.reportStaticTest(p,"pass",void 0,g))}}for(let e of b.dynamic||[]){if(!e.assertions||e.assertions.length===0){let a="Skipping test - no assertions found for this dynamic test.";x.push(a),i.reportTest({description:e.description,level:Q(e.level)},"skip",a);continue}if(!y||y.isClosed()){console.warn(`
|
|
28
|
+
- Original error: ${e}`)}i.start(M,Me,Ee),M==="menu"&&b.selectors.main&&await y.locator(b.selectors.main).first().waitFor({state:"visible",timeout:le}).catch(()=>{});let O=M==="menu"&&b.selectors.submenuTrigger?await y.locator(b.selectors.submenuTrigger).count()>0:!1,F=e=>e.type==="aria-reference"&&[e.from,e.to].some(p=>["submenu","submenuTrigger","submenuItems"].includes(p||""))||e.type==="contains"&&[e.parent,e.child].some(p=>["submenu","submenuTrigger","submenuItems"].includes(p||"")),D=0,P=0,I=0;for(let e of b.relationships||[]){if(d&&typeof d.resetState=="function")try{await d.resetState(y)}catch(g){K.push(`Warning: resetState failed before relationship test: ${g instanceof Error?g.message:String(g)}`)}let p=Q(e.level);if(Array.isArray(e.setup)&&e.setup.length>0){let w=function(l){return h.includes(l)};var ve=w;let g=new ee(y,b.selectors,z),S=e.type==="aria-reference"?`${e.from}.${e.attribute} references ${e.to}`:`${e.parent} contains ${e.child}`,h=["focus","type","click","keypress","hover"],m=l=>({...l,type:w(l.type)?l.type:"click"}),$=e.setup.map(m),k=await ue($,g,d,y,S,["submenu","submenuTrigger","submenuItems"]);if(k.skip){x.push(k.message||"Setup action skipped"),i.reportStaticTest(S,"skip",k.message,p);continue}if(!k.success){let l=`Relationship setup failed: ${k.error}`,c=E(l,e.level);c.status==="fail"&&(P+=1),c.status==="warn"&&(I+=1),i.reportStaticTest(S,c.status,c.detail,c.level);continue}}if(M==="menu"&&!O&&F(e)){let S=e.type==="aria-reference"?`${e.from}.${e.attribute} references ${e.to}`:`${e.parent} contains ${e.child}`,h="Skipping submenu relationship assertion: no submenu capability detected in rendered component.";x.push(h),i.reportStaticTest(S,"skip",h,p);continue}if(e.type==="aria-reference"){let g=`${e.from}.${e.attribute} references ${e.to}`,S=b.selectors[e.from],h=b.selectors[e.to];if(!S||!h){let f=E(`Relationship selector missing: from="${e.from}" or to="${e.to}" not found in selectors.`,e.level);f.status==="fail"&&(P+=1),f.status==="warn"&&(I+=1),i.reportStaticTest(g,f.status,f.detail,f.level);continue}let w=y.locator(S).first(),m=y.locator(h).first(),$=await w.count()>0,k=await m.count()>0;if(!$||!k){if(M==="menu"&&F(e)){let B="Skipping submenu relationship assertion in static phase: submenu elements are not present until submenu is opened.";x.push(B),i.reportStaticTest(g,"skip",B,p);continue}let f=E(`Relationship target not found: ${$?e.to:e.from}.`,e.level);f.status==="fail"&&(P+=1),f.status==="warn"&&(I+=1),i.reportStaticTest(g,f.status,f.detail,f.level);continue}let l=await w.getAttribute(e.attribute),c=await m.getAttribute("id");if(!c){let f=E(`Relationship target "${e.to}" must have an id for ${e.attribute} validation.`,e.level);f.status==="fail"&&(P+=1),f.status==="warn"&&(I+=1),i.reportStaticTest(g,f.status,f.detail,f.level);continue}if(!(l||"").split(/\s+/).filter(Boolean).includes(c)){let f=E(`Expected ${e.from} ${e.attribute} to reference id "${c}", found "${l||""}".`,e.level);f.status==="fail"&&(P+=1),f.status==="warn"&&(I+=1),i.reportStaticTest(g,f.status,f.detail,f.level);continue}q.push(`Relationship valid: ${e.from}.${e.attribute} -> ${e.to} (id=${c}).`),D+=1,i.reportStaticTest(g,"pass",void 0,p);continue}if(e.type==="contains"){let g=`${e.parent} contains ${e.child}`,S=b.selectors[e.parent],h=b.selectors[e.child];if(!S||!h){let l=E(`Relationship selector missing: parent="${e.parent}" or child="${e.child}" not found in selectors.`,e.level);l.status==="fail"&&(P+=1),l.status==="warn"&&(I+=1),i.reportStaticTest(g,l.status,l.detail,l.level);continue}let w=y.locator(S).first();if(!(await w.count()>0)){if(M==="menu"&&F(e)){let c="Skipping submenu relationship assertion in static phase: submenu container is not present until submenu is opened.";x.push(c),i.reportStaticTest(g,"skip",c,p);continue}let l=E(`Relationship parent target not found: ${e.parent}.`,e.level);l.status==="fail"&&(P+=1),l.status==="warn"&&(I+=1),i.reportStaticTest(g,l.status,l.detail,l.level);continue}if(await w.locator(h).count()<1){if(M==="menu"&&F(e)){let c="Skipping submenu relationship assertion in static phase: submenu descendants are not present until submenu is opened.";x.push(c),i.reportStaticTest(g,"skip",c,p);continue}let l=E(`Expected ${e.parent} to contain descendant matching selector for ${e.child}.`,e.level);l.status==="fail"&&(P+=1),l.status==="warn"&&(I+=1),i.reportStaticTest(g,l.status,l.detail,l.level);continue}q.push(`Relationship valid: ${e.parent} contains ${e.child}.`),D+=1,i.reportStaticTest(g,"pass",void 0,p)}}async function ye(e,p,g,S={}){if(!e||typeof e!="object"||!("ref"in e))return e;let h;if(e.ref==="relative"){if(!e.relativeTarget||!S.relativeBaseSelector)return;let w=g.locator(S.relativeBaseSelector),m=await w.count(),$=0;if(e.relativeTarget==="first"?$=0:e.relativeTarget==="second"?$=1:e.relativeTarget==="last"?$=m-1:isNaN(Number(e.relativeTarget))?$=0:$=Number(e.relativeTarget),$<0||$>=m)return;let k=w.nth($);return await we(k,e.property||e.attribute)}else{if(h=p[e.ref],!h)throw new Error(`Selector for ref '${e.ref}' not found in contract selectors.`);let w=g.locator(h).first();return await we(w,e.property||e.attribute)}}async function we(e,p){if(e)return!p||p==="id"?await e.getAttribute("id")??void 0:p==="class"?await e.getAttribute("class")??void 0:p==="textContent"?await e.evaluate(g=>g.textContent??void 0):p.startsWith("aria-")?await e.getAttribute(p)??void 0:p.endsWith("*")?await e.evaluate(S=>{let h=[];for(let w of Array.from(S.attributes))w.name.startsWith("aria-")&&h.push(`${w.name}=${w.value}`);return h.join(";")}):await e.getAttribute(p)??void 0}let xe=new re(y,b.selectors,X);async function ue(e,p,g,S,h,w=[]){if(!Array.isArray(e)||e.length===0)return{success:!0};g&&typeof g.resetState=="function"&&await g.resetState(S);for(let m of e){let $={success:!0};try{if(m.type==="focus")m.target==="relative"&&m.relativeTarget?$=await p.focus("relative",m.relativeTarget):$=await p.focus(m.target);else if(m.type==="type"&&m.value)$=await p.type(m.target,m.value);else if(m.type==="click")$=await p.click(m.target,m.relativeTarget);else if(m.type==="keypress"&&m.key)$=await p.keypress(m.target,m.key,m.relativeTarget);else if(m.type==="hover")$=await p.hover(m.target,m.relativeTarget);else continue}catch(k){$={success:!1,error:k instanceof Error?k.message:String(k)}}if(!$.success){let k=$.error||"Setup action failed";return w.some(c=>h.includes(c)||k.includes(c))?{success:!1,skip:!0,message:`Skipping test - capability not present: ${k}`}:{success:!1,error:k}}}return{success:!0}}for(let e of b.static||[]){if(d&&typeof d.resetState=="function")try{await d.resetState(y)}catch(l){K.push(`Warning: resetState failed before static test: ${l instanceof Error?l.message:String(l)}`)}if(e.target==="relative")continue;let p=`${e.target}${e.attribute?` (${e.attribute})`:""}`,g=Q(e.level);if(M==="menu"&&e.target==="submenuTrigger"&&!O){let l=`Skipping submenu static assertion for ${e.target}: no submenu capability detected in rendered component.`;x.push(l),i.reportStaticTest(p,"skip",l,g);continue}let S=[];if(e.target||S.push("target"),e.attribute||S.push("attribute"),typeof e.expectedValue>"u"&&S.push("expectedValue"),S.length>0){let l=`${e.target||""}${e.attribute?` (${e.attribute})`:""}`,c=`Static assertion missing required field(s): ${S.join(", ")}`,v=E(c,e.level);v.status==="fail"&&(P+=1),v.status==="warn"&&(I+=1),i.reportStaticTest(l,v.status,v.detail,v.level);continue}if(Array.isArray(e.setup)&&e.setup.length>0){let v=function(a){return c.includes(a)};var ve=v;let l=new ee(y,b.selectors,z),c=["focus","type","click","keypress","hover"],U=a=>({...a,type:v(a.type)?a.type:"click"}),f=e.setup.map(U),B=await ue(f,l,d,y,p,["submenu","submenuTrigger","submenuItems"]);if(B.skip){x.push(B.message||"Setup action skipped"),i.reportStaticTest(p,"skip",B.message,g);continue}if(!B.success){let a=`Static setup failed: ${B.error}`,T=E(a,e.level);T.status==="fail"&&(P+=1),T.status==="warn"&&(I+=1),i.reportStaticTest(p,T.status,T.detail,T.level);continue}}let h=b.selectors[e.target];if(!h){let l=`Selector for target ${e.target} not found.`,c=E(l,e.level);c.status==="fail"&&(P+=1),c.status==="warn"&&(I+=1),i.reportStaticTest(p,c.status,c.detail,c.level);continue}let w=y.locator(h).first();if(!(await w.count()>0)){let l=`Target ${e.target} not found.`,c=E(l,e.level);c.status==="fail"&&(P+=1),c.status==="warn"&&(I+=1),i.reportStaticTest(p,c.status,c.detail,c.level);continue}let $=(l,c,v)=>{let U=new RegExp(`\\[${c}(?:=["']?([^\\]"']+)["']?)?\\]`),f=l.match(U);if(!f)return!1;if(!v)return!0;let B=f[1];return B?v.split(" | ").includes(B):!1},k=e.expectedValue;if(e.expectedValue&&typeof e.expectedValue=="object"&&"ref"in e.expectedValue){let l={},c=e.relativeTarget;if(e.expectedValue.ref==="relative"&&e.target==="relative"&&c){let v=b.selectors[c];if(!v)throw new Error(`Selector for relativeTarget '${c}' not found in contract selectors.`);l.relativeBaseSelector=v}else if(e.expectedValue.ref==="relative"&&c){let v=b.selectors[c];if(!v)throw new Error(`Selector for relativeTarget '${c}' not found in contract selectors.`);l.relativeBaseSelector=v}k=await ye(e.expectedValue,b.selectors,y,l)}if(e.expectedValue)if($(h,e.attribute,typeof k=="string"?k:void 0))q.push(`${e.attribute}="${k}" on ${e.target} verified by selector (already present in: ${h}).`),D+=1,i.reportStaticTest(p,"pass",void 0,g);else{let l=k??"",c=await xe.validateAttribute(w,e.target,e.attribute,l,e.failureMessage,"Static ARIA Test");if(c.success&&c.passMessage)q.push(c.passMessage),D+=1,i.reportStaticTest(p,"pass",void 0,g);else if(!c.success&&c.failMessage){let v=E(c.failMessage,e.level);v.status==="fail"&&(P+=1),v.status==="warn"&&(I+=1),i.reportStaticTest(p,v.status,v.detail,v.level)}}else{let l=e.attribute.split(" | "),c=!1,v=!0;for(let U of l){let f=U.trim();if($(h,f)){q.push(`${f} on ${e.target} verified by selector (already present in: ${h}).`),c=!0;continue}if(v=!1,await w.getAttribute(f)!==null){c=!0;break}}if(!c&&!v){let U=e.failureMessage+` None of the attributes "${e.attribute}" are present.`,f=E(U,e.level);f.status==="fail"&&(P+=1),f.status==="warn"&&(I+=1),i.reportStaticTest(p,f.status,f.detail,f.level)}else!v&&c?(q.push(`At least one of the attributes "${e.attribute}" exists on the element.`),D+=1,i.reportStaticTest(p,"pass",void 0,g)):(D+=1,i.reportStaticTest(p,"pass",void 0,g))}}for(let e of b.dynamic||[]){if(!e.assertions||e.assertions.length===0){let a="Skipping test - no assertions found for this dynamic test.";x.push(a),i.reportTest({description:e.description,level:Q(e.level)},"skip",a);continue}if(!y||y.isClosed()){console.warn(`
|
|
29
29
|
\u26A0\uFE0F Browser closed - skipping remaining ${b.dynamic.length-b.dynamic.indexOf(e)} tests
|
|
30
30
|
`),V.push(`CRITICAL: Browser/page closed before completing all tests. ${b.dynamic.length-b.dynamic.indexOf(e)} tests skipped.`);break}try{await d.resetState(y)}catch(a){let T=a instanceof Error?a.message:String(a);throw i.error(T),a}let{setup:p=[],action:g,assertions:S}=e,h=Q(e.level),w=new ee(y,b.selectors,z);if(Array.isArray(p)&&p.length>0){let T=function(L){return a.includes(L)};var ve=T;let a=["focus","type","click","keypress","hover"],Z=L=>({...L,type:T(L.type)?L.type:"click"}),pe=p.map(Z),W=await ue(pe,w,d,y,e.description,["submenu","submenuTrigger","submenuItems"]);if(W.skip){x.push(W.message||"Setup action skipped"),i.reportTest({description:e.description,level:h},"skip",W.message);continue}if(!W.success){let L=E(`Setup failed: ${W.error}`,e.level);i.reportTest({description:e.description,level:h},L.status,L.detail);continue}}let m=V.length,$=K.length,k=x.length;if(await d.shouldSkipTest(e,y)){let a="Skipping test - component-specific conditions not met";x.push(a),i.reportTest({description:e.description,level:h},"skip",a);continue}let c=new re(y,b.selectors,X),v=!1,U=null;for(let a of g){if(!y||y.isClosed()){V.push("CRITICAL: Browser/page closed during test execution. Remaining actions skipped."),v=!0;break}let T;if(a.type==="focus")a.target==="relative"&&a.relativeTarget?T=await w.focus("relative",a.relativeTarget):T=await w.focus(a.target);else if(a.type==="type"&&a.value)T=await w.type(a.target,a.value);else if(a.type==="click")T=await w.click(a.target,a.relativeTarget);else if(a.type==="keypress"&&a.key)T=await w.keypress(a.target,a.key,a.relativeTarget);else if(a.type==="hover")T=await w.hover(a.target,a.relativeTarget);else continue;if(!T.success){if(T.error){let Z=E(T.error,e.level);U={status:Z.status,detail:Z.detail}}v=!0;break}}if(v){i.reportTest({description:e.description,level:h},U?.status||"fail",U?.detail||V[V.length-1]);continue}for(let a of S){let T;if(a.expectedValue&&typeof a.expectedValue=="object"&&"ref"in a.expectedValue)if(a.expectedValue.ref==="relative"){let{RelativeTargetResolver:J}=await import("./RelativeTargetResolver-PDJM3ZJI.js"),L=b.selectors.relative;if(!L)throw new Error("Relative selector not defined in contract selectors.");let se=a.relativeTarget||"first",G=await J.resolve(y,L,se);if(!G)throw new Error(`Could not resolve relative target '${se}' for expectedValue.`);let $e=a.expectedValue.property||a.expectedValue.attribute||"id";if($e==="textContent")T=await G.evaluate(ne=>ne.textContent??void 0);else{let ne=await G.getAttribute($e);T=ne===null?void 0:ne}}else T=await ye(a.expectedValue,b.selectors,y,{});else typeof a.expectedValue=="string"||typeof a.expectedValue>"u"?T=a.expectedValue:T="";let Z={...a,expectedValue:T},pe=T??"",W=await c.validate({...Z,expectedValue:pe},e.description);if(W.success&&W.passMessage)q.push(W.passMessage);else if(!W.success&&W.failMessage){let J=[];if(a.target||J.push("target"),a.assertion||J.push("assertion"),["toHaveAttribute","toHaveValue","toHaveRole"].includes(a.assertion)&&(typeof a.attribute>"u"&&a.assertion==="toHaveAttribute"&&J.push("attribute"),typeof a.expectedValue>"u"&&J.push("expectedValue")),J.length>0){let L=Q(a.level||e.level),se=`Dynamic assertion missing required field(s): ${J.join(", ")}`,G=E(se,L);if(G.status==="skip")continue;V.push(se),i.reportTest({description:e.description,level:L},G.status,G.detail);continue}}}let f=V.length,B=K.length,be=x.length;f>m?i.reportTest({description:e.description,level:h},"fail",V[V.length-1]):B>$?i.reportTest({description:e.description,level:h},"warn",K[K.length-1]):be>k?i.reportTest({description:e.description,level:h},"skip",x[x.length-1]):i.reportTest({description:e.description,level:h},"pass")}i.reportStatic(D,P,I),i.summary(V)}catch(d){if(d instanceof Error)throw d.message.includes("Executable doesn't exist")||d.message.includes("browserType.launch")?new Error(`
|
|
31
31
|
\u274C CRITICAL: Playwright browsers not found!
|