Skip to content

Commit

Permalink
chore(events): add pdf and drag-and-drop
Browse files Browse the repository at this point in the history
  • Loading branch information
j-mendez committed Mar 24, 2024
1 parent 2305af4 commit ec49f65
Show file tree
Hide file tree
Showing 32 changed files with 173 additions and 90 deletions.
2 changes: 1 addition & 1 deletion kayle/bench/fast_axecore-playwright.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ async function launchBench() {
unit: "OPS/S",
value: 1000 / avg,
},
])
]),
);
}

Expand Down
2 changes: 1 addition & 1 deletion kayle/bench/fast_htmlcs-playwright.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ async function launchBench() {
unit: "OPS/S",
value: 1000 / avg,
},
])
]),
);
}

Expand Down
2 changes: 1 addition & 1 deletion kayle/builder/build-extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ window.addEventListener("kayle_send", async (event) => {

writeFileSync(
`${ext}/content-script.js`,
`${extensionRunner}\n${extensionAxe}\n${extensionHtmlcs}\n${extensionRawEnd}`
`${extensionRunner}\n${extensionAxe}\n${extensionHtmlcs}\n${extensionRawEnd}`,
);

const extensionManifest = `{
Expand Down
2 changes: 1 addition & 1 deletion kayle/builder/build-htmlcs-params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ const processFile = (filePath, paramList: ParamList[]) => {

if (!guide) {
guide = code.match(
/(_global\.HTMLCS_WCAG2AAA_Sniffs_)([A-Za-z0-9_]+)/
/(_global\.HTMLCS_WCAG2AAA_Sniffs_)([A-Za-z0-9_]+)/,
);
if (guide && guide[2]) {
const end = guide[2].length - 23;
Expand Down
30 changes: 15 additions & 15 deletions kayle/builder/build-rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import type { Rule } from "./build-types";
origin: "https://www.example.com",
language,
},
true
true,
);

await Promise.all([
Expand All @@ -54,7 +54,7 @@ import type { Rule } from "./build-types";
content: `window.htmlcsRuleMap = ${htmlcsRuleMap.toString()};`,
}),
page.exposeFunction("pushHtmlcsRule", (t: Rule[]) =>
fast_htmlcs_rules.push(...t)
fast_htmlcs_rules.push(...t),
),
page.exposeFunction("pushAxeRule", (t: Rule) => fast_axe_rules.push(t)),
]);
Expand Down Expand Up @@ -93,25 +93,25 @@ import type { Rule } from "./build-types";
return r.description;
})
.sort((a, b) => a.ruleId.localeCompare(b.ruleId))
.sort((a, b) => a.ruleId.localeCompare(b.ruleId)),
)};`,
pConfig
)
pConfig,
),
),
"utf8"
"utf8",
);

await writeFile(
`./lib/rules/${language}/axe-rules.ts`,
Buffer.from(
await format(
`/* ${DNE} */\nexport const axeRules = ${JSON.stringify(
fast_axe_rules.sort((a, b) => a.ruleId.localeCompare(b.ruleId))
fast_axe_rules.sort((a, b) => a.ruleId.localeCompare(b.ruleId)),
)};`,
pConfig
)
pConfig,
),
),
"utf8"
"utf8",
);

await page.close({
Expand All @@ -120,7 +120,7 @@ import type { Rule } from "./build-types";
};

const localesList: string[] = Array.from(
new Set(htmlcsLocales.concat(axeLocales))
new Set(htmlcsLocales.concat(axeLocales)),
);

localesList.push("en");
Expand All @@ -143,7 +143,7 @@ import type { Rule } from "./build-types";
export const importRules = async (locale: ${localesList
.map((l) => `"${l}"`)
.join(
" | "
" | ",
)}, runner: "htmlcs" | "axe", baseDir?: "string"): Promise<Rule[]> => {
const rules = await import(` +
"`${baseDir || './'}${locale.replace('-', '_')}/${runner === 'htmlcs' ? 'htmlcs' : 'axe'}-rules`" +
Expand All @@ -167,10 +167,10 @@ import type { Rule } from "./build-types";
${runnerImports}
`,
pConfig
)
pConfig,
),
),
"utf8"
"utf8",
);

await browser.close();
Expand Down
56 changes: 45 additions & 11 deletions kayle/lib/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ export const actions = [
target.dispatchEvent(
new Event("input", {
bubbles: true,
})
}),
);

return Promise.resolve();
},
selector,
value
value,
);
} catch (error) {
throw new Error(`${failedActionElement} "${selector}"`);
Expand Down Expand Up @@ -91,7 +91,7 @@ export const actions = [
target.dispatchEvent(
new Event("input", {
bubbles: true,
})
}),
);
return Promise.resolve();
}, selector);
Expand All @@ -117,18 +117,27 @@ export const actions = [
target.dispatchEvent(
new Event("change", {
bubbles: true,
})
}),
);
return Promise.resolve();
},
selector,
checked
checked,
);
} catch (error) {
throw new Error(`${failedActionElement} "${selector}"`);
}
},
},
{
name: "style",
match: /^style ( content)? (.+?)$/i,
run: async (_, page, __, matches) => {
await page.addStyleTag({
content: matches[2],
});
},
},
{
name: "screen-capture",
match: /^(screen[ -]?capture|capture[ -]?screen)( to)? (.+)$/i,
Expand All @@ -139,6 +148,31 @@ export const actions = [
});
},
},
{
name: "pdf",
match: /^pdf( to)? (.+)$/i,
run: async (_, page, __, matches) => {
await page.pdf({
path: matches[3],
});
},
},
{
name: "drag-and-drop",
match: /^drag-and-drop ( element)? (.+)( to ) (target)$/i,
run: async (_, page, __, matches) => {
if (typeof page.dragAndDrop === "function") {
await page.dragAndDrop(matches[1], matches[3]);
} else if (typeof page?.mouse?.dragAndDrop) {
const positions = await page.$$eval(
[matches[1], matches[3]],
(elements: HTMLInputElement[]) =>
elements.map((e) => e.getBoundingClientRect),
);
await page.dragAndDrop(positions[0], positions[1]);
}
},
},
{
name: "wait-for-url",
match: /^wait for (fragment|hash|host|path|url)( to (not )?be)? ([^\s]+)$/i,
Expand Down Expand Up @@ -176,7 +210,7 @@ export const actions = [
{},
property,
expectedValue,
negated
negated,
);
},
},
Expand Down Expand Up @@ -216,7 +250,7 @@ export const actions = [
polling: 200,
},
selector,
state
state,
);
},
},
Expand Down Expand Up @@ -244,11 +278,11 @@ export const actions = [
},
{
once: true,
}
},
);
},
selector,
eventType
eventType,
);

await page.waitForFunction(
Expand All @@ -263,7 +297,7 @@ export const actions = [
},
{
polling: 200,
}
},
);
} catch (error) {
throw new Error(`${failedActionElement} "${selector}"`);
Expand All @@ -283,7 +317,7 @@ export const actions = [
*/
export async function runAction(browser, page, options, act, customActions?) {
const action = (customActions ?? actions).find((item) =>
item.match.test(act)
item.match.test(act),
);

if (!action) {
Expand Down
8 changes: 4 additions & 4 deletions kayle/lib/auto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export async function autoKayle(
cb?: ((result: Audit) => Promise<void>) | ((result: Audit) => void);
} = {},
ignoreSet?: Set<String>,
_results?: Audit[]
_results?: Audit[],
): Promise<Audit[]> {
if (!write) {
const { writeFile } = await import("fs/promises");
Expand Down Expand Up @@ -51,7 +51,7 @@ export async function autoKayle(
if (o.store) {
await write(
`${o.store}/${encodeURIComponent(o.page.url())}`,
await o.page.content()
await o.page.content(),
);
}

Expand Down Expand Up @@ -84,7 +84,7 @@ export async function autoKayle(
origin: link,
},
ignoreSet,
_results
_results,
);
})
.catch((e) => {
Expand All @@ -94,7 +94,7 @@ export async function autoKayle(
console.error(e);
}
});
})
}),
);

return _results;
Expand Down
Loading

0 comments on commit ec49f65

Please sign in to comment.