mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-09-12 22:07:17 +00:00
Because the flakiness of this check seems to be also present in Firefox, this is an attempt at reducing the flakiness, as an alternative to #9118. Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/9137 Reviewed-by: Mathieu Fenniak <mfenniak@noreply.codeberg.org> Co-authored-by: Antonin Delpeuch <antonin@delpeuch.eu> Co-committed-by: Antonin Delpeuch <antonin@delpeuch.eu>
40 lines
1.8 KiB
TypeScript
40 lines
1.8 KiB
TypeScript
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
|
|
disabledRules.push('link-in-text-block');
|
|
|
|
let accessibilityScanner = new AxeBuilder({page})
|
|
.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);
|
|
}
|
|
|
|
// 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
|
|
// elements between 0.1 and 0.3 seconds, we give the accessibility scanner up to 2s to settle into success for each
|
|
// scan.
|
|
await expect(async () => {
|
|
const accessibilityScanResults = await accessibilityScanner.analyze();
|
|
expect(accessibilityScanResults.violations).toEqual([]);
|
|
}).toPass({timeout: 2000});
|
|
|
|
await page.emulateMedia({colorScheme: 'dark'});
|
|
|
|
await expect(async () => {
|
|
const accessibilityScanResults = await accessibilityScanner.analyze();
|
|
expect(accessibilityScanResults.violations).toEqual([]);
|
|
}).toPass({timeout: 2000});
|
|
|
|
await page.emulateMedia({colorScheme: 'light'});
|
|
}
|