2024-11-11 18:44:55 +01:00
|
|
|
import {expect, type Page} from '@playwright/test';
|
|
|
|
import {AxeBuilder} from '@axe-core/playwright';
|
|
|
|
|
|
|
|
export async function accessibilityCheck({page}: {page: Page}, includes: string[], excludes: string[], disabledRules: string[]) {
|
|
|
|
// contrast of inline links is still a global issue in Forgejo
|
2024-11-15 01:41:55 +01:00
|
|
|
disabledRules.push('link-in-text-block');
|
2024-11-11 18:44:55 +01:00
|
|
|
|
2024-11-15 01:41:55 +01:00
|
|
|
let accessibilityScanner = new AxeBuilder({page})
|
2024-11-11 18:44:55 +01:00
|
|
|
.disableRules(disabledRules);
|
|
|
|
// passing the whole array seems to be not supported,
|
|
|
|
// iterating has the nice side-effectof skipping this if the array is empty
|
|
|
|
for (const incl of includes) {
|
|
|
|
// passing the whole array seems to be not supported
|
|
|
|
accessibilityScanner = accessibilityScanner.include(incl);
|
|
|
|
}
|
|
|
|
for (const excl of excludes) {
|
|
|
|
accessibilityScanner = accessibilityScanner.exclude(excl);
|
|
|
|
}
|
|
|
|
|
2025-08-29 07:33:59 +02:00
|
|
|
// Scan the page both in dark and light theme.
|
|
|
|
//
|
|
|
|
// Have observed failures during this scanning which are understood to be caused by CSS transitions, either applied to
|
|
|
|
// whatever last action occurred on the page before `accessibilityCheck` was called, or during the transition from
|
|
|
|
// dark to light. As there are a variety of transitions in Forgejo's CSS files (primarily in fomantic) with ease
|
2025-09-02 16:08:58 +02:00
|
|
|
// elements between 0.1 and 0.3 seconds, we give the accessibility scanner up to 2s to settle into success for each
|
2025-08-29 07:33:59 +02:00
|
|
|
// scan.
|
|
|
|
await expect(async () => {
|
|
|
|
const accessibilityScanResults = await accessibilityScanner.analyze();
|
|
|
|
expect(accessibilityScanResults.violations).toEqual([]);
|
2025-09-02 16:08:58 +02:00
|
|
|
}).toPass({timeout: 2000});
|
2025-08-29 07:33:59 +02:00
|
|
|
|
2024-11-11 18:44:55 +01:00
|
|
|
await page.emulateMedia({colorScheme: 'dark'});
|
2025-08-29 07:33:59 +02:00
|
|
|
|
|
|
|
await expect(async () => {
|
|
|
|
const accessibilityScanResults = await accessibilityScanner.analyze();
|
|
|
|
expect(accessibilityScanResults.violations).toEqual([]);
|
2025-09-02 16:08:58 +02:00
|
|
|
}).toPass({timeout: 2000});
|
2025-08-29 07:33:59 +02:00
|
|
|
|
2024-11-11 18:44:55 +01:00
|
|
|
await page.emulateMedia({colorScheme: 'light'});
|
|
|
|
}
|