Skip to content

Commit

Permalink
fix(rule): add check node to the check result object (#2608)
Browse files Browse the repository at this point in the history
  • Loading branch information
straker committed Oct 29, 2020
1 parent 1b66930 commit b188911
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/core/base/rule.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});
Expand Down Expand Up @@ -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;
}
Expand Down
46 changes: 46 additions & 0 deletions test/core/base/rule.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
{
Expand Down

0 comments on commit b188911

Please sign in to comment.