Testing in CI
postdoc test exits with a non-zero code when a test or check fails, which fails the CI job.
What the job needs
Your code
A push or a pull request
Dependencies
npm ci installs Postdoc and Nightwatch
A browser
Chrome is on the Ubuntu runners
npx postdoc test
1
Build
The site, into the output folder
2
Serve
The build, on a free port
3
Check
Every page, in the browser
4
Test
Your own tests, on the same build
GitHub Actions
The Ubuntu runners have Chrome installed:
yaml
name: Docs
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: actions/setup-node@v7
with:
node-version: 22
cache: npm
- run: npm ci
- run: npx postdoc check
- run: npx postdoc test --report page-checks.jsonpostdoc check takes seconds and finds what a browser isn't needed for, such as broken links, so the job fails early when there is one. --report writes what the page checks found as JSON, for a later step to read.
Deploy what was tested
postdoc test leaves the build in the output folder, so a later step can deploy exactly what was tested. GitHub Pages has a workflow that tests the site and then deploys it.