in src/test.js [69:150]
test(tagName, props, children, done) {
Object.keys(this.options.rules).forEach((key) => {
const rule = this.rules[key];
// ensure that the rule exists
if (!rule) {
throw new Error(`react-a11y: rule ${key} not found, `
+ 'maybe you\'re missing a plugin?');
}
// get options for rule
const [
sev,
...options
] = normalize(this.options.rules[key]);
if (sev !== 'off') {
const ctx = {
options,
React: this.React,
ReactDOM: this.ReactDOM
};
getTests(rule).reduce(async (pprev, defn) => {
// only fail once per rule
// so check if previous test failed
// already, if this is true, they havn't-
const prev = await pprev;
if (!prev) {
return prev;
}
const {
tagName: tagNames,
msg,
url,
AX,
test,
affects = allDevices
} = defn;
// filter by tagName
if (Array.isArray(tagNames)) {
if (tagNames.indexOf(tagName) < 0) {
return prev;
}
} else if (tagNames) {
if (tagName !== tagNames) {
return prev;
}
}
// perform the test
let pass;
// try/catch so that exceptions are not silently swallowed by await
try {
pass = await test(tagName, props, children, ctx);
} catch (error) {
console.log(error);
pass = false;
}
if (!pass) {
done({
tagName,
msg,
url,
AX,
props,
children,
severity: sev,
rule: key,
affects
});
}
return prev && pass;
}, true);
}
});
}