diff --git a/README.md b/README.md index 6a85b5e..b474288 100644 --- a/README.md +++ b/README.md @@ -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") diff --git a/kayle/lib/option.ts b/kayle/lib/option.ts index 0c0f933..57616af 100644 --- a/kayle/lib/option.ts +++ b/kayle/lib/option.ts @@ -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 diff --git a/kayle/lib/runner.ts b/kayle/lib/runner.ts index 017785a..5c046b9 100644 --- a/kayle/lib/runner.ts +++ b/kayle/lib/runner.ts @@ -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([ @@ -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 @@ -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); diff --git a/kayle/lib/runners/ace.ts b/kayle/lib/runners/ace.ts index 67aa2d5..8ee49e1 100644 --- a/kayle/lib/runners/ace.ts +++ b/kayle/lib/runners/ace.ts @@ -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); diff --git a/kayle/lib/runners/htmlcs.ts b/kayle/lib/runners/htmlcs.ts index 3876dd9..e8829a3 100644 --- a/kayle/lib/runners/htmlcs.ts +++ b/kayle/lib/runners/htmlcs.ts @@ -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, diff --git a/kayle/package.json b/kayle/package.json index 6dbf6f8..cb1ec2f 100644 --- a/kayle/package.json +++ b/kayle/package.json @@ -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": [ diff --git a/kayle/tests/basic-ace.ts b/kayle/tests/basic-ace.ts index 790ddfe..8a568ef 100644 --- a/kayle/tests/basic-ace.ts +++ b/kayle/tests/basic-ace.ts @@ -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 }); @@ -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"); diff --git a/kayle/tests/basic-axe.ts b/kayle/tests/basic-axe.ts index bcbbf87..9aab28c 100644 --- a/kayle/tests/basic-axe.ts +++ b/kayle/tests/basic-axe.ts @@ -16,6 +16,7 @@ import { performance } from "perf_hooks"; browser, runners: ["axe"], includeWarnings: true, + standard: "WCAG2AAA", origin: "https://www.drake.com", html: drakeMock, });