Repository Public
1/**2 * =============================================================================3 * SP BOUCHER | SOFTWARE & RESEARCH4 * ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project : UQO Éval — Le Grand Défi Immobilier8 * File : tests/accessibility/axe.mjs9 * Module : tests10 * Repository : https://git.spboucher.ai/uqo-eval-jeux11 * Project Website : https://jeux.uqo-eval.app12 * Created : 2026-11-2513 * Last Modified : 2026-11-2514 *15 * Author : Simon-Pierre Boucher16 * Position : Professor of Finance17 * Institution : Université du Québec en Outaouais (UQO)18 * Organization : SP Boucher19 * Website : https://spboucher.ai20 * Git : https://git.spboucher.ai21 *22 * Preferred Contact: contact@spboucher.ai23 * Development : dev@spboucher.ai24 * Support : support@spboucher.ai25 * Security/Admin : admin@spboucher.ai26 *27 * Copyright (c) 202628 * Simon-Pierre Boucher29 * All rights reserved where applicable. This file is governed by the30 * applicable project license, copyright notices and relevant law.31 * Existing third-party rights and notices remain unaffected.32 *33 * License : None specified (no license file in this repository)34 *35 * Do not embed credentials, private keys, access tokens,36 * certificates or confidential personal information.37 *38 * =============================================================================39 * END OF SP BOUCHER SOURCE HEADER40 * =============================================================================41 */4243// Audit d'accessibilité automatisé (axe-core, règles WCAG 2.0/2.1/2.2 niveaux A et AA) des écrans principaux.44// Usage : node tests/accessibility/axe.mjs [URL de base] (défaut : http://localhost:8090)45// Un audit automatisé ne détecte qu'une partie des problèmes : il ne remplace pas un essai au clavier et au lecteur d'écran.46import { AxeBuilder } from "@axe-core/playwright";47import { chromium, devices } from "@playwright/test";4849const base = process.argv[2] ?? "http://localhost:8090";50const browser = await chromium.launch();51let total = 0;52const scan = async (page, label) => {53 const results = await new AxeBuilder({ page }).withTags(["wcag2a", "wcag2aa", "wcag21a", "wcag21aa", "wcag22aa"]).analyze();54 total += results.violations.length;55 console.log(`${results.violations.length === 0 ? "OK " : "!! "} ${label} — ${results.violations.length} règle(s) en défaut, ${results.passes.length} réussie(s)`);56 for (const v of results.violations) console.log(` ${v.id} (${v.impact}) × ${v.nodes.length} : ${v.help}\n ex. ${v.nodes[0].target.join(" ")} ${(v.nodes[0].failureSummary ?? "").split("\n").slice(1, 2).join(" ").trim().slice(0, 160)}`);57};58for (const [device, options] of [["ordinateur", { viewport: { width: 1440, height: 900 } }], ["mobile", { ...devices["iPhone 14"] }]]) {59 const context = await browser.newContext({ ...options, locale: "fr-CA", reducedMotion: "reduce" });60 const page = await context.newPage();61 await page.goto(base, { waitUntil: "networkidle" });62 await scan(page, `${device} · accueil`);63 await page.locator(".entry-alt").click();64 await page.waitForURL(/jouer/);65 await page.waitForTimeout(1800); // laisse finir l'apparition progressive des règles avant de mesurer les contrastes66 await scan(page, `${device} · introduction`);67 await page.click(".intro button");68 await page.waitForSelector(".choice:not([disabled])");69 await page.waitForTimeout(900);70 await scan(page, `${device} · question`);71 await page.locator(".choice").first().click();72 await page.click(".answer-submit");73 await page.waitForSelector(".feedback-foot button");74 await page.waitForTimeout(900);75 await scan(page, `${device} · rétroaction`);76 for (const [path, label] of [["/classement", "classement"], ["/regles", "règles"], ["/confidentialite", "confidentialité"], ["/reprendre", "reprise"], ["/admin", "administration"]]) {77 await page.goto(base + path, { waitUntil: "networkidle" });78 await page.waitForTimeout(900);79 await scan(page, `${device} · ${label}`);80 }81 await context.close();82}83await browser.close();84console.log(`\nTotal : ${total} règle(s) en défaut.`);85process.exit(total === 0 ? 0 : 1);86