Skip to content
This repository has been archived by the owner on Dec 7, 2022. It is now read-only.

adds selectors to the Audit results #305

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/js/Audit.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ axs.Audit.getRulesCannotRun = function(opt_configuration) {
* {
* result, // @type {axs.constants.AuditResult}
* elements, // @type {Array.<Element>}
* selectors, // @type {Array.<String>}
* rule // @type {axs.AuditRule} - data only (name, severity, code)
* }
*/
Expand Down
2 changes: 2 additions & 0 deletions src/js/AuditRule.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,12 +217,14 @@ axs.AuditRule.Result.prototype.update = function(auditResult, element) {
var result = this;
if (auditResult === axs.constants.AuditResult.FAIL) {
var failingElements = result.elements || (result.elements = []);
var failingSelectors = result.selectors || (result.selectors = []);
result.result = auditResult; // If FAIL then we change the result to FAIL no matter what it is
if (this.maxResults && result.elements.length >= this.maxResults) {
result.resultsTruncated = true;
} else if (element) {
// element should always be defined here but testing first avoids pushing undefined onto the array
failingElements.push(element);
failingSelectors.push(axs.utils.getQuerySelectorText(element))
}
} else if (auditResult === axs.constants.AuditResult.PASS) {
if (!result.elements)
Expand Down
26 changes: 26 additions & 0 deletions test/js/audit-configuration-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,32 @@ test('Configure audit rules to ignore', function() {

});

test("Check that selectors are returned in the results", function() {
var fixture = document.getElementById('qunit-fixture');
var div = document.createElement('div');
div.setAttribute('role', 'not-an-aria-role');
fixture.appendChild(div);
var div2 = document.createElement('div');
div2.setAttribute('role', 'also-not-an-aria-role');
fixture.appendChild(div2);
var auditConfig = new axs.AuditConfiguration();
auditConfig.auditRulesToRun = ['badAriaRole'];
auditConfig.scope = fixture; // limit scope to just fixture element
auditConfig.walkDom = false;

var results = axs.Audit.run(auditConfig);
equal(results.length, 1);
equal(results[0].selectors.length, 2);
equal(results[0].selectors[0], '#qunit-fixture > DIV');
equal(results[0].selectors[1], '#qunit-fixture > DIV:nth-of-type(2)');

auditConfig.maxResults = 1;
results = axs.Audit.run(auditConfig);
equal(results.length, 1);
equal(results[0].selectors.length, 1);
equal(results[0].selectors[0], '#qunit-fixture > DIV');
});

var __warnings = [];
console.warn = function(msg) {
__warnings.push(msg);
Expand Down