diff --git a/lib/core/utils/aggregateRule.js b/lib/core/utils/aggregateNodeResults.js similarity index 52% rename from lib/core/utils/aggregateRule.js rename to lib/core/utils/aggregateNodeResults.js index 4d6f266ba7..650ecc5e93 100644 --- a/lib/core/utils/aggregateRule.js +++ b/lib/core/utils/aggregateNodeResults.js @@ -2,19 +2,19 @@ /** * Calculates the result of a Rule based on its types and the result of its child Checks - * @param {RuleResult} ruleResult The RuleResult to calculate the result of + * @param {Array} nodeResults The array of nodes tested by the Rule */ -axe.utils.aggregateRule = function (subResults) { +axe.utils.aggregateNodeResults = function (nodeResults) { let ruleResult = {}; // For each node, retrieve the result and impact - subResults = subResults.map(function (subResult) { + nodeResults = nodeResults.map(function (nodeResult) { // Known result - if (subResult.any && subResult.all && subResult.none) { - return axe.utils.aggregateChecks(subResult); + if (nodeResult.any && nodeResult.all && nodeResult.none) { + return axe.utils.aggregateChecks(nodeResult); - } else if (Array.isArray(subResult.node)) { - return axe.utils.finalizeRuleResult(subResult); + } else if (Array.isArray(nodeResult.node)) { + return axe.utils.finalizeRuleResult(nodeResult); } else { throw new TypeError('Invalid Result type'); @@ -22,17 +22,22 @@ axe.utils.aggregateRule = function (subResults) { }); // Aggregate the result - let resultList = subResults.map((node) => node.result); - ruleResult.result = axe.utils.aggregate(axe.constants.results, resultList, ruleResult.result); + // If there were no nodes passed in, mark the test as inapplicable + if (nodeResults && nodeResults.length) { + let resultList = nodeResults.map((node) => node.result); + ruleResult.result = axe.utils.aggregate(axe.constants.results, resultList, ruleResult.result); + } else { + ruleResult.result = 'inapplicable'; + } // Create an array for each type axe.constants.resultGroups .forEach((group) => ruleResult[group] = []); // Fill the array with nodes - subResults.forEach(function (subResult) { - var groupName = axe.constants.resultGroupMap[subResult.result]; - ruleResult[groupName].push(subResult); + nodeResults.forEach(function (nodeResult) { + var groupName = axe.constants.resultGroupMap[nodeResult.result]; + ruleResult[groupName].push(nodeResult); }); // Take the highest impact of failed or canttell rules @@ -54,4 +59,4 @@ axe.utils.aggregateRule = function (subResults) { return ruleResult; }; -}()); \ No newline at end of file +}()); diff --git a/lib/core/utils/finalize-result.js b/lib/core/utils/finalize-result.js index b42937aa04..d56fc3543f 100644 --- a/lib/core/utils/finalize-result.js +++ b/lib/core/utils/finalize-result.js @@ -4,7 +4,7 @@ * @return {object} */ axe.utils.finalizeRuleResult = function (ruleResult) { - Object.assign(ruleResult, axe.utils.aggregateRule(ruleResult.nodes)); + Object.assign(ruleResult, axe.utils.aggregateNodeResults(ruleResult.nodes)); delete ruleResult.nodes; return ruleResult; diff --git a/test/core/utils/aggregateRule.js b/test/core/utils/aggregateNodeResults.js similarity index 82% rename from test/core/utils/aggregateRule.js rename to test/core/utils/aggregateNodeResults.js index 4f4f765f82..a5aaef0660 100644 --- a/test/core/utils/aggregateRule.js +++ b/test/core/utils/aggregateNodeResults.js @@ -1,4 +1,4 @@ -describe('axe.utils.aggregateRule', function() { +describe('axe.utils.aggregateNodeResults', function() { 'use strict'; var FAIL = 'failed'; var PASS = 'passed'; @@ -38,20 +38,16 @@ describe('axe.utils.aggregateRule', function() { }); it('should be a function', function() { - assert.isFunction(axe.utils.aggregateRule); + assert.isFunction(axe.utils.aggregateNodeResults); }); it('Should be `inapplicable` when no results are given', function () { - var ruleResult = axe.utils.aggregateRule( createTestResults( - {}, {} - )); - + var ruleResult = axe.utils.aggregateNodeResults([]); assert.equal(ruleResult.result, INAPPLICABLE); - assert.lengthOf(ruleResult.inapplicable, 2); }); it('should assign FAIL to ruleResult over PASS', function() { - var ruleResult = axe.utils.aggregateRule( createTestResults( + var ruleResult = axe.utils.aggregateNodeResults( createTestResults( { all: false }, { all: true }, { all: true } @@ -62,7 +58,7 @@ describe('axe.utils.aggregateRule', function() { }); it('should assign FAIL to ruleResult over CANTTELL', function() { - var ruleResult = axe.utils.aggregateRule( createTestResults( + var ruleResult = axe.utils.aggregateNodeResults( createTestResults( { all: false }, { all: 0 }, { all: true } @@ -74,7 +70,7 @@ describe('axe.utils.aggregateRule', function() { }); it('should assign PASS to ruleResult if there are only passing checks', function() { - var ruleResult = axe.utils.aggregateRule( createTestResults( + var ruleResult = axe.utils.aggregateNodeResults( createTestResults( { all: true }, { all: true }, { all: true } @@ -86,7 +82,7 @@ describe('axe.utils.aggregateRule', function() { }); it('should assign FAIL if there are no passing anys checks', function() { - var ruleResult = axe.utils.aggregateRule( createTestResults( + var ruleResult = axe.utils.aggregateNodeResults( createTestResults( { any: false }, { any: false }, { any: false } @@ -97,7 +93,7 @@ describe('axe.utils.aggregateRule', function() { }); it('should assign CANTTELL over PASS', function() { - var ruleResult = axe.utils.aggregateRule( createTestResults( + var ruleResult = axe.utils.aggregateNodeResults( createTestResults( { all: true }, { all: 0 }, { all: 0 } @@ -108,14 +104,14 @@ describe('axe.utils.aggregateRule', function() { }); it('should provide impact on incomplete', function () { - var ruleResult = axe.utils.aggregateRule( createTestResults({ + var ruleResult = axe.utils.aggregateNodeResults( createTestResults({ none: { result: undefined, impact: 'serious' } })); assert.equal(ruleResult.impact, 'serious'); }); it('should raise the highest "raisedMetadata" on failing checks', function() { - var ruleResult = axe.utils.aggregateRule( createTestResults({ + var ruleResult = axe.utils.aggregateNodeResults( createTestResults({ none: { result: true, impact: 'moderate' }, any: { result: true, impact: 'minor' }, all: [ diff --git a/test/core/utils/finalize-result.js b/test/core/utils/finalize-result.js index 6731ef63a0..c5b0809c3c 100644 --- a/test/core/utils/finalize-result.js +++ b/test/core/utils/finalize-result.js @@ -3,11 +3,11 @@ describe('axe.utils.finalizeRuleResult', function() { var origAggregate; beforeEach(function() { - origAggregate = axe.utils.aggregateRule; + origAggregate = axe.utils.aggregateNodeResults; }); afterEach(function () { - axe.utils.aggregateRule = origAggregate; + axe.utils.aggregateNodeResults = origAggregate; }); it('should be a function', function() { @@ -15,7 +15,7 @@ describe('axe.utils.finalizeRuleResult', function() { }); it('returns the first param object', function () { - axe.utils.aggregateRule = function () {}; + axe.utils.aggregateNodeResults = function () {}; var goingIn = {}; var comingOut = axe.utils.finalizeRuleResult(goingIn); @@ -23,10 +23,10 @@ describe('axe.utils.finalizeRuleResult', function() { assert.equal(goingIn, comingOut); }); - it('passes the nodes property to utils.aggregateRule', function() { + it('passes the nodes property to utils.aggregateNodeResults', function() { var isCalled = false; var nodes = []; - axe.utils.aggregateRule = function (n) { + axe.utils.aggregateNodeResults = function (n) { assert.equal(n, nodes); isCalled = true; }; @@ -34,8 +34,8 @@ describe('axe.utils.finalizeRuleResult', function() { assert.ok(isCalled); }); - it('adds properties returned from utils.aggregateRule to the return value', function() { - axe.utils.aggregateRule = function () { + it('adds properties returned from utils.aggregateNodeResults to the return value', function() { + axe.utils.aggregateNodeResults = function () { return { vulgaris:'magistralis' };