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

a11y-auditor

v0.0.14

Published

This a11y auditor aims at implementing unit tests for accessibility via chai-a11y, by automating the rules as defined in W3C Accessibility Checklist

Downloads

48

Readme

a11y-auditor

Build Status Dependency Status devDependency Status peerDependency Status

npm DUB Maintenance Coverage Status Twitter CodeClimate

NPM

Table of Contents

What is this? What does it do ?

This a11y project is an implementation of accessibility rules as defined in W3C Accessibility Checklist

Accessibility testing happens on products after they are deployed onto staging and relies on the QA folks. This project along with chai-a11y helps to include accessibility testing as part of the unit tests phase itself. chai-a11y provides a BDD style to.be.accessible() interface for asserting a11y audits. This audit, helps in cutting down lead time by eliminating dependency over the QA deployments. Accessibility issues can now be spotted in the development phase itself.

Recursively conducts accessibility audits on HTML partials / snippets / mocked HTML response (inclusive of child nodes)

Status

Status : Dev (in progress) & Pull requests are welcome!

Usage Tip :


Its recommended to use a11y-auditor to run accessibility audit for A, AA, AAA compliance on your web pages as part of your Dev testing (unit tests) itself via the chai-a11y plugin.

chai-a11y is a chai plugin available as an npm module which consumes a11y-auditor, provides a to.be.accessible() interface for asserting a11y audits, and helps run tests, conduct audits on a headless phantomJS instance (supporting all flavors of javascript :- AMD, common JS style and also via script tag loading.)

For Node JS usage :


require the module as require('a11y-auditor') and add it to the dependencies. This will return a [function ()]. Use it in your module. But its recommended to use a11y-auditor with the chai-a11y plugin that provides BDD style to.be.accessible() interface via chai js and can be integrated with mocha tests and run on development machines and CI.

var auditRunner = require('a11y-auditor');

var result = auditRunner(htmlSelector, rulesConfig, auditConfig);

For Browser usage (include <script...> and run without AMD):


Use the distribution file at dist/browser/main.js. Implement it as :

window.onload = function(){
		auditRunner(htmlSelector, rulesConfig, auditConfig);
}

But its recommended to use a11y-auditor with the chai-a11y plugin that provides BDD style to.be.accessible() interface via chai and can be integrated with mocha tests and run on development machines and CI.

For JAVA projects :


It is possible to run a grunt workflow via MAVEN builds using the Front end maven plugin and execute test cases built on mocha and chai. The above setup for a11y-auditor & chai-a11y ( mentioned above for Node JS ) holds good here as well, as the Front End Maven plugin downloads and installs a node executable. You will have to integrate your project with the Front End Maven Plugin before attempting to use a11y-auditor for JAVA based projects built on JSP / JSF / Struts.

Configuring to run on a phantomJS CLI :


The a11y-auditor has a command line runner to conduct the audit on static HTML files and on any URL's directly. To use the runner, install phantomjs then run the following command from the project root directory.

$ phantomjs path/to/phantomRunner.js <path-to-StaticFile-or-URL> <path-To-A11yAuditor-Distribution-File> <path-to-outPutFile>

Method definition of method exported by the Module :


The method takes in 3 parameters:

var auditRunner = require('a11y-auditor');

var result = auditRunner(htmlSelector, rulesConfig, auditConfig);
  1. htmlSelector or DOM object - A valid HTML selector or a DOM object (containing child nodes is also cool) (eg. 'button')
  2. rulesConfig - A config obj containing rules to be ignored for some elements matched by valid HTML selectors as shown below
  3. auditConfig - A config obj for the a11y-auditor that governs compliance, global rules execution etc.,

auditConfig takes in 2 properties / keys :

  • 'executeGlobalRules': A Boolean to indicate whether global rules that audit the whole document need to be ignored.
  • 'compliance' : Takes one of the 3 strings : 'A', 'AA', 'AAA'.

To ignore a few rules :


As an example :

function(“img”, {
	‘img’ : [‘AX_01’, 'AX_04'],
	‘#sampleId1’ : [‘AX_22’, 'AX_33'],
	‘title’ : [‘*’] //* will skip all rules for the selector
},{
	executeGlobalRules : true,
	compliance : 'AA'
	});

Note : If there is no HTML partial object or selector passed, it will perform the audit for the whole document

To author new rules :


  1. Create a new numbered rule named file AX_XX.js (eg: AX_01.js) under lib/rulesImpl
  2. Follow the pattern in which the files are authored under lib/rulesImpl/AX_XXX.js
  3. The exported object via module.exports will contain the following:
module.exports = {
	name: "shortNameMentioningWhatThisRuleDoes",
	description: "Detailed description of the rule",
	ruleID: "AX_XXX",
	tagName: ['comma separated array of tagNames'], // the rule will execute for the tags mentioned here
	handler: function(){/* Your implementation here */},
	isGlobal: Boolean //to indicate if this rule checks on document level checks,
	compliance : 'AA'
};

tagName can take :

  1. ['comma separated array of tagNames'] - if its not a Global Rule.
  2. [] - if its a Global Rule as its not tag specific and will execute just once for the document.
  3. ['*'] - if its to execute for all tags

compliance can take : A, AA, AAA

isGlobal can take : true / false

File Structure :


| Directory | Description | | :--- | :--- | | dist/ | The distribution file to use in browser environments | | lib/auditRunner | The engine that recursively iterates & performs the audit & exposes an interface to consume | | lib/constants | Constants / Enums | | lib/axs | Utils for certain rules | | lib/enums | List of enums | | lib/mapper | Mapper functions that map rules to handler and tagName | | lib/rulesImpl | Implementation functions that contain the rule implementation | | lib/rulesProcessor | Code to pick up rules and add it to the auditRulesCreator | | lib/utils | Code containing utils for enum creation, DOM object checks and dependency injections | | test/ | The test cases written for this project |

Implementation Tests :


Individual tests for each of the rules implemented have been placed under tests. The test cases are built with the help of Mocha and Chai for BDD style assertions. The tests are integrated into the workflow via Grunt.

Rule Understanding:


The a11y-auditor aims to automate rules defined in the W3C Accessibility Checklist, which contains numerous rules. In order to make creation of rules easier, each rule is implemented in a modular fashion in a separate file. To understand what each rule does, look at the a11y.properties.json file.

Build Tasks


clean task

This task will clean up the residue directories .test, .coverage, .docs.

lint task

This task runs jshint, jsonlint, jscs on the source files.

test task

Runs the above lint task and mocha test cases over a sampled DOM via jsdom

coverage task

Runs mocha test cases and use istanbul to instrument code & collects the coverage info to build coverage reports & submit .lcov to coveralls.io for code coverage

build task

Generates the distribution file built via Browserify & also the Documentation and publishes it to the GH pages.

document task

Generates Code Documentation using docco-plus

Dependencies :


jQuery (v 2.2.0), lodash (4.3.0), glob (6.0.4)

Dev Dependencies :


Grunt, grunt-mocha-test, Chai, grunt-browserify, jsdom, grunt-istanbul, grunt-contrib-watch, grunt-jsonlint, grunt-jscs, grunt-contrib-jshint, docco-plus, proxyquire, sinon-chai, grunt-contrib-copy, grunt-contrib-clean, require-globify

Ideation & Contributors :


@pranavjha

License


The MIT License (MIT)