Skip to content

Commit

Permalink
chore(util): add inject runner
Browse files Browse the repository at this point in the history
  • Loading branch information
j-mendez committed Sep 26, 2023
1 parent 43e6de8 commit 5b91832
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 19 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ The `kayle` function also expects a field called `browserExtension` with the opt

In order to develop you need yarn v2 installed for the workspace.

Run the following to install on ^node@16.10
Run the following to install on ^node@18

`corepack enable && corepack prepare yarn@stable --activate` and reload shell after.

Expand Down
6 changes: 3 additions & 3 deletions kayle/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ const results = {
x: 20,
y: 100,
width: 300,
height: 200
height: 200,
},
clipBase64: "iVBORw0KGgoAAAANSUhEUgAAAJYAAABxCAYAAAA3QFrYAAAAA" // use in img element like data:image/png;base64, + clipBase64
clipBase64: "iVBORw0KGgoAAAANSUhEUgAAAJYAAABxCAYAAAA3QFrYAAAAA", // use in img element like data:image/png;base64, + clipBase64
};
```

Expand All @@ -89,7 +89,7 @@ kayle supports multiple test runners which return different results. The built-i

- `axe`: run tests using [axe-core](./lib/runners/axe.ts).
- `htmlcs` (default): run tests using [HTML CodeSniffer](./lib/runners/htmlcs.ts)
- `custom`: custom runners.
- `custom`: custom runners using `injectRunner` util.

## Playwright/Puppeteer

Expand Down
5 changes: 3 additions & 2 deletions kayle/lib/config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Watcher } from "./watcher";
import type { Runner } from "./runner-js";

type Permission =
| "geolocation"
Expand Down Expand Up @@ -134,8 +135,6 @@ export interface CDPSession {
[x: string]: any;
}

type Runner = "axe" | "htmlcs";

// runner configuration
export type RunnerConfig = {
browser: Partial<Browser>;
Expand Down Expand Up @@ -196,3 +195,5 @@ export enum Standard {
WCAG2AAA = "WCAG2AAA",
SECTION508 = "SECTION508",
}

export { Runner };
4 changes: 2 additions & 2 deletions kayle/lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export { kayle } from "./kayle";
export type { Issue, Audit, MetaInfo, Automatable } from "./common";
export { autoKayle } from "./auto";
export { runnersJavascript } from "./runner-js";
export { runnersJavascript, getRunner, injectRunner } from "./runner-js";
export {
goToPage,
setNetworkInterception,
Expand All @@ -11,5 +11,5 @@ export {
sendCDPPageConfigurationEnable,
sendCDPPageConfigurationReset,
} from "./utils/cdp-blocking";
export { setLogging, Standard, RunnerConfig } from "./config";
export { setLogging, Standard, RunnerConfig, Runner } from "./config";
export { extractLinks } from "./wasm";
8 changes: 4 additions & 4 deletions kayle/lib/kayle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,11 @@ export const kayle = async (
const { clip, selector } = item;

// prevent screenshots
if(typeof o.clipMax === 'number') {
if(!o.clipMax) {
return item
if (typeof o.clipMax === "number") {
if (!o.clipMax) {
return item;
}
o.clipMax--
o.clipMax--;
}

try {
Expand Down
33 changes: 31 additions & 2 deletions kayle/lib/runner-js.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,21 @@ const runnersJavascript = {
// axe_pt_BR: loadRunnerScript("axe", "pt-BR"),
};

// inject a new runner for testing
const injectRunner = (runner: string, path: string, lang: string) => {
runnersJavascript[runner] = loadRunnerScript(path, lang ?? "");
};

/**
* Get the runner for the page.
* @param {String} [language="en"] - The language.
* @param {String} [runner=""] - The runner type.
* @returns {String} Returns the runner javascript by locale.
*/
const getRunner = (language: string, runner: string) => {
const getRunner = (
language: string,
runner: keyof typeof runnersJavascript
) => {
// if langauge exist get the runner type
if (language) {
if (runner === "axe") {
Expand All @@ -83,4 +91,25 @@ const getRunner = (language: string, runner: string) => {
return runnersJavascript[runner];
};

export { runnersJavascript, getRunner };
export type Runner = Exclude<
keyof typeof runnersJavascript,
| "kayle"
| "htmlcs_es"
| "htmlcs_ja"
| "htmlcs_fr"
| "htmlcs_it"
| "htmlcs_nl"
| "htmlcs_pl"
| "htmlcs_zh_CN"
| "axe_es"
| "axe_ja"
| "axe_fr"
| "axe_da"
| "axe_de"
| "axe_he"
| "axe_nl"
| "axe_pl"
| "axe_ko"
>;

export { runnersJavascript, getRunner, injectRunner };
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.6.3",
"version": "0.6.4",
"description": "Extremely fast and accurate accessibility engine built for any headless tool like playwright or puppeteer.",
"main": "./build/index.js",
"keywords": [
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8962,21 +8962,21 @@ __metadata:

"typescript@patch:typescript@^4.9.3#~builtin<compat/typescript>, typescript@patch:typescript@^4.9.4#~builtin<compat/typescript>":
version: 4.9.5
resolution: "typescript@patch:typescript@npm%3A4.9.5#~builtin<compat/typescript>::version=4.9.5&hash=23ec76"
resolution: "typescript@patch:typescript@npm%3A4.9.5#~builtin<compat/typescript>::version=4.9.5&hash=289587"
bin:
tsc: bin/tsc
tsserver: bin/tsserver
checksum: ab417a2f398380c90a6cf5a5f74badd17866adf57f1165617d6a551f059c3ba0a3e4da0d147b3ac5681db9ac76a303c5876394b13b3de75fdd5b1eaa06181c9d
checksum: 1f8f3b6aaea19f0f67cba79057674ba580438a7db55057eb89cc06950483c5d632115c14077f6663ea76fd09fce3c190e6414bb98582ec80aa5a4eaf345d5b68
languageName: node
linkType: hard

"typescript@patch:typescript@^5.0.4#~builtin<compat/typescript>":
version: 5.1.3
resolution: "typescript@patch:typescript@npm%3A5.1.3#~builtin<compat/typescript>::version=5.1.3&hash=85af82"
resolution: "typescript@patch:typescript@npm%3A5.1.3#~builtin<compat/typescript>::version=5.1.3&hash=5da071"
bin:
tsc: bin/tsc
tsserver: bin/tsserver
checksum: 32a25b2e128a4616f999d4ee502aabb1525d5647bc8955e6edf05d7fbc53af8aa98252e2f6ba80bcedfc0260c982b885f3c09cfac8bb65d2924f3133ad1e1e62
checksum: 6f0a9dca6bf4ce9dcaf4e282aade55ef4c56ecb5fb98d0a4a5c0113398815aea66d871b5611e83353e5953a19ed9ef103cf5a76ac0f276d550d1e7cd5344f61e
languageName: node
linkType: hard

Expand Down

0 comments on commit 5b91832

Please sign in to comment.