Skip to content

Commit b05e1cc

Browse files
Add JavaScript config example to README
1 parent e7b7c17 commit b05e1cc

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

README.md

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ Pa11y CI runs accessibility tests against multiple URLs and reports on any issue
1818
* [Requirements](#requirements)
1919
* [Usage](#usage)
2020
* [Configuration](#configuration)
21-
* [Default configuration](#default-configuration)
22-
* [URL configuration](#url-configuration)
21+
* [Default configuration](#default-configuration)
22+
* [URL configuration](#url-configuration)
23+
* [Javascript configuration](#javascript-configuration)
2324
* [Sitemaps](#sitemaps)
2425
* [Reporters](#reporters)
2526
* [Use Multiple reporters](#use-multiple-reporters)
@@ -78,7 +79,7 @@ You can use the `--config` command line argument to specify a different file, wh
7879

7980
Pa11y will be run against each of the URLs in the `urls` array and the paths specified as CLI arguments. Paths can be specified as relative, absolute and as [glob](https://github.com/isaacs/node-glob#glob) patterns.
8081

81-
### Default configuration
82+
#### Default configuration
8283

8384
You can specify a default set of [pa11y configurations] that should be used for each test run. These should be added to a `defaults` object in your config. For example:
8485

@@ -103,7 +104,7 @@ Pa11y CI has a few of its own configurations which you can set as well:
103104
* `concurrency`: The number of tests that should be run in parallel. Defaults to `1`.
104105
* `useIncognitoBrowserContext`: Run test with an isolated incognito browser context, stops cookies being shared and modified between tests. Defaults to `true`.
105106

106-
### URL configuration
107+
#### URL configuration
107108

108109
Each URL in your config file can be an object and specify [pa11y configurations] which override the defaults too. You do this by using an object instead of a string, and providing the URL as a `url` property on that object. This can be useful if, for example, you know that a certain URL takes a while to load or you want to check what the page looked like when the tests were run:
109110

@@ -123,6 +124,26 @@ Each URL in your config file can be an object and specify [pa11y configurations]
123124
}
124125
```
125126

127+
#### Javascript configuration
128+
129+
If a JavaScript configuration file is used, it should be a CommonJS module that exports a configuration object. This can be used to dynamically update configuration parameters, for example taking data from environment variables as shown in the example below.
130+
131+
```js
132+
module.exports = {
133+
defaults: {
134+
timeout: 1000,
135+
viewport: {
136+
width: 320,
137+
height: 480
138+
},
139+
headers: {
140+
token: process.env.TOKEN
141+
}
142+
},
143+
urls: ["https://pa11y.org/", "https://pa11y.org/contributing"]
144+
};
145+
```
146+
126147
### Sitemaps
127148

128149
If you don't wish to specify your URLs in a config file, you can use an XML sitemap that's published somewhere online. This is done with the `--sitemap` option:

0 commit comments

Comments
 (0)