diff --git a/doc/API.md b/doc/API.md index 16aae332a9..ba0a207f6a 100644 --- a/doc/API.md +++ b/doc/API.md @@ -440,13 +440,14 @@ Additionally, there are a number or properties that allow configuration of diffe 6. Only process certain types of results - The `resultTypes` option can be used to limit the result types that aXe will process, aggregate, and send to the reporter. This can be useful for improving performance on very large or complicated pages when you are only interested in certain types of results. + The `resultTypes` option can be used to limit the result types that aXe will process, aggregate, and send to the reporter. This can be useful for improving performance on very large or complicated pages when you are only interested in certain types of results. The option will return 1 result of each type if that rule has at least one of that type of result instead of returning all of that type of result. The caller can use this information to inform the user of the existence of that type of result if appropriate. + ```javascript { resultTypes: ['violations', 'incomplete', 'inapplicable'] } ``` - This example will only process the specified result types: "violations", "incomplete", and "inapplicable". Notably, it will not process "passes". On a series of extremely large pages, this could improve performance considerably. + This example will only process the specified result types: "violations", "incomplete", and "inapplicable". Notably, it will only process the first pass for each rule that has a pass. On a series of extremely large pages, this could improve performance considerably. ##### Callback Parameter diff --git a/lib/core/reporters/helpers/process-aggregate.js b/lib/core/reporters/helpers/process-aggregate.js index e124df749d..1f534fd3d3 100644 --- a/lib/core/reporters/helpers/process-aggregate.js +++ b/lib/core/reporters/helpers/process-aggregate.js @@ -59,8 +59,12 @@ helpers.processAggregate = function (results, options) { resultKeys.forEach(function (key) { if (options.resultTypes && !options.resultTypes.includes(key)) { - delete resultObject[key]; - return; + // If the user asks us to, truncate certain finding types to maximum one finding + (resultObject[key] || []).forEach(function (ruleResult) { + if (Array.isArray(ruleResult.nodes) && ruleResult.nodes.length > 0) { + ruleResult.nodes = [ruleResult.nodes[0]]; + } + }); } resultObject[key] = (resultObject[key] || []).map(function (ruleResult) { ruleResult = Object.assign({}, ruleResult); diff --git a/test/core/reporters/helpers/process-aggregate.js b/test/core/reporters/helpers/process-aggregate.js index 0a62c066a5..e8dcf5bab9 100644 --- a/test/core/reporters/helpers/process-aggregate.js +++ b/test/core/reporters/helpers/process-aggregate.js @@ -25,6 +25,25 @@ describe('helpers.processAggregate', function () { }], all: [], none: [] + }, { + result: 'passed', + node: { + element: document.createElement('div'), + selector: 'main > .thing', + source: '
Thing
', + xpath: '/main/div[@class="thing"]' + }, + any: [{ + id: 'passed-rule', + relatedNodes: [{ + element: document.createElement('div'), + selector: 'footer > .thing', + source: '
Thing
', + xpath: '/footer/div[@class="thing"]', + }] + }], + all: [], + none: [] }], inapplicable: [], incomplete: [], @@ -51,6 +70,26 @@ describe('helpers.processAggregate', function () { }], all: [], none: [] + }, { + result: 'failed', + node: { + selector: '#dopell', + source: '', + xpath: '/header/input[@id="dopell"]', + fromFrame: true + }, + any: [{ + id: 'failed-rule', + relatedNodes: [{ + element: document.createElement('input'), + selector: '#dopell', + source: '', + xpath: '/header/input[@id="dopell"]', + fromFrame: true + }] + }], + all: [], + none: [] }], inapplicable: [], passes: [], @@ -96,12 +135,17 @@ describe('helpers.processAggregate', function () { describe('`resultTypes` option', function () { - it('should remove non-specified result types from the `resultObject`', function () { - var resultObject = helpers.processAggregate(results, { resultTypes: ['passes', 'violations'] }); + it('should reduce the unwanted result types to 1 in the `resultObject`', function () { + var resultObject = helpers.processAggregate(results, { resultTypes: ['violations'] }); assert.isDefined(resultObject.passes); + assert.equal(resultObject.passes[0].nodes.length, 1); assert.isDefined(resultObject.violations); - assert.isUndefined(resultObject.incomplete); - assert.isUndefined(resultObject.inapplicable); + assert.equal(resultObject.violations[0].nodes.length, 2); + resultObject = helpers.processAggregate(results, { resultTypes: ['passes'] }); + assert.equal(resultObject.passes[0].nodes.length, 2); + assert.equal(resultObject.violations[0].nodes.length, 1); + assert.isDefined(resultObject.incomplete); + assert.isDefined(resultObject.inapplicable); }); });