cristinafsanz
8/9/2019 - 8:06 AM

Automatic testing accessibility

By @_angelmm:

a11y npm library

Manual testing

Other resources

/*
Accessibility test example

- actions are the steps to execute before running the test
- hideElements: needed because the pa11y check hidden prefetch images otherwise
- log to display what's happening to the console
*/
'use strict'

const pa11y = require('pa11y')

let URL = '';

// Get url to test performance
(() => {
  const argv = process.argv.slice(2)
  URL = argv[0]
})()

function errorIfIssues(results) {
  if (results && results.issues.length > 0) {
    console.error(results)
    process.exit(1)
  }
}

pa11y(URL, {
  actions: [
    // First page
    'click element .button-instructions',
    // First screen game
    'wait for element .button-game to be visible'
  ],
  hideElements: "[class^='prefetch-image-wrapper']",
  log: {
    debug: (message) => {
      if (!message.startsWith('Browser Console:')) {
        console.log(message)
      }
    },
    error: console.error,
    info: console.log
  }
}).then((results) => {
  errorIfIssues(results)
}).catch((error) => {
  throw new Error(error)
})