Skip to content

Commit 8b5abbb

Browse files
authored
Improve DX, add failing a11y tests (#142)
* Add a11y test (failing) * Test on local build, document scripts, sort package.json * Update dev guide * Use local hugo to build site * Fixup CI pipeline * Document local vs global Hugo, role of Node * Use hugo-bin instead of hugo-extended * Update readme * Revert "Update readme" This reverts commit f368bcb. * Revert "Use hugo-bin instead of hugo-extended" This reverts commit 618d49d.
1 parent de05707 commit 8b5abbb

File tree

8 files changed

+2268
-182
lines changed

8 files changed

+2268
-182
lines changed

.github/workflows/build.yml

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,12 @@ on: [push, pull_request]
55
jobs:
66
build:
77
runs-on: ubuntu-latest
8-
strategy:
9-
matrix:
10-
hugo-version:
11-
- 'latest'
12-
- '0.134.2'
138
steps:
149
- uses: actions/checkout@v4
1510
with:
1611
submodules: true
1712
fetch-depth: 0
18-
19-
- name: Setup Hugo
20-
uses: peaceiris/actions-hugo@v3
21-
with:
22-
hugo-version: ${{ matrix.hugo-version }}
23-
extended: true
24-
25-
- name: Run Hugo
26-
run: hugo --panicOnWarning
13+
- name: Install depdencies
14+
run: npm ci
15+
- name: Build site to check for errors
16+
run: npm run build:ci

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,7 @@ hugo.linux
1313
/.hugo_build.lock
1414

1515
# Node
16-
node_modules
16+
node_modules
17+
18+
# A11y checker
19+
test-results

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,24 @@ Theme: [hugo-book](https://themes.gohugo.io/themes/hugo-book/)
77
See [/content](/content/) for content.
88

99
See [About This Site](content/about-this-site/_index.md) for more information
10+
11+
## package.json
12+
13+
`package.json` dependencies and scripts are described here for readability:
14+
15+
- scripts
16+
- `build`: Builds the site to ensure changes are valid
17+
- `build:ci`: Builds the site but fails if any warnings are detected. Used in our CI pipeline.
18+
- `format:fix`: Fixes formatting of the `package.json` file
19+
- `start`: Builds and serves the site at http://localhost:1313 with Hugo.
20+
- `test:a11y`: Builds and serves the site, then uses Playwright and axe to test accessibility
21+
- `test:a11y:tests`: Not meant for independent use, only as part of `test:a11y`
22+
- `test:spelling`: Reports all apparent spelling errors. WIP, ref [#83](https://github.com/minetest/dev.luanti.org/issues/83) for details.
23+
- depdendencies
24+
- `hugo-extended`: Static site generator that turns Markdown and shortcodes into HTML
25+
- devDependencies
26+
- [`@axe-core/playwright`](https://npmjs.com/package/@axe-core/playwright): A11y tester bindings for Playwright
27+
- [`@playwright/test`](https://npmjs.com/package/@playwright/test): Browser automation and test library
28+
- [`cspell`](https://npmjs.com/package/cspell): Spellchecker
29+
- [`sort-package-json`](https://npmjs.com/package/sort-package-json): Sorts package.json files for consistency
30+
- [`start-server-and-test`](https://npmjs.com/package/start-server-and-test): Allows easy setup and teardown of complex tests, like our a11y tests

a11y/a11y.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { test, expect } from '@playwright/test';
2+
import AxeBuilder from '@axe-core/playwright';
3+
4+
test.describe('homepage', () => {
5+
test('should not have any automatically detectable accessibility issues', async ({ page }) => {
6+
await page.goto('http://localhost:1313/');
7+
8+
const results = await new AxeBuilder({ page }).analyze();
9+
10+
expect(results.violations).toEqual([]);
11+
});
12+
});

a11y/readme.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Accessibility (a11y)
2+
3+
This folder contains test files to help us review the accessibility of the site. We use `Playwright` and `axe` for this. Learn more at [Accessibility testing | Playwright](https://playwright.dev/docs/accessibility-testing).

content/about-this-site/local-development.md

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@ title: Local Development
66

77
_(anyone)_
88

9-
To build locally, you will need to first [install Hugo](https://gohugo.io/installation/).
10-
* Note, you need the extended version
11-
129
When cloning the repository you need to clone it recursively so that the theme submodule gets included:
1310

1411
```bash
@@ -22,17 +19,27 @@ git submodule init
2219
git submodule update --remote
2320
```
2421

25-
To launch the Hugo development server run `hugo server`. It will watch and regenerate whenever changes are made.
22+
This project uses [Hugo](https://gohugo.io/) to build the site and various Node packages to test it.
2623

27-
To generate the site once without starting the server you can simply run `hugo`.
24+
You can install Hugo locally as a [Node.js](https://nodejs.org) package for convenience. Node is also used for further testing scripts, like spell-checking and a11y. These scripts are described in `package.json` and `readme.md`.
2825

29-
Some additional checks are run in [Node](npmjs.org):
26+
To install and run via Node:
3027

3128
```bash
32-
npm install
33-
npm test
29+
npm install # Installs packages needed to build and test the site
30+
npm start # Builds and serves the site on a localhost port for manual testing
3431
```
3532

33+
If you prefer, you can manually install the relevant "extended" release globally from [Installation | Hugo](https://gohugo.io/installation/). Be sure to match the version present in `hugo.yaml`.
34+
35+
To run globally:
36+
37+
```bash
38+
hugo server # This is the command internal to the `npm start` command
39+
```
40+
41+
## Spellchecker
42+
3643
You can disable the spell checker with Hugo comments:
3744

3845
```md

0 commit comments

Comments
 (0)