Skip to content

Commit

Permalink
Add full Accessibility Code Checker example for Cypress (#61)
Browse files Browse the repository at this point in the history
* Setup Cypress tests

* Update Alfa

* Typo

* Update yarn

* Update Alfa

* Add some documentation

* Clean up
  • Loading branch information
Jym77 authored Oct 22, 2024
1 parent 38554ed commit 4280810
Show file tree
Hide file tree
Showing 26 changed files with 1,914 additions and 1,792 deletions.
725 changes: 367 additions & 358 deletions .yarn/releases/yarn-4.5.0.cjs → .yarn/releases/yarn-4.5.1.cjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion .yarnrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ enableGlobalCache: false

nodeLinker: node-modules

yarnPath: .yarn/releases/yarn-4.5.0.cjs
yarnPath: .yarn/releases/yarn-4.5.1.cjs
29 changes: 29 additions & 0 deletions accessibility-code-checker/cypress/cypress.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import type { Audit } from "@siteimprove/alfa-test-utils/audit";
import { Logging, SIP } from "@siteimprove/alfa-test-utils/report";

import { defineConfig } from "cypress";

export default defineConfig({
screenshotOnRunFailure: false,

e2e: {
setupNodeEvents(on, config) {
// implement node event listeners here
on("task", {
// Upload audit to Siteimprove Intelligence Platform and log results
async report(audit: Audit.JSON): Promise<null> {
const pageReportUrl = await SIP.upload(audit, {
userName: process.env.SI_USER_EMAIL,
apiKey: process.env.SI_API_KEY,
});

Logging.fromAudit(audit, pageReportUrl).print();

return null;
},
});
},
supportFile: false,
specPattern: "test/**.spec.ts",
},
});
19 changes: 19 additions & 0 deletions accessibility-code-checker/cypress/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"$schema": "http://json.schemastore.org/package",
"name": "code-checker-cypress",
"description": "Demo of using Cypress with the Accessibility Code Checker",
"private": true,
"version": "0.0.0",
"type": "module",
"engines": {
"node": ">=20.0.0"
},
"scripts": {
"test": "cypress run"
},
"devDependencies": {
"@siteimprove/alfa-cypress": "^0.74.2",
"@siteimprove/alfa-test-utils": "^0.74.2",
"cypress": "^13.15.0"
}
}
43 changes: 43 additions & 0 deletions accessibility-code-checker/cypress/test/cypress.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { Cypress as AlfaCypress } from "@siteimprove/alfa-cypress";
import { Audit } from "@siteimprove/alfa-test-utils/audit";

it("should be accessible", () => {
// Navigate to the local web page
// This suppose that the server is already started. See the demo-site folder.
// TODO: Replace with your own page
cy.visit("http://localhost:5173");

// wait for the page to fully load, here by waiting for a specific selector
// TODO: Adapt with what is present in your own page
cy.get(".testimonials-top").should("exist");

const audit = cy
// Get the document from the page
.document()
// Scrape the page
.then(AlfaCypress.toPage)
// Run the audit
.then(Audit.run)
// Upload and log the results.
// Note: this has to happen in NodeJS, not in Cypress browser, hence we use
// a cy.task call.
.then(async (alfaResult) => {
cy.task("report", alfaResult.toJSON());
return alfaResult;
});

// Fail the test if any rule is failing
// Note: this happens in a separate chain to avoid interfering with the
// reporting.
audit.then(async (alfaResult) => {
const failingRules = alfaResult.resultAggregates.filter(
(aggregate) => aggregate.failed > 0,
);

// Fail the test if any rule failed.
expect(failingRules.size).to.equal(
0,
`The page has ${failingRules.size} failing rules`,
);
});
});
12 changes: 12 additions & 0 deletions accessibility-code-checker/cypress/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"$schema": "http://json.schemastore.org/tsconfig",
"extends": "../tsconfig.json",
"compilerOptions": {
"skipLibCheck": true,
"types": ["cypress"]
},
"include": [
"test-utils/**/*.ts",
"test-utils/**/*.tsx"
]
}
4 changes: 2 additions & 2 deletions accessibility-code-checker/playwright/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
},
"devDependencies": {
"@playwright/test": "^1.47.0",
"@siteimprove/alfa-playwright": "^0.74.0",
"@siteimprove/alfa-test-utils": "^0.74.0"
"@siteimprove/alfa-playwright": "^0.74.2",
"@siteimprove/alfa-test-utils": "^0.74.2"
}
}
2 changes: 1 addition & 1 deletion accessibility-code-checker/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"$schema": "http://json.schemastore.org/tsconfig",
"extends": "../tsconfig.json",
"files": [],
"references": [{ "path": "playwright" }]
"references": [{ "path": "cypress" }, { "path": "playwright" }]
}
14 changes: 7 additions & 7 deletions common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
"./persist.js": "./persist.js"
},
"devDependencies": {
"@siteimprove/alfa-act": "^0.93.6",
"@siteimprove/alfa-assert": "^0.74.0",
"@siteimprove/alfa-formatter": "^0.74.0",
"@siteimprove/alfa-hash": "^0.93.6",
"@siteimprove/alfa-mapper": "^0.93.6"
"@siteimprove/alfa-act": "^0.93.8",
"@siteimprove/alfa-assert": "^0.74.2",
"@siteimprove/alfa-formatter": "^0.74.2",
"@siteimprove/alfa-hash": "^0.93.8",
"@siteimprove/alfa-mapper": "^0.93.8"
},
"dependencies": {
"@siteimprove/alfa-formatter-earl": "^0.74.0",
"@siteimprove/alfa-future": "^0.93.6"
"@siteimprove/alfa-formatter-earl": "^0.74.2",
"@siteimprove/alfa-future": "^0.93.8"
}
}
18 changes: 9 additions & 9 deletions custom-testing/adding-rules/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
"node": ">=20.0.0"
},
"devDependencies": {
"@siteimprove/alfa-act": "^0.93.6",
"@siteimprove/alfa-chai": "^0.74.0",
"@siteimprove/alfa-dom": "^0.93.6",
"@siteimprove/alfa-future": "^0.93.6",
"@siteimprove/alfa-playwright": "^0.74.0",
"@siteimprove/alfa-refinement": "^0.93.6",
"@siteimprove/alfa-result": "^0.93.6",
"@siteimprove/alfa-rules": "^0.93.6",
"@siteimprove/alfa-web": "^0.93.6",
"@siteimprove/alfa-act": "^0.93.8",
"@siteimprove/alfa-chai": "^0.74.2",
"@siteimprove/alfa-dom": "^0.93.8",
"@siteimprove/alfa-future": "^0.93.8",
"@siteimprove/alfa-playwright": "^0.74.2",
"@siteimprove/alfa-refinement": "^0.93.8",
"@siteimprove/alfa-result": "^0.93.8",
"@siteimprove/alfa-rules": "^0.93.8",
"@siteimprove/alfa-web": "^0.93.8",
"@types/chai": "^5.0.0",
"@types/mocha": "^10.0.0",
"chai": "^5.0.0",
Expand Down
20 changes: 10 additions & 10 deletions custom-testing/answering/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@
"node": ">=20.0.0"
},
"devDependencies": {
"@siteimprove/alfa-act": "^0.93.6",
"@siteimprove/alfa-chai": "^0.74.0",
"@siteimprove/alfa-css": "^0.93.6",
"@siteimprove/alfa-dom": "^0.93.6",
"@siteimprove/alfa-future": "^0.93.6",
"@siteimprove/alfa-hash": "^0.93.6",
"@siteimprove/alfa-option": "^0.93.6",
"@siteimprove/alfa-playwright": "^0.74.0",
"@siteimprove/alfa-refinement": "^0.93.6",
"@siteimprove/alfa-rules": "^0.93.6",
"@siteimprove/alfa-act": "^0.93.8",
"@siteimprove/alfa-chai": "^0.74.2",
"@siteimprove/alfa-css": "^0.93.8",
"@siteimprove/alfa-dom": "^0.93.8",
"@siteimprove/alfa-future": "^0.93.8",
"@siteimprove/alfa-hash": "^0.93.8",
"@siteimprove/alfa-option": "^0.93.8",
"@siteimprove/alfa-playwright": "^0.74.2",
"@siteimprove/alfa-refinement": "^0.93.8",
"@siteimprove/alfa-rules": "^0.93.8",
"@types/chai": "^5.0.0",
"@types/mocha": "^10.0.0",
"chai": "^5.0.0",
Expand Down
10 changes: 5 additions & 5 deletions custom-testing/crawling/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
"node": ">=20.0.0"
},
"devDependencies": {
"@siteimprove/alfa-act": "^0.93.6",
"@siteimprove/alfa-crawler": "^0.74.0",
"@siteimprove/alfa-frontier": "^0.74.0",
"@siteimprove/alfa-hash": "^0.93.6",
"@siteimprove/alfa-rules": "^0.93.6"
"@siteimprove/alfa-act": "^0.93.8",
"@siteimprove/alfa-crawler": "^0.74.2",
"@siteimprove/alfa-frontier": "^0.74.2",
"@siteimprove/alfa-hash": "^0.93.8",
"@siteimprove/alfa-rules": "^0.93.8"
}
}
18 changes: 9 additions & 9 deletions custom-testing/filtering/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
"node": ">=20.0.0"
},
"devDependencies": {
"@siteimprove/alfa-act": "^0.93.6",
"@siteimprove/alfa-chai": "^0.74.0",
"@siteimprove/alfa-future": "^0.93.6",
"@siteimprove/alfa-hash": "^0.93.6",
"@siteimprove/alfa-iterable": "^0.93.6",
"@siteimprove/alfa-playwright": "^0.74.0",
"@siteimprove/alfa-refinement": "^0.93.6",
"@siteimprove/alfa-rules": "^0.93.6",
"@siteimprove/alfa-wcag": "^0.93.6",
"@siteimprove/alfa-act": "^0.93.8",
"@siteimprove/alfa-chai": "^0.74.2",
"@siteimprove/alfa-future": "^0.93.8",
"@siteimprove/alfa-hash": "^0.93.8",
"@siteimprove/alfa-iterable": "^0.93.8",
"@siteimprove/alfa-playwright": "^0.74.2",
"@siteimprove/alfa-refinement": "^0.93.8",
"@siteimprove/alfa-rules": "^0.93.8",
"@siteimprove/alfa-wcag": "^0.93.8",
"@types/chai": "^5.0.0",
"@types/mocha": "^10.0.0",
"chai": "^5.0.0",
Expand Down
8 changes: 4 additions & 4 deletions custom-testing/interacting/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
"node": ">=20.0.0"
},
"devDependencies": {
"@siteimprove/alfa-chai": "^0.74.0",
"@siteimprove/alfa-future": "^0.93.6",
"@siteimprove/alfa-playwright": "^0.74.0",
"@siteimprove/alfa-rules": "^0.93.6",
"@siteimprove/alfa-chai": "^0.74.2",
"@siteimprove/alfa-future": "^0.93.8",
"@siteimprove/alfa-playwright": "^0.74.2",
"@siteimprove/alfa-rules": "^0.93.8",
"@types/chai": "^5.0.0",
"@types/mocha": "^10.0.0",
"chai": "^5.0.0",
Expand Down
12 changes: 6 additions & 6 deletions custom-testing/measuring-performances/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
"node": ">=20.0.0"
},
"devDependencies": {
"@siteimprove/alfa-act": "^0.93.6",
"@siteimprove/alfa-aria": "^0.93.6",
"@siteimprove/alfa-cascade": "^0.93.6",
"@siteimprove/alfa-performance": "^0.93.6",
"@siteimprove/alfa-rules": "^0.93.6",
"@siteimprove/alfa-scraper": "^0.74.0"
"@siteimprove/alfa-act": "^0.93.8",
"@siteimprove/alfa-aria": "^0.93.8",
"@siteimprove/alfa-cascade": "^0.93.8",
"@siteimprove/alfa-performance": "^0.93.8",
"@siteimprove/alfa-rules": "^0.93.8",
"@siteimprove/alfa-scraper": "^0.74.2"
}
}
8 changes: 4 additions & 4 deletions custom-testing/navigating/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
"node": ">=20.0.0"
},
"devDependencies": {
"@siteimprove/alfa-chai": "^0.74.0",
"@siteimprove/alfa-future": "^0.93.6",
"@siteimprove/alfa-playwright": "^0.74.0",
"@siteimprove/alfa-rules": "^0.93.6",
"@siteimprove/alfa-chai": "^0.74.2",
"@siteimprove/alfa-future": "^0.93.8",
"@siteimprove/alfa-playwright": "^0.74.2",
"@siteimprove/alfa-rules": "^0.93.8",
"@types/chai": "^5.0.0",
"@types/mocha": "^10.0.0",
"chai": "^5.0.0",
Expand Down
8 changes: 4 additions & 4 deletions custom-testing/scraping/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
"test": "node scraping.js"
},
"devDependencies": {
"@siteimprove/alfa-act": "^0.93.6",
"@siteimprove/alfa-hash": "^0.93.6",
"@siteimprove/alfa-rules": "^0.93.6",
"@siteimprove/alfa-scraper": "^0.74.0"
"@siteimprove/alfa-act": "^0.93.8",
"@siteimprove/alfa-hash": "^0.93.8",
"@siteimprove/alfa-rules": "^0.93.8",
"@siteimprove/alfa-scraper": "^0.74.2"
}
}
4 changes: 2 additions & 2 deletions end-to-end-testing/cypress/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
"node": ">=20.0.0"
},
"devDependencies": {
"@siteimprove/alfa-cypress": "^0.74.0",
"@siteimprove/alfa-rules": "^0.93.6",
"@siteimprove/alfa-cypress": "^0.74.2",
"@siteimprove/alfa-rules": "^0.93.8",
"cypress": "^13.3.1"
}
}
8 changes: 4 additions & 4 deletions end-to-end-testing/playwright/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
"node": ">=20.0.0"
},
"devDependencies": {
"@siteimprove/alfa-chai": "^0.74.0",
"@siteimprove/alfa-future": "^0.93.6",
"@siteimprove/alfa-playwright": "^0.74.0",
"@siteimprove/alfa-rules": "^0.93.6",
"@siteimprove/alfa-chai": "^0.74.2",
"@siteimprove/alfa-future": "^0.93.8",
"@siteimprove/alfa-playwright": "^0.74.2",
"@siteimprove/alfa-rules": "^0.93.8",
"@types/chai": "^5.0.0",
"@types/mocha": "^10.0.0",
"chai": "^5.0.0",
Expand Down
8 changes: 4 additions & 4 deletions end-to-end-testing/puppeteer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
"node": ">=20.0.0"
},
"devDependencies": {
"@siteimprove/alfa-chai": "^0.74.0",
"@siteimprove/alfa-future": "^0.93.6",
"@siteimprove/alfa-puppeteer": "^0.74.0",
"@siteimprove/alfa-rules": "^0.93.6",
"@siteimprove/alfa-chai": "^0.74.2",
"@siteimprove/alfa-future": "^0.93.8",
"@siteimprove/alfa-puppeteer": "^0.74.2",
"@siteimprove/alfa-rules": "^0.93.8",
"@types/chai": "^5.0.0",
"@types/mocha": "^10.0.0",
"chai": "^5.0.0",
Expand Down
8 changes: 4 additions & 4 deletions end-to-end-testing/webdriver/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
"node": ">=20.0.0"
},
"devDependencies": {
"@siteimprove/alfa-chai": "^0.74.0",
"@siteimprove/alfa-future": "^0.93.6",
"@siteimprove/alfa-rules": "^0.93.6",
"@siteimprove/alfa-webdriver": "^0.74.0",
"@siteimprove/alfa-chai": "^0.74.2",
"@siteimprove/alfa-future": "^0.93.8",
"@siteimprove/alfa-rules": "^0.93.8",
"@siteimprove/alfa-webdriver": "^0.74.2",
"@types/chai": "^5.0.0",
"@types/mocha": "^10.0.0",
"@wdio/cli": "^5.14.4",
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@
"//": [
"Somehow, https://github.com/enzymejs/enzyme/blob/master/packages/enzyme/package.json correctly pins cheerio",
"but once installed it is replaced with ^1.0.0-rc.3 which resolves to 1.0.0 whose internal organisation has",
"chanrged. This results in non-working enzyme installation."
"changed. This results in non-working enzyme installation."
],
"resolutions": {
"enzyme/cheerio": "=1.0.0-rc.3"
},
"packageManager": "[email protected].0"
"packageManager": "[email protected].1"
}
8 changes: 4 additions & 4 deletions unit-testing/angular/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@
"zone.js": "^0.11.4"
},
"devDependencies": {
"@siteimprove/alfa-angular": "^0.74.0",
"@siteimprove/alfa-future": "^0.93.6",
"@siteimprove/alfa-jest": "^0.74.0",
"@siteimprove/alfa-rules": "^0.93.6",
"@siteimprove/alfa-angular": "^0.74.2",
"@siteimprove/alfa-future": "^0.93.8",
"@siteimprove/alfa-jest": "^0.74.2",
"@siteimprove/alfa-rules": "^0.93.8",
"@types/jest": "^29.5.1",
"common": "workspace:^",
"jest": "^29.5.0",
Expand Down
Loading

0 comments on commit 4280810

Please sign in to comment.