Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to override timeouts for larger scans #34

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ If you've installed the plugin via `netlify.toml`, you can add a `[[plugins.inpu
| `ignoreElements` | Indicates elements that should be ignored by a11y testing | String (CSS selector) | Comma-separated string of CSS selectors | `undefined` |
| `ignoreGuidelines` | Indicates guidelines and types to ignore ([pa11y docs](https://github.com/pa11y/pa11y#ignore-array)) | Array of strings | Comma-separated string of WCAG Guidlines | `[]` |
| `wcagLevel` | The WCAG standard level against which pages are checked | String | `'WCAG2A'` or `'WCAGA2A'` or `'WCAG2AAA'` | `'WCAG2AA'` |
| `timeout` | Amount of time, in milliseconds, the scan will run before timing out. | Number | Any positive integer | 60000 |

Here's how these inputs can be used in `netlify.toml`, with comments to explain how each input affects the plugin's behavior:

Expand All @@ -119,4 +120,6 @@ Here's how these inputs can be used in `netlify.toml`, with comments to explain
ignoreGuidelines = ['WCAG2AA.Principle1.Guideline1_4.1_4_6.G17']
# Perform a11y check against WCAG 2.1 AAA
wcagLevel = 'WCAG2AAA'
# Extends the timeout of the scan to 2 minutes (120000ms)
timeout = 120000
```
3 changes: 3 additions & 0 deletions manifest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@ inputs:
- name: wcagLevel
default: 'WCAG2AA'
description: The level of WCAG 2.1 against which to check site pages. Defaults to 'WCAGAA'; can also be 'WCAGA' or 'WCAGAAA'.
- name: timeout
default: 60000
description: Amount of time, in milliseconds, the scan will run before timing out. Defaults to 60000.
8 changes: 6 additions & 2 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ type InputT = {
ignoreGuidelines?: string[],
failWithIssues?: boolean,
wcagLevel?: WCAGLevel,
timeout?: number,
}

const DEFAULT_CHECK_PATHS = ['/']
const DEFAULT_FAIL_WITH_ISSUES = true
const DEFAULT_IGNORE_DIRECTORIES: string[] = []
const DEFAULT_TIMEOUT: number = 60000

const PA11Y_DEFAULT_WCAG_LEVEL = 'WCAG2AA'
const PA11Y_RUNNERS = ['axe']
Expand All @@ -24,7 +26,7 @@ export const getConfiguration = async ({
constants: { PUBLISH_DIR },
inputs,
}: Pick<NetlifyPluginOptions, 'constants' | 'inputs'>) => {
const { checkPaths, ignoreDirectories, ignoreElements, ignoreGuidelines, failWithIssues, wcagLevel } =
const { checkPaths, ignoreDirectories, ignoreElements, ignoreGuidelines, failWithIssues, wcagLevel, timeout } =
inputs as InputT
return {
checkPaths: checkPaths || DEFAULT_CHECK_PATHS,
Expand All @@ -34,21 +36,23 @@ export const getConfiguration = async ({
hideElements: ignoreElements,
ignore: ignoreGuidelines,
standard: wcagLevel || PA11Y_DEFAULT_WCAG_LEVEL,
timeout: timeout || DEFAULT_TIMEOUT,
}),
publishDir: (PUBLISH_DIR || process.env.PUBLISH_DIR) as string,
}
}

export type Config = ReturnType<typeof getConfiguration>

export const getPa11yOpts = async ({ hideElements, ignore, standard }: { hideElements?: string; ignore?: string[]; standard: WCAGLevel }) => {
export const getPa11yOpts = async ({ hideElements, ignore, standard, timeout }: { hideElements?: string; ignore?: string[]; standard: WCAGLevel, timeout: number }) => {
return {
browser: await puppeteer.launch({ ignoreHTTPSErrors: true }),
hideElements,
ignore,
runners: PA11Y_RUNNERS,
userAgent: PA11Y_USER_AGENT,
standard,
timeout,
}
}

Expand Down