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(rule): add check node to the check result object #2608

Merged
merged 1 commit into from
Oct 29, 2020
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
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