From 88d039f852bb25a6471fe8a6cd7833812f8bb1e8 Mon Sep 17 00:00:00 2001 From: Wilco Fiers Date: Tue, 17 Oct 2017 16:17:38 +0200 Subject: [PATCH] fix: Remove axe.a11yCheck() BREAKING CHANGE --- CONTRIBUTING.md | 10 ++- axe.d.ts | 10 --- doc/API.md | 9 --- lib/core/public/a11y-check.js | 39 ---------- test/core/public/a11y-check.js | 76 ------------------- test/core/public/run-rules.js | 8 +- ...-exclude.html => run-include-exclude.html} | 2 +- ...lude-exclude.js => run-include-exclude.js} | 8 +- ...{a11ycheck-object.html => run-object.html} | 2 +- .../{a11ycheck-object.js => run-object.js} | 5 +- .../options-parameter/options-parameter.js | 18 ++--- typings/axe-core/axe-core-tests.ts | 39 +++++----- 12 files changed, 47 insertions(+), 179 deletions(-) delete mode 100644 lib/core/public/a11y-check.js delete mode 100644 test/core/public/a11y-check.js rename test/integration/full/jquery/{a11ycheck-include-exclude.html => run-include-exclude.html} (93%) rename test/integration/full/jquery/{a11ycheck-include-exclude.js => run-include-exclude.js} (72%) rename test/integration/full/jquery/{a11ycheck-object.html => run-object.html} (94%) rename test/integration/full/jquery/{a11ycheck-object.js => run-object.js} (69%) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 82ba8e83a2..74cca3cd6b 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -136,10 +136,12 @@ Installing aXe to run accessibility tests in your TypeScript project should be a import * as axe from 'axe-core'; describe('Module', () => { - it('should have no accessibility violations', () => { - axe.a11yCheck(compiledFixture, {}, (results) => { - expect(results.violations.length).toBe(0); - }); + it('should have no accessibility violations', (done) => { + axe.run(compiledFixture) + .then((results) => { + expect(results.violations.length).toBe(0); + done() + }, done); }); }); ``` diff --git a/axe.d.ts b/axe.d.ts index 789f35d1a8..70e516db2f 100644 --- a/axe.d.ts +++ b/axe.d.ts @@ -139,16 +139,6 @@ declare module axe { function run(context: ElementContext, options: RunOptions): Promise function run(context: ElementContext, options: RunOptions, callback: RunCallback): void - /** - * Starts analysis on the current document and its subframes - * - * @param {Object} context The `Context` specification object @see Context - * @param {Array} options Options passed into rules or checks, temporarily modifyint them. - * @param {Function} callback The function to invoke when analysis is complete. - * @returns {Object} results The aXe results object - */ - function a11yCheck(context: ElementContext, options: {runOnly?: RunOnly, rules?: Object, iframes?: Boolean, elementRef?: Boolean, selectors?: Boolean}, callback: (results:AxeResults) => void): AxeResults - /** * Method for configuring the data format used by aXe. Helpful for adding new * rules, which must be registered with the library to execute. diff --git a/doc/API.md b/doc/API.md index 3f514dd748..b16a39fad2 100644 --- a/doc/API.md +++ b/doc/API.md @@ -20,7 +20,6 @@ 1. [Results Object](#results-object) 1. [API Name: axe.registerPlugin](#api-name-axeregisterplugin) 1. [API Name: axe.cleanup](#api-name-axecleanup) - 1. [API Name: axe.a11yCheck](#api-name-axea11ycheck) 1. [Virtual DOM Utilities](#virtual-dom-utilities) 1. [API Name: axe.utils.querySelectorAll](#api-name-axeutilsqueryselectorall) 1. [Common Functions](#common-functions) @@ -619,14 +618,6 @@ Register a plugin with the aXe plugin system. See [implementing a plugin](plugin Call the plugin system's cleanup function. See [implementing a plugin](plugins.md). -### API Name: axe.a11yCheck - -In axe-core v1 the main method for axe was `axe.a11yCheck()`. This method was replaced with `axe.run()` in order to better deal with errors. The method `axe.a11yCheck()` differs from `axe.run()` in the following ways: - -- .a11yCheck does not pass the error object to the callback, rather it returns the result as the first parameter and logs errors to the console. -- .a11yCheck requires a context object, and so will not fall back to the document root. -- .a11yCheck does not return a Promise. - ### Virtual DOM Utilities Note: If you’re writing rules or checks, you’ll have both the `node` and `virtualNode` passed in. diff --git a/lib/core/public/a11y-check.js b/lib/core/public/a11y-check.js deleted file mode 100644 index d73d4f1976..0000000000 --- a/lib/core/public/a11y-check.js +++ /dev/null @@ -1,39 +0,0 @@ -/** - * Starts analysis on the current document and its subframes - * - * @param {Object} context The `Context` specification object @see Context - * @param {Array} options Optional RuleOptions - * @param {Function} callback The function to invoke when analysis is complete; receives an array of `RuleResult`s - */ -axe.a11yCheck = function (context, options, callback) { - 'use strict'; - if (typeof options === 'function') { - callback = options; - options = {}; - } - - if (!options || typeof options !== 'object') { - options = {}; - } - - var audit = axe._audit; - if (!audit) { - throw new Error('No audit configured'); - } - options.reporter = options.reporter || audit.reporter || 'v2'; - - if (options.performanceTimer) { - axe.utils.performanceTimer.start(); - } - - var reporter = axe.getReporter(options.reporter); - axe._runRules(context, options, function (results) { - var res = reporter(results, options, callback); - if (res !== undefined) { - if (options.performanceTimer) { - axe.utils.performanceTimer.end(); - } - callback(res); - } - }, axe.log); -}; diff --git a/test/core/public/a11y-check.js b/test/core/public/a11y-check.js deleted file mode 100644 index 9e8a97f95b..0000000000 --- a/test/core/public/a11y-check.js +++ /dev/null @@ -1,76 +0,0 @@ -describe('axe.a11yCheck', function () { - 'use strict'; - - describe('reporter', function () { - var origReporters; - var noop = function () {}; - - beforeEach(function () { - axe._load({}); - origReporters = window.reporters; - }); - - afterEach(function () { - window.reporters = origReporters; - }); - - it('should throw if no audit is configured', function () { - axe._audit = null; - - assert.throws(function () { - axe.a11yCheck(document, {}); - }, Error, /^No audit configured/); - }); - - it('should allow for option-less invocation', function (done) { - axe.a11yCheck(document, function (result) { - assert.isObject(result); - done(); - }); - }); - - it('should work with performance logging enabled', function (done) { - axe.a11yCheck(document, {performanceTimer: true}, function (result) { - assert.isObject(result); - done(); - }); - }); - - it('sets v2 as the default reporter if audit.reporter is null', function (done) { - var origRunRules = axe._runRules; - - axe._runRules = function (ctxt, opt) { - assert.equal(opt.reporter, 'v2'); - axe._runRules = origRunRules; - done(); - }; - - axe._audit.reporter = null; - axe.a11yCheck(document, noop); - }); - - it('uses the audit.reporter if no reporter is set in options', function (done) { - var origRunRules = axe._runRules; - - axe._runRules = function (ctxt, opt) { - assert.equal(opt.reporter, 'raw'); - axe._runRules = origRunRules; - done(); - }; - axe._audit.reporter = 'raw'; - axe.a11yCheck(document, noop); - }); - - it('does not override if another reporter is set', function (done) { - var origRunRules = axe._runRules; - axe._runRules = function (ctxt, opt) { - assert.equal(opt.reporter, 'raw'); - axe._runRules = origRunRules; - done(); - }; - axe._audit.reporter = null; - axe.a11yCheck(document, {reporter: 'raw'}, noop); - }); - - }); -}); \ No newline at end of file diff --git a/test/core/public/run-rules.js b/test/core/public/run-rules.js index bf376e3bb9..118c27c806 100644 --- a/test/core/public/run-rules.js +++ b/test/core/public/run-rules.js @@ -491,7 +491,8 @@ describe('runRules', function () { fixture.innerHTML = '
'; - axe.a11yCheck('#fixture', function (results) { + axe.run('#fixture', function (err, results) { + assert.isNull(err); assert.lengthOf(results.incomplete, 2); assert.equal(results.incomplete[0].id, 'incomplete-1'); assert.equal(results.incomplete[1].id, 'incomplete-2'); @@ -527,7 +528,8 @@ describe('runRules', function () { }); iframeReady('../mock/frames/rule-error.html', fixture, 'context-test', function () { - axe.a11yCheck('#fixture', function (results) { + axe.run('#fixture', function (err, results) { + assert.isNull(err); assert.lengthOf(results.incomplete, 2); assert.equal(results.incomplete[0].id, 'incomplete-1'); assert.equal(results.incomplete[1].id, 'incomplete-2'); @@ -535,7 +537,7 @@ describe('runRules', function () { assert.include(results.incomplete[1].description, 'An error occured while running this rule'); done(); - }, isNotCalled); + }); }); }); diff --git a/test/integration/full/jquery/a11ycheck-include-exclude.html b/test/integration/full/jquery/run-include-exclude.html similarity index 93% rename from test/integration/full/jquery/a11ycheck-include-exclude.html rename to test/integration/full/jquery/run-include-exclude.html index 114c8d2983..e14d82569f 100644 --- a/test/integration/full/jquery/a11ycheck-include-exclude.html +++ b/test/integration/full/jquery/run-include-exclude.html @@ -30,7 +30,7 @@
- + diff --git a/test/integration/full/jquery/a11ycheck-include-exclude.js b/test/integration/full/jquery/run-include-exclude.js similarity index 72% rename from test/integration/full/jquery/a11ycheck-include-exclude.js rename to test/integration/full/jquery/run-include-exclude.js index d50fb9ac48..423ae9d4c7 100644 --- a/test/integration/full/jquery/a11ycheck-include-exclude.js +++ b/test/integration/full/jquery/run-include-exclude.js @@ -1,6 +1,6 @@ /*global $ */ -describe('jQuery object with a11yCheck', function () { +describe('jQuery object with axe.run', function () { 'use strict'; var config = { runOnly: { type: 'rule', values: ['aria-roles'] } }; @@ -8,7 +8,8 @@ describe('jQuery object with a11yCheck', function () { describe('include', function() { it('should find violations', function (done) { var target = $('#target')[0]; - axe.a11yCheck({ include: [target] }, config, function (results) { + axe.run({ include: [target] }, config, function (err, results) { + assert.isNull(err); assert.lengthOf(results.violations, 1, 'violations'); assert.lengthOf(results.passes, 0, 'passes'); done(); @@ -19,7 +20,8 @@ describe('jQuery object with a11yCheck', function () { describe('exclude', function() { it('should find no violations', function (done) { var target = $('#target')[0]; - axe.a11yCheck({ exclude: [target] }, config, function (results) { + axe.run({ exclude: [target] }, config, function (err, results) { + assert.isNull(err); assert.lengthOf(results.violations, 0, 'violations'); assert.lengthOf(results.passes, 0, 'passes'); done(); diff --git a/test/integration/full/jquery/a11ycheck-object.html b/test/integration/full/jquery/run-object.html similarity index 94% rename from test/integration/full/jquery/a11ycheck-object.html rename to test/integration/full/jquery/run-object.html index b4b3a85074..8b4f68d579 100644 --- a/test/integration/full/jquery/a11ycheck-object.html +++ b/test/integration/full/jquery/run-object.html @@ -30,7 +30,7 @@
- + diff --git a/test/integration/full/jquery/a11ycheck-object.js b/test/integration/full/jquery/run-object.js similarity index 69% rename from test/integration/full/jquery/a11ycheck-object.js rename to test/integration/full/jquery/run-object.js index 9989f4d4aa..15dc8d21b9 100644 --- a/test/integration/full/jquery/a11ycheck-object.js +++ b/test/integration/full/jquery/run-object.js @@ -1,11 +1,12 @@ /*global $ */ -describe('jQuery object as a11yCheck context', function () { +describe('jQuery object as axe.run context', function () { 'use strict'; var config = { runOnly: { type: 'rule', values: ['aria-roles'] } }; it('should find no violations', function (done) { var fixture = $('#fixture'); - axe.a11yCheck(fixture, config, function (results) { + axe.run(fixture, config, function (err, results) { + assert.isNull(err); assert.lengthOf(results.violations, 0, 'violations'); assert.lengthOf(results.passes, 1, 'passes'); done(); diff --git a/test/integration/full/options-parameter/options-parameter.js b/test/integration/full/options-parameter/options-parameter.js index 0e9a7eb632..eb08b7229c 100644 --- a/test/integration/full/options-parameter/options-parameter.js +++ b/test/integration/full/options-parameter/options-parameter.js @@ -19,7 +19,7 @@ describe('Options parameter', function() { describe('iframes', function() { it('should include iframes if `iframes` is true', function(done) { var config = { iframes: true }; - axe.a11yCheck(document, config, function(results) { + axe.run(document, config, function(err, results) { try { assert.lengthOf(results.violations, 0, 'violations'); assert.lengthOf(results.passes, 1, 'passes'); @@ -39,7 +39,7 @@ describe('Options parameter', function() { it('should exclude iframes if `iframes` is false', function(done) { var config = { iframes: false }; - axe.a11yCheck(document, config, function(results) { + axe.run(document, config, function(err, results) { try { assert.lengthOf(results.violations, 0, 'violations'); assert.lengthOf(results.passes, 1, 'passes'); @@ -59,7 +59,7 @@ describe('Options parameter', function() { it('should include iframes by default', function(done) { var config = {}; - axe.a11yCheck(document, config, function(results) { + axe.run(document, config, function(err, results) { try { assert.lengthOf(results.violations, 0, 'violations'); assert.lengthOf(results.passes, 1, 'passes'); @@ -81,7 +81,7 @@ describe('Options parameter', function() { describe('elementRef', function() { it('should not return an elementRef by default', function(done) { var config = {}; - axe.a11yCheck(document, config, function(results) { + axe.run(document, config, function(err, results) { try { assert.lengthOf(results.violations, 0, 'violations'); assert.lengthOf(results.passes, 1, 'passes'); @@ -98,7 +98,7 @@ describe('Options parameter', function() { it('should not return an elementRef if `elementRef` is false', function(done) { var config = { elementRef: false }; - axe.a11yCheck(document, config, function(results) { + axe.run(document, config, function(err, results) { try { assert.lengthOf(results.violations, 0, 'violations'); assert.lengthOf(results.passes, 1, 'passes'); @@ -115,7 +115,7 @@ describe('Options parameter', function() { it('should return element refs for the top frame only if `elementRef` is true', function(done) { var config = { elementRef: true }; - axe.a11yCheck(document, config, function(results) { + axe.run(document, config, function(err, results) { try { assert.lengthOf(results.violations, 0, 'violations'); assert.lengthOf(results.passes, 1, 'passes'); @@ -137,7 +137,7 @@ describe('Options parameter', function() { describe('no selectors', function() { it('should return a selector by default', function(done) { var config = {}; - axe.a11yCheck(document, config, function(results) { + axe.run(document, config, function(err, results) { try { assert.lengthOf(results.violations, 0, 'violations'); assert.lengthOf(results.passes, 1, 'passes'); @@ -154,7 +154,7 @@ describe('Options parameter', function() { it('should return a selector if `selectors` is true', function(done) { var config = { selectors: true }; - axe.a11yCheck(document, config, function(results) { + axe.run(document, config, function(err, results) { try { assert.lengthOf(results.violations, 0, 'violations'); assert.lengthOf(results.passes, 1, 'passes'); @@ -171,7 +171,7 @@ describe('Options parameter', function() { it('should return no selector in top frame if `selectors` is false', function(done) { var config = { selectors: false }; - axe.a11yCheck(document, config, function(results) { + axe.run(document, config, function(err, results) { try { assert.lengthOf(results.violations, 0, 'violations'); assert.lengthOf(results.passes, 1, 'passes'); diff --git a/typings/axe-core/axe-core-tests.ts b/typings/axe-core/axe-core-tests.ts index e16c87f046..a636177e89 100644 --- a/typings/axe-core/axe-core-tests.ts +++ b/typings/axe-core/axe-core-tests.ts @@ -17,26 +17,21 @@ axe.run().then(function(done:any) { done(); }); // additional configuration options -axe.run(context, {iframes: false, selectors: false, elementRef: false}, (error: Error, results: axe.AxeResults) => { - console.log(results.passes.length); -}); - -// axe.a11yCheck config -axe.a11yCheck(context, {}, (results: axe.AxeResults) => { - // axe's results object - console.log(results.passes.length) - console.log(results.violations.length) +axe.run(context, {iframes: false, selectors: false, elementRef: false}, + (error: Error, results: axe.AxeResults) => { + console.log(error || results.passes.length); }); -// axe.a11yCheck include/exclude -axe.a11yCheck({include: [['#id1'], ['#id2']]}, {}, (results: axe.AxeResults) => { - console.log(results) +// axe.run include/exclude +axe.run({include: [['#id1'], ['#id2']]}, {}, (error: Error, results: axe.AxeResults) => { + console.log(error || results) }) -axe.a11yCheck({exclude: [$fixture[0]]}, {}, (results: axe.AxeResults) => { - console.log(results) +axe.run({exclude: [$fixture[0]]}, {}, (error: Error, results: axe.AxeResults) => { + console.log(error || results) }) // additional configuration options -axe.a11yCheck(context, {iframes: false, selectors: false, elementRef: false}, (results: axe.AxeResults) => { - console.log(results.passes.length); +axe.run(context, {iframes: false, selectors: false, elementRef: false}, + (error: Error, results: axe.AxeResults) => { + console.log(error || results.passes.length); }); var tagConfigRunOnly: axe.RunOnly = { type: 'tag', @@ -45,8 +40,8 @@ var tagConfigRunOnly: axe.RunOnly = { var tagConfig = { runOnly: tagConfigRunOnly } -axe.a11yCheck(context, tagConfig, (results: axe.AxeResults) => { - console.log(results) +axe.run(context, tagConfig, (error: Error, results: axe.AxeResults) => { + console.log(error || results) }) var includeExcludeTagsRunOnly: axe.RunOnly = { type: 'tags', @@ -58,8 +53,8 @@ var includeExcludeTagsRunOnly: axe.RunOnly = { var includeExcludeTagsConfig = { runOnly: includeExcludeTagsRunOnly } -axe.a11yCheck(context, includeExcludeTagsConfig, (results: axe.AxeResults) => { - console.log(results) +axe.run(context, includeExcludeTagsConfig, (error: Error, results: axe.AxeResults) => { + console.log(error || results) }) var someRulesConfig = { rules: { @@ -67,8 +62,8 @@ var someRulesConfig = { "heading-order": {enabled: 'true'} } } -axe.a11yCheck(context, someRulesConfig, (results: axe.AxeResults) => { - console.log(results) +axe.run(context, someRulesConfig, (error: Error, results: axe.AxeResults) => { + console.log(error || results) }) // axe.configure