npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

nightwatch-axe-core

v2.0.1

Published

Nightwatch.js commands for running aXe-core.

Downloads

302

Readme

Nightwatch aXe-core

Nightwatch.js commands for running aXe-core.

Installation

Install using yarn or npm

npm install nightwatch-axe-core --save-dev

Add these commands to the custom_commands_path in your Nightwatch.js configuration.

{
  custom_commands_path : [
    "./node_modules/nightwatch-axe-core/commands"
  ]
}

Configuration & Usage

The axe() command takes the following two parameters:

Parameter Name | Parameter Type | Description ------------- | ---------------- | ----------- context | string or object | css selector or include/exclude object options | object | set of axe options

These can be defined globally and/or per call to the axe() command.

In addition to the standard aXe options:

  • options.timeout configures Nightwatch's timeoutsAsyncScript() amount, default value is 1000 milliseconds.

aXe can require a fair amount of time to run, so increasing the timeout option is often required.

Injecting aXe-core

Since Nightwatch 2.3.6, axe is included by default, but still requires calling both axeInject() and axeRun(). This command handles both.

Global configuration file

Create an axe.conf.js file in your project root as an CommonJS module that exports a default object with both the context and options parameters:

// axe.conf.js

module.exports = {
  context: {
    include: [['html']],
    exclude: [['.advertising']],
  },
  options: {
    runOnly: {
      type: 'tag',
      values: ['wcag2a', 'wcag2aa'],
    },
    timeout: 2000,
  }
};

Then your test simply needs to call the axe() command.

// nightwatch-test.js

export default {
  '@tags': ['accessibility'],

  'Thing passes aXe-core checks': function (browser) {
    browser
      .url(`${browser.launch_url}/page-to-test`)
      .waitForElementPresent('.thing-to-test')
      .axe()
      .end()
  }
}

Per test configuration

When calling axe() you can can pass in the context and options values as arguments. context will override any globally defined contexts, whilst options will be merged with any globally defined options. This way you can have edge case tests that inherit global config but can easily be change one or two things.

axe(context, options)

For example;

// nightwatch-test.js

export default {
  '@tags': ['accessibility'],

  'Thing passes aXe-core checks': function (browser) {
    browser
      .url(`${browser.launch_url}/page-to-test`)
      .waitForElementPresent('.thing-to-test')
      .axe('.thing-to-test', {
        runOnly: {
          type: 'tag',
          values: ['wcag2a']
        },
        rules: {
          'color-contrast': { enabled: true },
          'valid-lang': { enabled: false }
        },
      })
      .end()
  }
}

Debugging

When debugging a failure it can be useful to enable all of the output options, and set a large timeout;

options: {
  timeout: 60000,
  verbose: true,
  selectors: true,
  absolutePaths: true,
  ancestry: true,
  elementRef: true,
}

This will give you as much information as possible into what caused the failure.

Another helpful option is setting resultTypes: ['violations'], as described in the axe-core docs which can improve performance and reduce timeout failures.