Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Exclude any checks from output if one passed #466

Merged
merged 1 commit into from
Aug 3, 2017
Merged
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
16 changes: 9 additions & 7 deletions lib/core/utils/aggregateChecks.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,22 @@ axe.utils.aggregateChecks = function (nodeResOriginal) {
});

// Find the result with the highest priority
let priorities = anyAllNone(nodeResult, (c) => c.priority);
nodeResult.priority = Math.max(
priorities.all.reduce((a, b) => Math.max(a,b), 0),
priorities.none.reduce((a, b) => Math.max(a,b), 0),
const priorities = {
all: nodeResult.all.reduce((a, b) => Math.max(a, b.priority), 0),
none: nodeResult.none.reduce((a, b) => Math.max(a,b.priority), 0),
// get the lowest passing of 'any' defaulting
// to 0 by wrapping around 4 to 0 (inapplicable)
priorities.any.reduce((a, b) => Math.min(a,b), 4) % 4
);
any: nodeResult.any.reduce((a, b) => Math.min(a, b.priority), 4) % 4
};

nodeResult.priority = Math.max(priorities.all, priorities.none, priorities.any);

// Of each type, filter out all results not matching the final priority
let impacts = [];
checkTypes.forEach((type) => {
nodeResult[type] = nodeResult[type].filter((check) => {
return check.priority === nodeResult.priority;
return (check.priority === nodeResult.priority &&
check.priority === priorities[type]);
});
nodeResult[type].forEach((check) => impacts.push(check.impact));
});
Expand Down
20 changes: 20 additions & 0 deletions test/core/utils/aggregateChecks.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,26 @@ describe('axe.utils.aggregateChecks', function() {
}));
assert.equal(checkResult.result, FAIL);
});

it('ignores fail checks on any, if at least one passed', function () {
var checkResult = axe.utils.aggregateChecks( createTestCheckResults({
any: [false, undefined, true], // cantTell
none: [true, false] // fail
}));

assert.lengthOf(checkResult.any, 0);
assert.lengthOf(checkResult.none, 1);
});

it('includes cantTell checks from any if there are no fails', function () {
var checkResult = axe.utils.aggregateChecks( createTestCheckResults({
any: [undefined, undefined, false], // cantTell
none: [undefined, false] // cantTell
}));

assert.lengthOf(checkResult.any, 2);
assert.lengthOf(checkResult.none, 1);
});
});

});