-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add full Accessibility Code Checker example for Cypress (#61)
* Setup Cypress tests * Update Alfa * Typo * Update yarn * Update Alfa * Add some documentation * Clean up
- Loading branch information
Showing
26 changed files
with
1,914 additions
and
1,792 deletions.
There are no files selected for viewing
725 changes: 367 additions & 358 deletions
725
.yarn/releases/yarn-4.5.0.cjs → .yarn/releases/yarn-4.5.1.cjs
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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`, | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.