-
Notifications
You must be signed in to change notification settings - Fork 776
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(run-virtual-rule): new api to run rules using only virtual nodes (…
…#1594) * feat(run-virtual-rule): new api to run rules using only virtual nodes * do not modify original rule * fix * fix comment * throw instead of return * add parnet to virtual node for contains lookup * checck for actualNode before using * can run through completely using real virtual node * finalize * use ternary * add test, return null node
- Loading branch information
Showing
11 changed files
with
371 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* global helpers */ | ||
|
||
/** | ||
* Run a rule in a non-browser environment | ||
* @param {String} ruleId Id of the rule | ||
* @param {VirtualNode} vNode The virtual node to run the rule against | ||
* @param {Object} options (optional) Set of options passed into rules or checks | ||
* @return {Object} axe results for the rule run | ||
*/ | ||
axe.runVirtualRule = function(ruleId, vNode, options = {}) { | ||
options.reporter = options.reporter || axe._audit.reporter || 'v1'; | ||
axe._selectorData = {}; | ||
|
||
let rule = axe._audit.rules.find(rule => rule.id === ruleId); | ||
|
||
if (!rule) { | ||
throw new Error('unknown rule `' + ruleId + '`'); | ||
} | ||
|
||
// rule.prototype.gather calls axe.utils.isHidden which in turn calls | ||
// window.getComputedStyle if the rule excludes hidden elements. we | ||
// can avoid this call by forcing the rule to not exclude hidden | ||
// elements | ||
rule = Object.create(rule, { excludeHidden: { value: false } }); | ||
|
||
const context = { | ||
include: [vNode] | ||
}; | ||
|
||
const rawResults = rule.runSync(context, options); | ||
axe.utils.publishMetaData(rawResults); | ||
axe.utils.finalizeRuleResult(rawResults); | ||
const results = axe.utils.aggregateResult([rawResults]); | ||
|
||
results.violations.forEach(result => | ||
result.nodes.forEach(nodeResult => { | ||
nodeResult.failureSummary = helpers.failureSummary(nodeResult); | ||
}) | ||
); | ||
|
||
return { | ||
...helpers.getEnvironmentData(), | ||
...results, | ||
toolOptions: options | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.