Pa11y's API changes between major versions. This is a guide to help you make the switch when this happens.
- Migrating from 4.0 to 5.0
- Migrating from 3.0 to 4.0
- Migrating from 2.0 to 3.0
- Migrating from 1.0 to 2.0
Pa11y 5.0 switches from PhantomJS to Headless Chrome. This allows us to use more modern JavaScript APIs and make Pa11y testing more stable.
Pa11y 5.0 only supports Node.js v8.0.0 and higher, you'll need to upgrade to be able to use the latest versions of Pa11y.
Pa11y 5.0 ignores warnings and notices by default, as these are not usually actionable or useful in automated testing.
You can force Pa11y to include warnings and notices again by using the --include-notices and --include-warnings command-line flags, or the includeNotices and includeWarnings options.
The command-line interface in 5.0 is similar to 4.0, but there are a few key changes.
- The
--verify-pageflag has been removed, as page verification can be achieved with screen-shots or observing the debug output - The
--htmlcsflag has been removed, you can no longer configure the version of HTML CodeSniffer that Pa11y uses. An alternative would be to fork Pa11y for your individual use and replace HTML CodeSniffer, we'll be reviewing how we allow this again in future - The
--portflag has been removed, as this is not required to run multiple Headless Chrome instances
Pa11y is now completely Promise-based, and uses async/await internally. This means the API has changed significantly.
You no longer need to create a separate test function, now Pa11y is just one function: pa11y(url, options). See the README for more information.
The following reporters have been removed from Pa11y:
html: The HTML reporter has moved outside of Pa11y, please install usingnpm install pa11y-reporter-htmlmarkdown: The Markdown reporter has been removed. We may introduce it as a separate module at a later datetsv: The TSV reporter has moved outside of Pa11y, please install usingnpm install pa11y-reporter-tsv
Additionally the reporter interface has had an overhaul, and reporters that work for Pa11y 4.0 won't work for 5.0. See the README for more information on the API changes.
Configuration options have had an update between 4.0 and 5.0:
- The
allowedStandardsoption has been removed. This can still be set by manually adding entries topa11y.allowedStandards - The
beforeScriptoption has been removed in favour of using actions (if the existing actions don't meet your needs, please let us know) - The
htmlcsoption has been removed, you can no longer configure the version of HTML CodeSniffer that Pa11y uses. An alternative would be to fork Pa11y for your individual use and replace HTML CodeSniffer, we'll be reviewing how we allow this again in future - The
pageoption has been removed, as this was specific to PhantomJS. You can set the following options to achieve the same results:page.headerscan now be set with a newheadersoptionpage.settings.datacan now be set with a newpostDataoptionpage.settings.operationcan now be set with a newmethodoptionpage.settings.userAgentcan now be set with a newuserAgentoptionpage.viewportcan now be set with a newviewportoption
- The
phantomoption has been removed, as this was specific to PhantomJS - The
verifyPageoption has been removed, as page verification can be achieved with screen-shots or by inspecting thedocumentTitleproperty of the results
- The default viewport dimensions for Pa11y have been changed from
1024x768to1280x1024 - The
wait-for-element-stateaction no longer has a maximum number of retries – it will retry until Pa11y times out - The "multiple-concurrent" example has been removed in favour of a single "multiple" example
The only breaking change in Pa11y 4.0 is that Node.js 0.12 is no longer supported. We'll be using newer ES6 features in upcoming releases which will not work in this older Node.js version.
The Pa11y JavaScript API has been overhauled completely. It would be best to refer to the usage guide in the README as your code will need refactoring.
The phantom.port option no longer has a default. If a port is not specified, then Pa11y will bind to an available port. This allows for easier running of tests in parallel, as PhantomJS instances will no longer conflict with each other.
Node.js 0.10 is no longer officially supported, Pa11y is unlikely to continue to work with this version going forward.
The command-line interface in 2.0 is similar to 1.0, but there are a few key changes.
- The
consolereporter has been renamed tocliand has a different output format - The
csvreporter now includes the message context and selector - The
jsonreporter now outputs an array which matches the new output format. You can use the Pa11y JSON 1.0 reporter to output 1.0-style JSON - Reporters no longer handle the way Pa11y exits, this is controlled through the new
--levelflag - Custom reporters now have a different API, see the README for more information
- The file specified by the
--configflag now expects JSON in a different format. See configuration - The
--htmlcsflag shorthand has been changed to-H - The
--useragentflag has been removed, this is now managed through the config file - The
--viewportflag has been removed, this is now managed through the config file - The
--strictflag has been removed, this is controlled through the new--levelflag - HTML CodeSniffer is now loaded from a local file by default so tests can be run offline
A two-step running process is now used over a single pa11y.sniff() function. This allows a single PhantomJS browser to run multiple tests, reducing memory usage and making Pa11y more useful to derivative tools. See the README for more information.
Results in Pa11y 2.0 are no longer output as an object, instead only the results array is provided. It's up to your code (or reporter) to add totals etc. Also the result format has been changed:
// 1.0 result
{
code: 'WCAG2AA.Principle2.Guideline2_4.2_4_2.H25.2',
message: 'Check that the title element describes the document.',
type: 'notice',
html: '<title>Pa11y - Your automated accessib...</title>'
}
// 2.0 result
{
code: 'WCAG2AA.Principle2.Guideline2_4.2_4_2.H25.2',
context: '<title>Pa11y - Your automated accessib...</title>',
message: 'Check that the title element describes the document.',
selector: 'html > head > title',
type: 'notice',
typeCode: 3
}Configuration options have had a big overhaul between 1.0 and 2.0:
- The
urloption has been removed. See JavaScript Interface for more information - The
configoption has been removed. Cookies are now set as in thepage.headersoption. Ignored rules are now set in a newignoreoption - The
ignoreoption now accepts message types (error, warning, notice) as well as codes - The
useragentoption has been removed, it can now be set in thepage.headersoption - The
portoption has been removed, it can now be set in thephantom.portoption - The
viewportoption has been removed, it can now be set in thepage.viewportoption - The
debugoption has been removed, debugging is now handled by thelog.debugoption which expects a function
Pa11y 2.0 uses Make over Grunt as a build tool. For Windows users, all of the Make targets should be runnable individually by copying commands from the Makefile and running within a terminal.