Skip to content

Commit

Permalink
chore(selector): fix head element query selecting [#19]
Browse files Browse the repository at this point in the history
  • Loading branch information
j-mendez committed Nov 22, 2023
1 parent 87ed443 commit 5cd2cf5
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 12 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
[discord-url]: https://discord.gg/ukmJcjQ5
13 changes: 9 additions & 4 deletions kayle/lib/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 "";
}
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion kayle/package.json
Original file line number Diff line number Diff line change
@@ -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": [
Expand Down
17 changes: 11 additions & 6 deletions kayle/tests/innate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,19 @@ import { _audit_not_ready } from "kayle_innate";
origin: "https://www.drake.com",
html: drakeMock,
});

const mock = html.replace(
"<title>Drake Industries | Custom, Durable, High-Quality Labels, Asset Tags and Custom Server Bezels</title>",
""
).replace(`<body class=" hs-content-id-8839032963 hs-site-page page " style="">`, `<body class=" hs-content-id-8839032963 hs-site-page page " style=""><form action="/something" method="post">

const mock = html
.replace(
"<title>Drake Industries | Custom, Durable, High-Quality Labels, Asset Tags and Custom Server Bezels</title>",
""
)
.replace(
`<body class=" hs-content-id-8839032963 hs-site-page page " style="">`,
`<body class=" hs-content-id-8839032963 hs-site-page page " style=""><form action="/something" method="post">
<label for="name">Name:</label>
<input type="text" id="name" name="name">
</form>`);
</form>`
);

const startTime = performance.now();
const audit = await _audit_not_ready(mock, css, false);
Expand Down

0 comments on commit 5cd2cf5

Please sign in to comment.