@financial-times/n-pa11y-config
v2.1.0
Published
Configuration module for Pa11y CI
Downloads
8,415
Maintainers
Keywords
Readme
n-pa11y-config
This is a module to help creating a Pa11y CI configuration for your project.
Requirements
- Node version defined by
engines.node
inpackage.json
. Run commandnvm use
to switch your local Node version to the one specified in.nvmrc
. - Pa11y CI
Development
git clone [email protected]:Financial-Times/n-pa11y-config.git
cd n-pa11y-config
npm install
Installation
Install from NPM
npm install --save-dev @financial-times/n-pa11y-config
Usage
Include this library on your .pa11yci.js
file and export the result of the invocation of this library:
const nPa11yConfig = require('@financial-times/n-pa11y-config')
const tests = require('./tests/smoke-tests.js')
module.exports = nPa11yConfig({
tests,
host: 'http://localhost:3000',
exceptions: ['__gtg'],
viewports: [
{
width: 640,
height: 960,
},
],
headers: {
'FT-Next-Backend-Key': process.env.FT_NEXT_BACKEND_KEY,
},
})
Configuration
The function expects an object with the following attributes:
| Name | Description | Type | Optional |
| ----------------- | ------------------------------------------------------------------------------------------------------------------------------- | -------------- | -------- |
| tests | Tests to be tested by Pa11y | Array | false |
| host | Base URL to apply to all test routes | String | true |
| exceptions | Routes returning 200 that should not be tested (routes that return something different than 200 will be automatically excluded) | Array | true |
| wait | The time to wait before running tests in milliseconds | Number | true |
| hide | CSS selector to hide elements from testing, selectors can be comma separated | Array | true |
| viewports | Set viewports for puppeteer | Array | true |
| headers | Headers to be added to every test route | Object | true |
| screenCapturePath | Path where to store all the screenshots generated by Pa11y. By default it will store all screenshots in screenCaptures
| String | true |
Headers
Headers can be set:
- globally for all apps (in the
headers
attribute) - per test (configured in the tests array)
Headers objects will be merged, cookies and flags will be concatenated. No flags are allowed inside the cookie for easier merging: use the FT-Flags header instead.
Hide
Include in the hide
attribute the elements that should not run pa11y (i.e. google ad iFrames)
Use with caution. It may break the experience for users.