Skip to content

Commit

Permalink
chore(ace): add standard support
Browse files Browse the repository at this point in the history
  • Loading branch information
j-mendez committed Sep 27, 2023
1 parent 3328317 commit bbd4d3f
Show file tree
Hide file tree
Showing 15 changed files with 47 additions and 32 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ type RunnerConfig = {

## Localization

[Locales](https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/i18n) supported by the runner using pre-compilition. In order to pre-compile the locales run `yarn build`. Some locales are only available in certain runners. All of the languages are split into individual scripts to scale. `Ace` runner currently only supports english.
[Locales](https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/i18n) supported by the runner using pre-compilition. In order to pre-compile the locales run `yarn build`. Some locales are only available in certain runners.

1. da ("Danish")
1. de ("German")
Expand Down
2 changes: 1 addition & 1 deletion kayle/lib/option.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export function extractArgs(o, watcher?: Watcher) {
rootElement: o.rootElement,
rules: o.rules || [],
runners: o.runners || ["htmlcs"],
standard: o.standard || "WCAG2AA",
standard: o.standard,
origin: o.origin || (o.html && "http://localhost") || "",
language: o.language || "en",
// store clip tracking element position
Expand Down
39 changes: 23 additions & 16 deletions kayle/lib/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,24 @@

// start of code score maps todo: use enums A = Axe, H = Htmlcs, IA = IBM Ace
const A_1 = "color-contrast";
const H_1 = "WCAG2AA.Principle1.Guideline14.143.G18.Fail";
const IA_1 = "WCAG2AA.Principle1.Guideline1_4.1_4_3.G18.Fail";
const H_1 = "Principle1.Guideline14.143.G18.Fail";
const IA_1 = "Principle1.Guideline1_4.1_4_3.G18.Fail";
const A_2 = "duplicate-id";
const H_2 = "WCAG2AA.Principle4.Guideline41.411.F77";
const IA_2 = "WCAG2AA.Principle4.Guideline4_1.4_1_1.F77";
const H_2 = "Principle4.Guideline41.411.F77";
const IA_2 = "Principle4.Guideline4_1.4_1_1.F77";
// element_id_unique todo: add optional 3rd ref to track combo for ace runner
const A_3 = "empty-heading";
const H_3 = "WCAG2AA.Principle1.Guideline13.131.H42.2";
const IA_3 = "WCAG2AA.Principle1.Guideline1_3.1_3_1.H42.2";
const H_3 = "Principle1.Guideline13.131.H42.2";
const IA_3 = "Principle1.Guideline1_3.1_3_1.H42.2";
const A_4 = "frame-title";
const H_4 = "WCAG2AA.Principle2.Guideline24.241.H64.1";
const IA_4 = "WCAG2AA.Principle2.Guideline2_4.2_4_1.H64.1";
const H_4 = "Principle2.Guideline24.241.H64.1";
const IA_4 = "Principle2.Guideline2_4.2_4_1.H64.1";
const A_5 = "link-name";
const H_5 = "WCAG2AA.Principle4.Guideline41.412.H91.A.EmptyNoId";
const IA_5 = "WCAG2AA.Principle4.Guideline4_1.4_1_2.H91.A.EmptyNoId";
const H_5 = "Principle4.Guideline41.412.H91.A.EmptyNoId";
const IA_5 = "Principle4.Guideline4_1.4_1_2.H91.A.EmptyNoId";
const A_6 = "heading-order";
const H_6 = "WCAG2AA.Principle1.Guideline13.131A.G141"; // HeadingOrder map
const IA_6 = "WCAG2AA.Principle4.Guideline1_3.1_3_1_A.G141";
const H_6 = "Principle1.Guideline13.131A.G141"; // HeadingOrder map
const IA_6 = "Principle4.Guideline1_3.1_3_1_A.G141";

// oneshot map
const scoreMap = new Map<string, [number, string, string]>([
Expand Down Expand Up @@ -251,12 +252,18 @@
meta.noticeCount += issue.recurrence + 1;
}

if (scoreMap.has(issue.code)) {
const [accessScore, ref, ref2] = scoreMap.get(issue.code);
// replace WCAG from code
const code =
issue.code[0] === "W"
? issue.code.substring(issue.code.indexOf(".") + 1)
: issue.code;

if (scoreMap.has(code)) {
const [accessScore, ref, ref2] = scoreMap.get(code);
meta.accessScore -= accessScore;
scoreMap.delete(ref);
scoreMap.delete(ref2);
scoreMap.delete(issue.code);
scoreMap.delete(code);
}

// In-place hybrid insert sorting
Expand All @@ -282,7 +289,7 @@
if (errorType) {
meta.errorCount += issue.recurrence + 1;
if (
issue.code === "WCAG2AA.Principle1.Guideline1_1.1_1_1.H37" ||
issue.code === "Principle1.Guideline1_1.1_1_1.H37" ||
issue.code === "image-alt"
) {
missingAltIndexs.push(tracker.errorPointer);
Expand Down
2 changes: 1 addition & 1 deletion kayle/lib/runners/ace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const run = async (options) => {
(options.rootElement &&
window.document.querySelector(options.rootElement)) ||
window.document,
["IBM_Accessibility"]
["IBM_Accessibility", options.standard]
)
.then((report) => {
resolve(report.results);
Expand Down
2 changes: 1 addition & 1 deletion kayle/lib/runners/htmlcs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const run = async (options) => {

// @ts-ignore
window.HTMLCS.process(
options.standard,
options.standard || "WCAG2AA",
(options.rootElement &&
window.document.querySelector(options.rootElement)) ||
window.document,
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.1",
"version": "0.7.2",
"description": "Extremely fast and accurate accessibility engine built for any headless tool like playwright or puppeteer.",
"main": "./build/index.js",
"keywords": [
Expand Down
3 changes: 2 additions & 1 deletion kayle/tests/automa.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import assert from "assert";
import { launch } from "puppeteer";
import { autoKayle, setLogging } from "kayle";
import { Standard, autoKayle, setLogging } from "kayle";
import { performance } from "perf_hooks";

setLogging(false);
Expand All @@ -21,6 +21,7 @@ setLogging(false);
runners: ["axe"],
includeWarnings: true,
origin: "https://a11ywatch.com", // origin is the fake url in place of the raw content
standard: Standard.WCAG2AAA,
// store: `${process.cwd()}/_data/`, // create _data folder first
cb: async function callback(result) {
const { issues, pageUrl, documentTitle, meta } = result;
Expand Down
5 changes: 3 additions & 2 deletions kayle/tests/basic-ace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { performance } from "perf_hooks";
browser,
runners: ["ace"],
includeWarnings: true,
standard: "WCAG2AA",
html: drakeMock,
origin: "https://www.drake.com", // origin is the fake url in place of the raw content
});
Expand All @@ -28,9 +29,9 @@ import { performance } from "perf_hooks";

// valid list
assert(Array.isArray(issues));
assert(meta.errorCount === 55);
assert(meta.errorCount >= 55);
assert(meta.warningCount === 42);
assert(meta.accessScore === 40);
assert(meta.accessScore >= 40);

assert(typeof pageUrl === "string");
assert(typeof documentTitle === "string");
Expand Down
3 changes: 2 additions & 1 deletion kayle/tests/basic-axe-playwright.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import assert from "assert";
import { writeFileSync } from "fs";
import { kayle } from "kayle";
import { Standard, kayle } from "kayle";
import { drakeMock } from "./mocks/html-mock";
import { performance } from "perf_hooks";
import { test } from "@playwright/test";
Expand All @@ -15,6 +15,7 @@ test("fast_axecore audit drakeMock", async ({ page, browser }, testInfo) => {
browser,
runners: ["axe"],
includeWarnings: true,
standard: Standard.WCAG2AAA,
origin: "https://www.drake.com",
html: drakeMock,
waitUntil: "domcontentloaded",
Expand Down
3 changes: 2 additions & 1 deletion kayle/tests/basic-axe.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import assert from "assert";
import puppeteer from "puppeteer";
import { kayle } from "kayle";
import { Standard, kayle } from "kayle";
import { drakeMock } from "./mocks/html-mock";
import { performance } from "perf_hooks";

Expand All @@ -16,6 +16,7 @@ import { performance } from "perf_hooks";
browser,
runners: ["axe"],
includeWarnings: true,
standard: Standard.WCAG2AAA,
origin: "https://www.drake.com",
html: drakeMock,
});
Expand Down
4 changes: 2 additions & 2 deletions kayle/tests/basic-htmlcs.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import assert from "assert";
import puppeteer from "puppeteer";
import { kayle } from "kayle";
import { Standard, kayle } from "kayle";
import { drakeMock } from "./mocks/html-mock";
import { performance } from "perf_hooks";

Expand All @@ -16,7 +16,7 @@ import { performance } from "perf_hooks";
browser,
runners: ["htmlcs"],
includeWarnings: true,
standard: "WCAG2AAA",
standard: Standard.WCAG2AAA,
origin: "https://www.drake.com",
html: drakeMock,
});
Expand Down
3 changes: 2 additions & 1 deletion kayle/tests/basic-playwright.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { writeFileSync } from "fs";
import assert from "assert";
import { kayle } from "kayle";
import { Standard, kayle } from "kayle";
import { drakeMock } from "./mocks/html-mock";
import { performance } from "perf_hooks";
import { test } from "@playwright/test";
Expand All @@ -19,6 +19,7 @@ test("fast_htmlcs and fast_axecore audit drakeMock", async ({
runners: ["htmlcs", "axe"],
includeWarnings: true,
html: drakeMock,
standard: Standard.WCAG2AAA,
origin: "https://www.drake.com",
waitUntil: "domcontentloaded",
});
Expand Down
3 changes: 2 additions & 1 deletion kayle/tests/basic.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import assert from "assert";
import puppeteer from "puppeteer";
import { kayle } from "kayle";
import { Standard, kayle } from "kayle";
import { drakeMock } from "./mocks/html-mock";
import { performance } from "perf_hooks";

Expand All @@ -17,6 +17,7 @@ import { performance } from "perf_hooks";
runners: ["htmlcs", "axe"],
includeWarnings: true,
html: drakeMock,
standard: Standard.WCAG2AAA,
origin: "https://www.drake.com", // origin is the fake url in place of the raw content
});
const nextTime = performance.now() - startTime;
Expand Down
3 changes: 2 additions & 1 deletion kayle/tests/clips-playwright.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import assert from "assert";
import { writeFileSync } from "fs";
import { kayle } from "kayle";
import { Standard, kayle } from "kayle";
import { drakeMock } from "./mocks/html-mock";
import { performance } from "perf_hooks";
import { test } from "@playwright/test";
Expand All @@ -18,6 +18,7 @@ test("fast_axecore audit drakeMock", async ({ page, browser }, testInfo) => {
runners: ["axe"],
includeWarnings: true,
origin: "https://www.drake.com",
standard: Standard.WCAG2AAA,
html: drakeMock,
waitUntil: "domcontentloaded",
allowImages: true,
Expand Down
3 changes: 2 additions & 1 deletion kayle/tests/clips.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import assert from "assert";
import puppeteer from "puppeteer";
import { kayle } from "kayle";
import { Standard, kayle } from "kayle";
import { drakeMock } from "./mocks/html-mock";
import { performance } from "perf_hooks";

Expand All @@ -15,6 +15,7 @@ import { performance } from "perf_hooks";
page,
browser,
runners: ["axe"],
standard: Standard.WCAG2AAA,
includeWarnings: true,
origin: "https://www.drake.com",
html: drakeMock,
Expand Down

0 comments on commit bbd4d3f

Please sign in to comment.