From 5cd2cf584dd10aeda99142a7d0eada18ac641cac Mon Sep 17 00:00:00 2001 From: j-mendez Date: Wed, 22 Nov 2023 11:33:42 -0500 Subject: [PATCH] chore(selector): fix head element query selecting [#19] --- README.md | 2 +- kayle/lib/runner.ts | 13 +++++++++---- kayle/package.json | 2 +- kayle/tests/innate.ts | 17 +++++++++++------ 4 files changed, 22 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 5829aae..2ee986c 100644 --- a/README.md +++ b/README.md @@ -265,4 +265,4 @@ One of the main goals was to have the audit run quickly since we noticed some of Check the license file in the root of each project. [discord-badge]: https://img.shields.io/discord/860982761137111040.svg?logo=discord -[discord-url]: https://discord.gg/ukmJcjQ5 \ No newline at end of file +[discord-url]: https://discord.gg/ukmJcjQ5 diff --git a/kayle/lib/runner.ts b/kayle/lib/runner.ts index 276ad40..fa17a77 100644 --- a/kayle/lib/runner.ts +++ b/kayle/lib/runner.ts @@ -157,7 +157,7 @@ }; // get css selelector todo: shortest path https://patents.google.com/patent/CN105094940A/en - const getElementSelector = (element: HTMLElement) => { + const getElementSelector = (element: HTMLElement, initial?: boolean) => { if (!element || element.nodeName == "HTML") { return ""; } @@ -171,9 +171,14 @@ return "body"; } - return `${getElementSelector( - element.parentNode as HTMLElement - )}>:nth-child(${siblingPosition(element)})`; + const elementSelector = getElementSelector( + element.parentNode as HTMLElement, + true + ); + + return `${ + !elementSelector && initial ? "html" : elementSelector + }>:nth-child(${siblingPosition(element)})`; }; // runner to get accessibility issues diff --git a/kayle/package.json b/kayle/package.json index ef8216a..39bb35f 100644 --- a/kayle/package.json +++ b/kayle/package.json @@ -1,6 +1,6 @@ { "name": "kayle", - "version": "0.7.12", + "version": "0.7.13", "description": "Extremely fast and accurate accessibility engine built for any headless tool like playwright or puppeteer.", "main": "./build/index.js", "keywords": [ diff --git a/kayle/tests/innate.ts b/kayle/tests/innate.ts index 714bd2f..68fbfc6 100644 --- a/kayle/tests/innate.ts +++ b/kayle/tests/innate.ts @@ -18,14 +18,19 @@ import { _audit_not_ready } from "kayle_innate"; origin: "https://www.drake.com", html: drakeMock, }); - - const mock = html.replace( - "Drake Industries | Custom, Durable, High-Quality Labels, Asset Tags and Custom Server Bezels", - "" - ).replace(``, `
+ + const mock = html + .replace( + "Drake Industries | Custom, Durable, High-Quality Labels, Asset Tags and Custom Server Bezels", + "" + ) + .replace( + ``, + ` -
`); + ` + ); const startTime = performance.now(); const audit = await _audit_not_ready(mock, css, false);