# n-pa11y-config [![CircleCI](https://circleci.com/gh/Financial-Times/n-pa11y-config.svg?style=svg&circle-token=33bcf2eb98fe2e875cc66de93d7e4a50369c952d)](https://circleci.com/gh/Financial-Times/n-pa11y-config)

This is a module to help creating a Pa11y CI configuration for your project.

## Requirements

- Node version defined by `engines.node` in `package.json`. Run command `nvm use` to switch your local Node version to the one specified in `.nvmrc`.
- [Pa11y CI](https://github.com/pa11y/pa11y-ci)

## Development

```sh
git clone git@github.com:Financial-Times/n-pa11y-config.git
cd n-pa11y-config
npm install
```

## Installation

### Install from NPM

```sh
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:

```javascript
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<Object>  | 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<String>  | 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<String>  | true     |
| viewports         | Set viewports for puppeteer                                                                                                     | Array<Objects> | 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.
