From b10ce183cc69474b1cb548e5e67cbd3cb65cb5e9 Mon Sep 17 00:00:00 2001 From: Steven Lambert Date: Wed, 28 Oct 2020 14:44:18 -0600 Subject: [PATCH] fix(rule): add check node to the check result object --- lib/core/base/rule.js | 5 +++++ test/core/base/rule.js | 46 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/lib/core/base/rule.js b/lib/core/base/rule.js index 2a4b317c35..48685bc999 100644 --- a/lib/core/base/rule.js +++ b/lib/core/base/rule.js @@ -479,6 +479,7 @@ function findCheckResults(nodes, checkID) { var checks = getAllChecks(nodeResult); checks.forEach(function(checkResult) { if (checkResult.id === checkID) { + checkResult.node = nodeResult.node; checkResults.push(checkResult); } }); @@ -534,6 +535,10 @@ Rule.prototype.after = function(result, options) { var afterResults = check.after(beforeResults, option); beforeResults.forEach(function(item) { + // only add the node property for the check.after so we can + // look at which iframe a check result came from, but we don't + // want it for the final results object + delete item.node; if (afterResults.indexOf(item) === -1) { item.filtered = true; } diff --git a/test/core/base/rule.js b/test/core/base/rule.js index 995c0d0f7c..caeb97ccd4 100644 --- a/test/core/base/rule.js +++ b/test/core/base/rule.js @@ -1518,6 +1518,52 @@ describe('Rule', function() { assert.isTrue(success); }); + it('should add the check node to the check result', function() { + var success = false; + + var rule = new Rule( + { + id: 'cats', + any: ['cats'] + }, + { + checks: { + cats: { + id: 'cats', + enabled: true, + after: function(results) { + assert.equal(results[0].node, 'customNode'); + success = true; + return results; + } + } + } + } + ); + + rule.after( + { + id: 'cats', + nodes: [ + { + all: [], + none: [], + any: [ + { + id: 'cats', + result: true + } + ], + node: 'customNode' + } + ] + }, + { checks: { cats: { options: { dogs: true } } } } + ); + + assert.isTrue(success); + }); + it('should filter removed checks', function() { var rule = new Rule( {