From 68e4bbf79d10756f0e2c5241ea4012a4e60b9b21 Mon Sep 17 00:00:00 2001 From: "Amanda G. Brown" Date: Mon, 13 Feb 2023 11:52:41 -0500 Subject: [PATCH 1/5] chore (toHaveNoViolations): add axe-github --- e2e/matchers/toHaveNoViolations.ts | 3 +++ package-lock.json | 13 +++++++++++++ package.json | 1 + 3 files changed, 17 insertions(+) diff --git a/e2e/matchers/toHaveNoViolations.ts b/e2e/matchers/toHaveNoViolations.ts index e4d48c6cfef..4daf3445664 100644 --- a/e2e/matchers/toHaveNoViolations.ts +++ b/e2e/matchers/toHaveNoViolations.ts @@ -1,5 +1,6 @@ import {Page, expect, test} from '@playwright/test' import {AxeResults, source} from 'axe-core' +import axeConfig from '@github/axe-github' import path from 'node:path' import fs from 'node:fs' @@ -58,6 +59,7 @@ expect.extend({ }, tags: ['custom-github-rule'], }, + ...axeConfig.rules, ], checks: [ { @@ -69,6 +71,7 @@ expect.extend({ metadata: { impact: 'critical', }, + ...axeConfig.checks, }, ], }) diff --git a/package-lock.json b/package-lock.json index 1b5a150ce67..61b35e98dc9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -46,6 +46,7 @@ "@babel/preset-typescript": "7.18.6", "@changesets/changelog-github": "0.4.7", "@changesets/cli": "2.26.0", + "@github/axe-github": "0.4.0", "@github/markdownlint-github": "^0.3.0", "@github/prettier-config": "0.0.6", "@playwright/test": "1.27.1", @@ -3043,6 +3044,12 @@ "integrity": "sha512-k2Ty1JcVojjJFwrg/ThKi2ujJ7XNLYaFGNB/bWT9wGR+oSMJHMa5w+CUq6p/pVrKeNNgA7pCqEcjSnHVoqJQFw==", "dev": true }, + "node_modules/@github/axe-github": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/@github/axe-github/-/axe-github-0.4.0.tgz", + "integrity": "sha512-grp6BNBYjzeoytpBC5sqULia8vKrir0aTjKn5gxpGlcWCMeY4jFaMRWr2MqtGdrKPO+2Lv1d5xomb+S75Oyw6g==", + "dev": true + }, "node_modules/@github/combobox-nav": { "version": "2.1.7", "resolved": "https://registry.npmjs.org/@github/combobox-nav/-/combobox-nav-2.1.7.tgz", @@ -56414,6 +56421,12 @@ "integrity": "sha512-k2Ty1JcVojjJFwrg/ThKi2ujJ7XNLYaFGNB/bWT9wGR+oSMJHMa5w+CUq6p/pVrKeNNgA7pCqEcjSnHVoqJQFw==", "dev": true }, + "@github/axe-github": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/@github/axe-github/-/axe-github-0.4.0.tgz", + "integrity": "sha512-grp6BNBYjzeoytpBC5sqULia8vKrir0aTjKn5gxpGlcWCMeY4jFaMRWr2MqtGdrKPO+2Lv1d5xomb+S75Oyw6g==", + "dev": true + }, "@github/combobox-nav": { "version": "2.1.7", "resolved": "https://registry.npmjs.org/@github/combobox-nav/-/combobox-nav-2.1.7.tgz", diff --git a/package.json b/package.json index 059fd7b3ec9..e2b0f988eb0 100644 --- a/package.json +++ b/package.json @@ -124,6 +124,7 @@ "@babel/preset-typescript": "7.18.6", "@changesets/changelog-github": "0.4.7", "@changesets/cli": "2.26.0", + "@github/axe-github": "0.4.0", "@github/markdownlint-github": "^0.3.0", "@github/prettier-config": "0.0.6", "@playwright/test": "1.27.1", From 01a778d2b1da040736b675ca6ef5800899247f15 Mon Sep 17 00:00:00 2001 From: "Amanda G. Brown" Date: Thu, 23 Feb 2023 12:45:42 -0500 Subject: [PATCH 2/5] fix: manually added rules and checks from axe-github --- e2e/matchers/toHaveNoViolations.ts | 90 ++++++++++++++++++++++++++++-- 1 file changed, 86 insertions(+), 4 deletions(-) diff --git a/e2e/matchers/toHaveNoViolations.ts b/e2e/matchers/toHaveNoViolations.ts index 4daf3445664..51c7843c08a 100644 --- a/e2e/matchers/toHaveNoViolations.ts +++ b/e2e/matchers/toHaveNoViolations.ts @@ -45,13 +45,73 @@ expect.extend({ // @ts-ignore `axe` is a global variable defined by page.evaluate() above const axe = window.axe + const interactiveElements = ['a[href]', 'button', 'summary', 'select', 'input:not([type=hidden])', 'textarea'] + const focusableElements = interactiveElements.concat(['[tabindex]']) + axe.configure({ rules: [ + { + id: 'menuitem-should-be-interactive', + excludeHidden: true, + selector: + 'div[role="menuitem"], span[role="menuitem"], div[role="menuitemradio"], span[role="menuitemradio"], div[role="menuitemcheckbox"], span[role="menuitemcheckbox"]', + all: ['menuitem-should-be-interactive_0'], + any: [], + metadata: { + help: 'Menu items must be focusable. Use