Skip to content

Commit

Permalink
Merge branch 'main' of github.com:koddsson/accessbility-scanner into …
Browse files Browse the repository at this point in the history
…bypass
  • Loading branch information
koddsson committed Jun 26, 2024
2 parents 0de84dc + f3c7a94 commit 2136fe0
Show file tree
Hide file tree
Showing 51 changed files with 1,099 additions and 79 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ jobs:
runs-on: macos-latest
permissions:
pull-requests: write
contents: read
checks: write
id-token: write
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
Expand All @@ -27,3 +30,8 @@ jobs:
minimum-coverage: 90
artifact-name: code-coverage-report
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Publish Test Report
uses: mikepenz/action-junit-report@v4
if: success() || failure() # always run even if the previous step fails
with:
report_paths: './test-results.xml'
42 changes: 42 additions & 0 deletions .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
# For more information see: https://help.github.com/actions/language-and-framework-guides/publishing-nodejs-packages

name: Publish to npm

on:
release:
types: [created]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22
- run: npm ci
- run: npx playwright install --with-deps
- run: npm run build --if-present
- run: npm test

publish-npm:
needs: build
runs-on: ubuntu-latest
permissions:
id-token: write
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22.x
registry-url: "https://registry.npmjs.org"
cache: "npm"
- run: npm ci
- run: npm run build --if-present
- run: npm version ${TAG_NAME} --git-tag-version=false
env:
TAG_NAME: ${{ github.ref_name }}
- run: npm publish --provenance --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.npm_secret }}
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
|| aria-input-field-name | https://dequeuniversity.com/rules/axe/4.4/aria-input-field-name?application=RuleDescription | Ensures every ARIA input field has an accessible name | Moderate, Serious | cat.aria, wcag2a, wcag412, ACT | failure, needs review | [e086e5](https://act-rules.github.io/rules/e086e5) |
|| aria-meter-name | https://dequeuniversity.com/rules/axe/4.4/aria-meter-name?application=RuleDescription | Ensures every ARIA meter node has an accessible name | Serious | cat.aria, wcag2a, wcag111 | failure, needs review | |
|| aria-progressbar-name | https://dequeuniversity.com/rules/axe/4.4/aria-progressbar-name?application=RuleDescription | Ensures every ARIA progressbar node has an accessible name | Serious | cat.aria, wcag2a, wcag111 | failure, needs review | |
| | aria-required-attr | https://dequeuniversity.com/rules/axe/4.4/aria-required-attr?application=RuleDescription | Ensures elements with ARIA roles have all required ARIA attributes | Critical | cat.aria, wcag2a, wcag412 | failure | [4e8ab6](https://act-rules.github.io/rules/4e8ab6) |
| | aria-required-attr | https://dequeuniversity.com/rules/axe/4.4/aria-required-attr?application=RuleDescription | Ensures elements with ARIA roles have all required ARIA attributes | Critical | cat.aria, wcag2a, wcag412 | failure | [4e8ab6](https://act-rules.github.io/rules/4e8ab6) |
|| aria-required-children | https://dequeuniversity.com/rules/axe/4.4/aria-required-children?application=RuleDescription | Ensures elements with an ARIA role that require child roles contain them | Critical | cat.aria, wcag2a, wcag131 | failure, needs review | [bc4a75](https://act-rules.github.io/rules/bc4a75) |
|| aria-required-parent | https://dequeuniversity.com/rules/axe/4.4/aria-required-parent?application=RuleDescription | Ensures elements with an ARIA role that require parent roles are contained by them | Critical | cat.aria, wcag2a, wcag131 | failure | [ff89c9](https://act-rules.github.io/rules/ff89c9) |
|| aria-roledescription | https://dequeuniversity.com/rules/axe/4.4/aria-roledescription?application=RuleDescription | Ensure aria-roledescription is only used on elements with an implicit or explicit role | Serious | cat.aria, wcag2a, wcag412 | failure, needs review | |
|| aria-roles | https://dequeuniversity.com/rules/axe/4.4/aria-roles?application=RuleDescription | Ensures all elements with a role attribute use a valid value | Minor, Serious, Critical | cat.aria, wcag2a, wcag412 | failure | [674b10](https://act-rules.github.io/rules/674b10) |
|| aria-toggle-field-name | https://dequeuniversity.com/rules/axe/4.4/aria-toggle-field-name?application=RuleDescription | Ensures every ARIA toggle field has an accessible name | Moderate, Serious | cat.aria, wcag2a, wcag412, ACT | failure, needs review | [e086e5](https://act-rules.github.io/rules/e086e5) |
| | aria-tooltip-name | https://dequeuniversity.com/rules/axe/4.4/aria-tooltip-name?application=RuleDescription | Ensures every ARIA tooltip node has an accessible name | Serious | cat.aria, wcag2a, wcag412 | failure, needs review | |
| | aria-tooltip-name | https://dequeuniversity.com/rules/axe/4.4/aria-tooltip-name?application=RuleDescription | Ensures every ARIA tooltip node has an accessible name | Serious | cat.aria, wcag2a, wcag412 | failure, needs review | |
|| aria-valid-attr-value | https://dequeuniversity.com/rules/axe/4.4/aria-valid-attr-value?application=RuleDescription | Ensures all ARIA attributes have valid values | Serious, Critical | cat.aria, wcag2a, wcag412 | failure, needs review | [6a7281](https://act-rules.github.io/rules/6a7281) |
|| aria-valid-attr | https://dequeuniversity.com/rules/axe/4.4/aria-valid-attr?application=RuleDescription | Ensures attributes that begin with aria- are valid ARIA attributes | Critical | cat.aria, wcag2a, wcag412 | failure | [5f99a7](https://act-rules.github.io/rules/5f99a7) |
|| audio-caption | https://dequeuniversity.com/rules/axe/4.4/audio-caption?application=RuleDescription | Ensures <audio> elements have captions | Critical | cat.time-and-media, wcag2a, wcag121, section508, section508.22.a | needs review | [2eb176](https://act-rules.github.io/rules/2eb176), [afb423](https://act-rules.github.io/rules/afb423) |
Expand Down
120 changes: 58 additions & 62 deletions tests/act/act.js → generate-act-tests.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { fixture, html, expect } from "@open-wc/testing";
import { scan } from "../../src/scanner";
import { mkdir, writeFile, readFile } from "node:fs/promises";

const response = await fetch("/testcases.json");
const json = await response.json();
const { testcases } = JSON.parse(await readFile("./testcases.json", "utf8"));

const applicableRules = json.testcases.filter(
const applicableRules = testcases.filter(
(rule) => rule.ruleAccessibilityRequirements,
);

Expand Down Expand Up @@ -115,6 +113,7 @@ const rulesToIgnore = [
"off6ek",
"oj04fd",
"ucwvc8",
"ye5d6e",
"bf051a",
];

Expand All @@ -125,69 +124,66 @@ const ignoredExamples = [
"https://act-rules.github.io/testcases/qt1vmo/0ef4f516db9ed70cb25f39c99637272808b8e60f.html",
];

const parser = new DOMParser();
for (const rule of applicableRules) {
const {
ruleId,
ruleName,
testcaseId,
testcaseTitle,
expected,
url: exampleURL,
ruleAccessibilityRequirements,
} = rule;

describe("ACT Rules", function () {
for (const rule of applicableRules) {
const {
ruleId,
ruleName,
testcaseId,
testcaseTitle,
expected,
url: exampleURL,
ruleAccessibilityRequirements,
} = rule;
if (testCasesThatRedirect.includes(testcaseId)) continue;
if (ruleName.includes("DEPRECATED")) continue;
if (rulesToIgnore.includes(ruleId)) continue;
if (ignoredExamples.includes(exampleURL)) continue;
// Ignore inapplicable results
if (expected === "inapplicable") continue;

if (testCasesThatRedirect.includes(testcaseId)) continue;
if (ruleName.includes("DEPRECATED")) continue;
if (rulesToIgnore.includes(ruleId)) continue;
if (ignoredExamples.includes(exampleURL)) continue;
console.log({ ruleId, testcaseId });

if (
Object.keys(ruleAccessibilityRequirements).every(
(x) => !x.startsWith("wcag"),
)
if (
Object.keys(ruleAccessibilityRequirements).every(
(x) => !x.startsWith("wcag"),
)
continue;
)
continue;

describe(`[${ruleId}] ${ruleName}`, function () {
it(`${testcaseTitle} (${exampleURL})`, async () => {
const testResponse = await fetch(
`/tests/act/fixtures/${testcaseId}.html`,
);
if (testResponse.status !== 200) {
throw new Error("Couldn't find testcase HTML");
}
const testHTML = await testResponse.text();
const document = parser.parseFromString(testHTML, "text/html");
const html = await readFile(
`./tests/act/fixtures/${testcaseId}.html`,
"utf8",
);

const results = (await scan(document)).map(({ text, url }) => {
return { text, url };
});
let assertion = undefined;
if (expected === "passed") {
assertion = "expect(results).to.be.empty;";
} else if (expected === "failed") {
assertion = "expect(results).to.not.be.empty;";
} else {
throw new Error(`Unknown expected state: ${expected}`);
}

const suite = `import { fixture, expect } from "@open-wc/testing";
import { scan } from "../../../../src/scanner";
describe("[${ruleId}]${ruleName}", function () {
it("${testcaseTitle} (${exampleURL})", async () => {
await fixture(\`${html}\`);
try {
if (expected === "passed") {
expect(results).to.be.empty;
} else if (expected === "failed") {
expect(results).to.not.be.empty;
} else if (expected === "inapplicable") {
// Ignore inapplicable results
} else {
throw new Error(`Unknown expected state: ${expected}`);
}
} catch (error) {
console.log("=======");
console.log(`[${ruleId}] ${ruleName}`);
console.log(testcaseTitle);
console.log(`${testcaseId}.html`);
console.log(Object.keys(ruleAccessibilityRequirements));
console.log("-------");
console.log(testHTML);
console.log("\n");
throw error;
}
});
const results = (await scan(document.body)).map(({ text, url }) => {
return { text, url };
});
}
${assertion}
});
});
`;
await mkdir(`./tests/act/tests/${ruleId}/`, { recursive: true });
await writeFile(
`./tests/act/tests/${ruleId}/${testcaseId}.ts`,
suite,
"utf8",
);
}
38 changes: 36 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 2136fe0

Please sign in to comment.