Skip to content

Commit 6cb6e3f

Browse files
authored
test(axe): expand accessibility regression coverage (#14713)
Recent axe-core changes (#14607, #14655, #14667, #14677, #14680) reworked the accessibility-report feature repeatedly with no dedicated regression tests guarding several of its behaviors. A coverage audit found three gaps; this closes them. - No test guarded against reintroducing a CDN dependency for axe-core, despite #14677 vendoring it specifically to drop the Skypack CDN. - The report overlay's keyboard-scrollable region (added in #14680) was only checked for static tabindex/role attributes, never an actual keypress. - The self-scan pattern (added in #14680) only covered the plain-HTML overlay, not the RevealJS report slide or dashboard offcanvas that render the same violation markup. Extending the self-scan to RevealJS and the dashboard surfaced a real pre-existing issue: both report-chrome regions are scrollable but not keyboard-focusable once they overflow, the same class of gap already fixed for the plain-HTML overlay. Filed as #14710, not fixed here — the dashboard test filters that one known node out of the scrollable-region-focusable violation (not the whole violation), so it still catches other regressions in that scope. Related to #14710
1 parent 159913f commit 6cb6e3f

2 files changed

Lines changed: 208 additions & 0 deletions

File tree

‎tests/integration/playwright/tests/axe-accessibility.spec.ts‎

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,90 @@ test.describe('HTML axe — the report overlay passes its own scan', () => {
408408
});
409409
});
410410

411+
test.describe('RevealJS axe — the report slide passes its own scan', () => {
412+
test('report slide has no axe-core violations', async ({ page }) => {
413+
// The report slide is injected after the page scan runs, so it never
414+
// audits itself (same gap as the HTML overlay). Scan it here with the
415+
// same vendored axe-core build the deck already loaded (window.axe).
416+
//
417+
// createReportSlide() navigates back to the original slide, leaving the
418+
// report slide as a hidden future slide (hidden + aria-hidden). axe skips
419+
// hidden elements, so we MUST navigate to the report slide and wait for
420+
// `.present` first — otherwise the scan is a vacuous, permanent PASS.
421+
await page.goto('/revealjs/axe-accessibility.html', { waitUntil: 'networkidle' });
422+
423+
const reportSlide = page.locator('section.quarto-axe-report-slide');
424+
await expect(reportSlide).toBeAttached({ timeout: 10000 });
425+
await waitForAxeCompletion(page);
426+
427+
await page.evaluate(() => Reveal.slide(Reveal.getTotalSlides() - 1));
428+
await expect(reportSlide).toHaveClass(/present/);
429+
430+
// Non-empty precondition: guards against the region silently becoming
431+
// empty in a future refactor, which would make violations == [] a
432+
// vacuous pass rather than a real guard.
433+
await expect(
434+
reportSlide.locator('.quarto-axe-violation-description'),
435+
).not.toHaveCount(0);
436+
437+
const violations = await page.evaluate(async () => {
438+
const axe = (window as any).axe;
439+
const result = await axe.run(document.querySelector('.quarto-axe-report-slide'));
440+
return result.violations.map((v: { id: string; nodes: { target: string[] }[] }) => ({
441+
id: v.id,
442+
targets: v.nodes.map((n) => n.target),
443+
}));
444+
});
445+
expect(violations).toEqual([]);
446+
});
447+
});
448+
449+
test.describe('Dashboard axe — the offcanvas passes its own scan', () => {
450+
test('offcanvas and toggle have no axe-core violations', async ({ page }) => {
451+
// The offcanvas and its toggle button are injected after the page scan
452+
// runs, so they never audit themselves on initial load. Scan both here.
453+
// The toggle (.quarto-axe-toggle) is a SIBLING of #quarto-axe-offcanvas
454+
// (both appended to <body>), so it must be an explicit include — scanning
455+
// the offcanvas alone would miss a dropped aria-label on the toggle.
456+
await page.goto('/dashboard/axe-accessibility.html', { waitUntil: 'networkidle' });
457+
458+
const offcanvas = page.locator('#quarto-axe-offcanvas');
459+
await expect(offcanvas).toBeVisible({ timeout: 10000 });
460+
461+
// Non-empty precondition — see reveal test above for rationale.
462+
await expect(
463+
offcanvas.locator('.quarto-axe-violation-description'),
464+
).not.toHaveCount(0);
465+
466+
const violations = await page.evaluate(async () => {
467+
const axe = (window as any).axe;
468+
const result = await axe.run({
469+
include: [['#quarto-axe-offcanvas'], ['.quarto-axe-toggle']],
470+
});
471+
return result.violations.map((v: { id: string; nodes: { target: string[] }[] }) => ({
472+
id: v.id,
473+
targets: v.nodes.map((n) => n.target),
474+
}));
475+
});
476+
477+
// Known issue quarto-dev/quarto-cli#14710: .offcanvas-body is a scrolling
478+
// region with no focusable descendant and isn't itself focusable, so it
479+
// trips scrollable-region-focusable even on this short fixture (its fixed
480+
// height already overflows). That one node is filtered out (not
481+
// test.fail()'d) at the node level — not the whole violation — so this
482+
// test still catches any other regression here, including a second,
483+
// unrelated scrollable-region-focusable node — while #14710 is open.
484+
const unexpected = violations
485+
.map((v) =>
486+
v.id === 'scrollable-region-focusable'
487+
? { ...v, targets: v.targets.filter((t) => !t.includes('.offcanvas-body')) }
488+
: v,
489+
)
490+
.filter((v) => v.targets.length > 0);
491+
expect(unexpected).toEqual([]);
492+
});
493+
});
494+
411495
test.describe('Dashboard axe — re-scan on visibility change', () => {
412496
const pagesUrl = '/dashboard/axe-accessibility-pages.html';
413497

@@ -680,3 +764,86 @@ test.describe('Axe — standard and best-practice scoping (#14607)', () => {
680764
.not.toContain('heading');
681765
});
682766
});
767+
768+
test.describe('Axe — no third-party/CDN dependency (regression guard for #14677)', () => {
769+
const CDN_DENYLIST = [
770+
'skypack.dev',
771+
'unpkg.com',
772+
'jsdelivr.net',
773+
'esm.sh',
774+
'cdnjs.cloudflare.com',
775+
];
776+
777+
function cdnHost(url: string): string | null {
778+
let hostname: string;
779+
try {
780+
hostname = new URL(url).hostname;
781+
} catch {
782+
return null;
783+
}
784+
return CDN_DENYLIST.find(
785+
(base) => hostname === base || hostname.endsWith('.' + base),
786+
) ?? null;
787+
}
788+
789+
test('html — axe-enabled page makes no request to a package CDN', async ({ page }) => {
790+
const cdnRequests: string[] = [];
791+
page.on('request', (req) => {
792+
if (cdnHost(req.url())) cdnRequests.push(req.url());
793+
});
794+
795+
await page.goto('/html/axe-accessibility.html', { waitUntil: 'networkidle' });
796+
await waitForAxeCompletion(page);
797+
798+
expect(
799+
cdnRequests,
800+
`axe-enabled page must not load resources from a package CDN. ` +
801+
`Offending request(s): ${cdnRequests.join(', ')}`,
802+
).toEqual([]);
803+
});
804+
});
805+
806+
test.describe('HTML axe — the report overlay scrolls by keyboard (#14680)', () => {
807+
// Commit 4a528a2e3 made the fixed overlay a focusable scroll region so a
808+
// report taller than max-height: 50vh can be scrolled from the keyboard.
809+
// Keyboard scrolling here is *native* browser behavior (overflow-y: auto +
810+
// tabindex=0, no keydown handler), so the regression this guards is the
811+
// scroll behavior breaking — overflow-y flipped away from auto, or a future
812+
// keydown handler swallowing the keys — while tabindex/role/aria-label stay
813+
// intact. Those cases pass the static attribute checks (line ~172) AND the
814+
// overlay self-scan (scrollable-region-focusable, line ~388), so only an
815+
// actual key press that moves scrollTop catches them.
816+
for (const key of ['PageDown', 'ArrowDown']) {
817+
test(`html — focused overlay scrolls on ${key}`, async ({ page }) => {
818+
await page.goto('/html/axe-overlay-scroll.html', { waitUntil: 'networkidle' });
819+
820+
const axeReport = page.locator('.quarto-axe-report');
821+
await expect(axeReport).toBeVisible({ timeout: 10000 });
822+
823+
// Precondition: the fixture must inflate the report past its max-height,
824+
// or there is nothing to scroll and a green result would be meaningless.
825+
const overflow = await axeReport.evaluate(
826+
(el) => ({ scrollHeight: el.scrollHeight, clientHeight: el.clientHeight }),
827+
);
828+
expect(
829+
overflow.scrollHeight,
830+
`overlay must overflow to be scrollable (scrollHeight ${overflow.scrollHeight} ` +
831+
`must exceed clientHeight ${overflow.clientHeight}); check axe-overlay-scroll.qmd`,
832+
).toBeGreaterThan(overflow.clientHeight);
833+
834+
// Start from the top and put focus on the overlay itself. toBeFocused is
835+
// test hygiene: it proves the key goes to the overlay, not the document,
836+
// so a scrollTop change can only mean the overlay scrolled.
837+
await axeReport.evaluate((el) => { el.scrollTop = 0; });
838+
await axeReport.focus();
839+
await expect(axeReport).toBeFocused();
840+
841+
await page.keyboard.press(key);
842+
843+
// Native key scroll is instant, but poll to avoid any timing race.
844+
await expect
845+
.poll(() => axeReport.evaluate((el) => el.scrollTop), { timeout: 3000 })
846+
.toBeGreaterThan(0);
847+
});
848+
}
849+
});

‎tests/unit/axe-no-cdn.test.ts‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* axe-no-cdn.test.ts
3+
*
4+
* PR #14677 vendored axe-core so accessibility checking works offline and no
5+
* request goes to a CDN at runtime. The Playwright behavioral guard cannot
6+
* catch a *fallback* CDN load that only fires when the vendored file 404s
7+
* (the file returns 200 in tests). This static check does: it fails if either
8+
* the checker module or its dependency-wiring hard-codes a package-CDN host.
9+
*
10+
* Copyright (C) 2020-2025 Posit Software, PBC
11+
*/
12+
13+
import { unitTest } from "../test.ts";
14+
import { assertEquals } from "testing/asserts";
15+
16+
const CDN_DENYLIST = [
17+
"skypack.dev",
18+
"unpkg.com",
19+
"jsdelivr.net",
20+
"esm.sh",
21+
"cdnjs.cloudflare.com",
22+
];
23+
24+
const SCANNED_FILES = [
25+
"../../src/resources/formats/html/axe/axe-check.js",
26+
"../../src/format/html/format-html-axe.ts",
27+
];
28+
29+
// deno-lint-ignore require-await
30+
unitTest("axe dependency wiring references no package CDN (regression guard #14677)", async () => {
31+
for (const relPath of SCANNED_FILES) {
32+
const src = Deno.readTextFileSync(new URL(relPath, import.meta.url));
33+
const offenders = CDN_DENYLIST.filter((host) => src.includes(host));
34+
assertEquals(
35+
offenders,
36+
[],
37+
`${relPath} must not reference a package CDN (found: ${offenders.join(", ")}). ` +
38+
`axe-core is vendored (#14677); load it same-origin, not from a CDN.`,
39+
);
40+
}
41+
});

0 commit comments

Comments
 (0)