-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: setup accessibility testing and linting (#134)
<!-- Is your PR related to an issue? Then please link it via the "closes #" below. Else, remove it. --> closes #63 ## Description - Setup Playwright for a11y testing - Setup eslint plugin to show a11y violations while development
- Loading branch information
1 parent
7549554
commit 08673d0
Showing
16 changed files
with
201 additions
and
82 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module.exports = { | ||
root: false, // will be merged with our global config | ||
env: { | ||
node: true, | ||
}, | ||
}; |
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,16 @@ | ||
{ | ||
"name": "@sit-onyx/eslint-plugin", | ||
"description": "Custom eslint rules that should be used for all packages of this monorepo", | ||
"private": true, | ||
"version": "0.0.0", | ||
"type": "commonjs", | ||
"author": "Schwarz IT KG", | ||
"license": "Apache-2.0", | ||
"main": "./src/index.cjs", | ||
"peerDependencies": { | ||
"eslint": ">= 8" | ||
}, | ||
"devDependencies": { | ||
"@types/eslint": "^8.56.2" | ||
} | ||
} |
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 @@ | ||
// @ts-check | ||
const packageJson = require("../package.json"); | ||
|
||
module.exports = { | ||
meta: { | ||
name: packageJson.name, | ||
version: packageJson.version, | ||
}, | ||
rules: { | ||
"import-playwright-a11y": require("./rules/import-playwright-a11y.cjs"), | ||
}, | ||
}; |
41 changes: 41 additions & 0 deletions
41
packages/eslint-plugin/src/rules/import-playwright-a11y.cjs
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,41 @@ | ||
// @ts-check | ||
|
||
/** | ||
* @type {import('eslint').Rule.RuleModule} | ||
*/ | ||
module.exports = { | ||
meta: { | ||
type: "problem", | ||
docs: { | ||
recommended: true, | ||
description: | ||
"Prevents importing test and except from Playwright when a custom fixture is available", | ||
}, | ||
}, | ||
create: (context) => ({ | ||
ImportSpecifier(node) { | ||
// allow the fixture itself to import from Playwright directly | ||
if (context.filename.endsWith("/playwright-axe.ts")) return; | ||
|
||
const hasFixture = ["expect", "test"].includes(node.imported.name); | ||
if (!hasFixture) return; | ||
|
||
// type check that node.parent.source.value exists | ||
if (!("source" in node.parent) || !("value" in node.parent.source)) { | ||
return; | ||
} | ||
|
||
const isDisallowedImport = ["@playwright/test", "@playwright/experimental-ct-vue"].includes( | ||
node.parent.source.value.toString(), | ||
); | ||
|
||
if (isDisallowedImport) { | ||
context.report({ | ||
node, | ||
loc: node.loc, | ||
message: `Import "${node.imported.name}" from "../../playwright-axe" instead because Onyx uses custom Playwright fixtures for providing a global configuration for accessability testing.`, | ||
}); | ||
} | ||
}, | ||
}), | ||
}; |
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
Binary file modified
BIN
+39 Bytes
(100%)
packages/sit-onyx/playwright/snapshots/TestInput/default-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+61 Bytes
(100%)
packages/sit-onyx/playwright/snapshots/TestInput/default-firefox-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-44 Bytes
(99%)
packages/sit-onyx/playwright/snapshots/TestInput/default-webkit-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 |
---|---|---|
|
@@ -185,9 +185,6 @@ watch( | |
color: darkred; | ||
margin: 0; | ||
} | ||
&__info { | ||
color: grey; | ||
} | ||
&--touched { | ||
input:valid { | ||
|
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,25 @@ | ||
import AxeBuilder from "@axe-core/playwright"; | ||
import { test as base } from "@playwright/experimental-ct-vue"; | ||
|
||
export { expect } from "@playwright/experimental-ct-vue"; | ||
|
||
type AxeFixture = { | ||
makeAxeBuilder: () => AxeBuilder; | ||
}; | ||
|
||
/** | ||
* Extends Playwright's base test by providing `makeAxeBuilder` | ||
* This new `test` can be used in multiple test files, and each of them will get | ||
* a consistently configured AxeBuilder instance. | ||
* | ||
* @see https://playwright.dev/docs/accessibility-testing#using-a-test-fixture-for-common-axe-configuration | ||
*/ | ||
export const test: ReturnType<typeof base.extend<AxeFixture>> = base.extend<AxeFixture>({ | ||
makeAxeBuilder: async ({ page }, use) => { | ||
const makeAxeBuilder = () => { | ||
return new AxeBuilder({ page }).withTags(["wcag2a", "wcag2aa", "wcag21a", "wcag21aa"]); | ||
}; | ||
|
||
await use(makeAxeBuilder); | ||
}, | ||
}); |
Oops, something went wrong.