Skip to content

Commit 28e44c0

Browse files
HiDeoodelucis
andauthored
Tweak a11y e2e tests (#3507)
Co-authored-by: delucis <[email protected]>
1 parent fea3b89 commit 28e44c0

File tree

3 files changed

+59
-36
lines changed

3 files changed

+59
-36
lines changed

.github/workflows/ci.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,15 @@ jobs:
118118
- name: Checkout
119119
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
120120

121+
# Uninstall man-db to prevent man page updates taking a long time after package installations
122+
# on Ubuntu 24.04.
123+
# https://github.com/actions/runner/issues/4030
124+
# https://github.com/actions/runner-images/issues/10977
125+
- name: Uninstall man-db
126+
run: |
127+
sudo apt-get update
128+
sudo apt-get remove man-db
129+
121130
- name: Setup PNPM
122131
uses: pnpm/action-setup@41ff72655975bd51cab0327fa583b6e92b6d3061 # v4.2.0
123132

docs/.pa11yci

Lines changed: 0 additions & 10 deletions
This file was deleted.

docs/__a11y__/test-utils.ts

Lines changed: 50 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ import {
77
} from 'axe-playwright';
88
import Sitemapper from 'sitemapper';
99

10+
// We use the Lunaria config to get the list of languages rather than the Astro config as importing
11+
// the latter does not play well with Playwright.
12+
import lunariaConfig from '../lunaria.config.json' assert { type: 'json' };
13+
1014
export { expect, type Locator } from '@playwright/test';
1115

1216
const config: Config = {
@@ -17,29 +21,35 @@ const config: Config = {
1721
values: ['wcag2a', 'wcag21a', 'wcag2aa', 'wcag21aa', 'wcag22aa', 'best-practice'],
1822
},
1923
},
24+
// i18n specific configuration.
25+
i18n: {
26+
// A list of slugs to exclude from the sitemap for the default locale.
27+
// By default, all slugs for the default locale are included.
28+
exclude: [
29+
'components/using-components',
30+
'getting-started',
31+
'guides/customization',
32+
'guides/i18n',
33+
'guides/overriding-components',
34+
'guides/pages',
35+
'guides/project-structure',
36+
'guides/route-data',
37+
'guides/site-search',
38+
'manual-setup',
39+
'reference/frontmatter',
40+
'reference/overrides',
41+
'reference/plugins',
42+
'reference/route-data',
43+
],
44+
// Locale-specific included slugs (non-default locale slugs are excluded by default).
45+
locales: {
46+
ja: ['guides/route-data', 'reference/frontmatter'],
47+
},
48+
},
2049
// A list of violation to ignore.
2150
ignore: [{ id: 'landmark-unique', nodeMatcher: landmarkUniqueNodeMatcher }],
2251
sitemap: {
2352
url: 'http://localhost:4321/sitemap-index.xml',
24-
exclude: {
25-
// A pattern to exclude URLs from the sitemap.
26-
pattern: /\/(de|zh-cn|fr|es|pt-br|pt-pt|it|id|ko|ru|tr|hi|da|uk)\/.*/,
27-
// A list of slugs to exclude from the sitemap after processing the pattern.
28-
slugs: [
29-
'components/using-components',
30-
'getting-started',
31-
'guides/customization',
32-
'guides/i18n',
33-
'guides/overriding-components',
34-
'guides/pages',
35-
'guides/project-structure',
36-
'guides/site-search',
37-
'manual-setup',
38-
'reference/frontmatter',
39-
'reference/overrides',
40-
'reference/plugins',
41-
],
42-
},
4353
replace: {
4454
query: 'https://starlight.astro.build',
4555
value: 'http://localhost:4321',
@@ -50,6 +60,8 @@ const config: Config = {
5060
process.env.ASTRO_TELEMETRY_DISABLED = 'true';
5161
process.env.ASTRO_DISABLE_UPDATE_CHECK = 'true';
5262

63+
const locales = lunariaConfig.locales.map((locale) => locale.lang);
64+
5365
export const test = baseTest.extend<{
5466
docsSite: DocsSite;
5567
}>({
@@ -71,9 +83,24 @@ class DocsSite {
7183
const urls: string[] = [];
7284

7385
for (const site of sites) {
74-
const url = site.replace(config.sitemap.replace.query, config.sitemap.replace.value);
75-
if (config.sitemap.exclude.pattern.test(url)) continue;
76-
if (config.sitemap.exclude.slugs.some((slug) => url.endsWith(`/${slug}/`))) continue;
86+
const slug = site.replace(config.sitemap.replace.query, '');
87+
const url = config.sitemap.replace.value + slug;
88+
89+
// Default locale
90+
if (!locales.some((locale) => slug.startsWith(`/${locale}/`))) {
91+
// Skip default locale excluded slugs
92+
if (config.i18n.exclude.some((excludedSlug) => slug.endsWith(`/${excludedSlug}/`)))
93+
continue;
94+
} else {
95+
// Get locale-specific config
96+
const locale = slug.split('/')[1]!;
97+
const localeConfig = config.i18n.locales[locale];
98+
// Skip non-configured locales
99+
if (!localeConfig) continue;
100+
// Skip locale-specific non-included slugs
101+
if (!localeConfig.some((includedSlug) => slug.endsWith(`/${includedSlug}/`))) continue;
102+
}
103+
77104
urls.push(url);
78105
}
79106

@@ -129,6 +156,7 @@ function landmarkUniqueNodeMatcher(node: ViolationNode) {
129156

130157
interface Config {
131158
axe: Parameters<typeof getViolations>[2];
159+
i18n: { exclude: string[]; locales: Record<string, string[]> };
132160
ignore: Array<
133161
| string
134162
| {
@@ -140,10 +168,6 @@ interface Config {
140168
>;
141169
sitemap: {
142170
url: string;
143-
exclude: {
144-
pattern: RegExp;
145-
slugs: string[];
146-
};
147171
replace: {
148172
query: string;
149173
value: string;

0 commit comments

Comments
 (0)