@axe-core/react 4.4.3-alpha.262 → 4.4.3-alpha.265
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +1 -2
- package/dist/index.js +7 -15
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -18,5 +18,4 @@ interface ReactSpec extends axeCore.Spec {
|
|
|
18
18
|
* @param {Function} _logger Logger implementation
|
|
19
19
|
*/
|
|
20
20
|
declare function reactAxe(_React: typeof React, _ReactDOM: typeof ReactDOM, _timeout: number, _conf?: ReactSpec, _context?: axeCore.ElementContext, _logger?: (results: axeCore.AxeResults) => void): Promise<void>;
|
|
21
|
-
export
|
|
22
|
-
export default reactAxe;
|
|
21
|
+
export = reactAxe;
|
package/dist/index.js
CHANGED
|
@@ -10,12 +10,14 @@ var __assign = (this && this.__assign) || function () {
|
|
|
10
10
|
};
|
|
11
11
|
return __assign.apply(this, arguments);
|
|
12
12
|
};
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
+
};
|
|
15
16
|
/* global Promise */
|
|
16
17
|
var axeCore = require("axe-core");
|
|
17
18
|
var rIC = require("requestidlecallback");
|
|
18
19
|
var after = require("./after");
|
|
20
|
+
var cache_1 = __importDefault(require("./cache"));
|
|
19
21
|
var requestIdleCallback = rIC.request;
|
|
20
22
|
var cancelIdleCallback = rIC.cancel;
|
|
21
23
|
var React;
|
|
@@ -49,7 +51,6 @@ var conf;
|
|
|
49
51
|
var _createElement;
|
|
50
52
|
var components = {};
|
|
51
53
|
var nodes = [document.documentElement];
|
|
52
|
-
var cache = {};
|
|
53
54
|
// Returns a function, that, as long as it continues to be invoked, will not
|
|
54
55
|
// be triggered. The function will be called after it stops being called for
|
|
55
56
|
// N milliseconds. If `immediate` is passed, trigger the function on the
|
|
@@ -203,8 +204,8 @@ function checkAndReport(node, timeout) {
|
|
|
203
204
|
results.violations = results.violations.filter(function (result) {
|
|
204
205
|
result.nodes = result.nodes.filter(function (node) {
|
|
205
206
|
var key = node.target.toString() + result.id;
|
|
206
|
-
var retVal = !
|
|
207
|
-
|
|
207
|
+
var retVal = !cache_1.default.get(key);
|
|
208
|
+
cache_1.default.set(key, key);
|
|
208
209
|
return disableDeduplicate || retVal;
|
|
209
210
|
});
|
|
210
211
|
return !!result.nodes.length;
|
|
@@ -359,14 +360,5 @@ function reactAxe(_React, _ReactDOM, _timeout, _conf, _context, _logger) {
|
|
|
359
360
|
}
|
|
360
361
|
return checkAndReport(document.body, timeout);
|
|
361
362
|
}
|
|
362
|
-
|
|
363
|
-
// between tests
|
|
364
|
-
function _reset() {
|
|
365
|
-
Object.keys(cache).forEach(function (key) {
|
|
366
|
-
delete cache[key];
|
|
367
|
-
});
|
|
368
|
-
axeCore.reset();
|
|
369
|
-
}
|
|
370
|
-
exports._reset = _reset;
|
|
371
|
-
exports.default = reactAxe;
|
|
363
|
+
module.exports = reactAxe;
|
|
372
364
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,oBAAoB;AACpB,kCAAqC;AACrC,yCAA4C;AAC5C,+BAAkC;AAElC,IAAM,mBAAmB,GAAG,GAAG,CAAC,OAAO,CAAC;AACxC,IAAM,kBAAkB,GAAG,GAAG,CAAC,MAAM,CAAC;AAEtC,IAAI,KAAK,CAAC;AACV,IAAI,QAAQ,CAAC;AACb,IAAI,MAAM,CAAC;AAEX,qDAAqD;AACrD,IAAM,UAAU,GAAG;IACjB,OAAO,EAAE,SAAS;IAClB,KAAK,EAAE,SAAS;IAChB,IAAI,EAAE,OAAO;CACd,CAAC;AAEF,uDAAuD;AACvD,IAAM,SAAS,GAAG;IAChB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nB,cAAc,GAAG,KAAK,CAAC,aAAa,CAAC;QAErC,KAAK,CAAC,aAAa,GAAG;YAAU,cAAO;iBAAP,UAAO,EAAP,qBAAO,EAAP,IAAO;gBAAP,yBAAO;;YACrC,IAAM,OAAO,GAAG,cAAc,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;YAEjD,IAAI,OAAO,CAAC,MAAM,IAAI,OAAO,CAAC,MAAM,CAAC,SAAS,EAAE;gBAC9C,YAAY,CAAC,OAAO,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;aACxC;iBAAM,IAAI,OAAO,CAAC,MAAM,IAAI,OAAO,CAAC,MAAM,CAAC,SAAS,EAAE;gBACrD,YAAY,CAAC,OAAO,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;aACxC;YAED,OAAO,OAAO,CAAC;QACjB,CAAC,CAAC;KACH;IAED,OAAO,cAAc,CAAC,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;AAChD,CAAC;AAED,8DAA8D;AAC9D,gBAAgB;AAChB,SAAgB,MAAM;IACpB,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,UAAA,GAAG;QAC5B,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC;IACpB,CAAC,CAAC,CAAC;IAEH,OAAO,CAAC,KAAK,EAAE,CAAC;AAClB,CAAC;AAND,wBAMC;AAED,kBAAe,QAAQ,CAAC","sourcesContent":["/* global Promise */\nimport axeCore = require('axe-core');\nimport rIC = require('requestidlecallback');\nimport after = require('./after');\n\nconst requestIdleCallback = rIC.request;\nconst cancelIdleCallback = rIC.cancel;\n\nlet React;\nlet ReactDOM;\nlet logger;\n\n// contrasted against Chrome default color of #ffffff\nconst lightTheme = {\n serious: '#d93251',\n minor: '#d24700',\n text: 'black'\n};\n\n// contrasted against Safari dark mode color of #535353\nconst darkTheme = {\n serious: '#ffb3b3',\n minor: '#ffd500',\n text: 'white'\n};\n\nconst theme =\n window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches\n ? darkTheme\n : lightTheme;\n\nconst boldCourier = 'font-weight:bold;font-family:Courier;';\nconst critical = `color:${theme.serious};font-weight:bold;`;\nconst serious = `color:${theme.serious};font-weight:normal;`;\nconst moderate = `color:${theme.minor};font-weight:bold;`;\nconst minor = `color:${theme.minor};font-weight:normal;`;\nconst defaultReset = `font-color:${theme.text};font-weight:normal;`;\n\nlet idleId: number | undefined;\nlet timeout: number;\nlet context: axeCore.ElementContext | undefined;\nlet conf: ReactSpec;\nlet _createElement: typeof React.createElement;\nconst components: { [id: number]: React.Component } = {};\nconst nodes: Node[] = [document.documentElement];\nconst cache: { [key: string]: string } = {};\n\n// Returns a function, that, as long as it continues to be invoked, will not\n// be triggered. The function will be called after it stops being called for\n// N milliseconds. If `immediate` is passed, trigger the function on the\n// leading edge, instead of the trailing.\n// @see https://davidwalsh.name/javascript-debounce-function\nfunction debounce(func: Function, wait: number, immediate?: boolean): Function {\n let _timeout;\n return function (...args): void {\n const later = (): void => {\n _timeout = null;\n if (!immediate) func.apply(this, args);\n };\n const callNow = immediate && !_timeout;\n clearTimeout(_timeout);\n _timeout = setTimeout(later, wait);\n if (callNow) func.apply(this, args);\n };\n}\n\n/**\n * Return the entire parent tree of a node (from HTML down).\n * @param {Node} node\n * @return {Node[]}\n */\nfunction getPath(node: Node): Node[] {\n const path: Node[] = [node];\n while (node && node.nodeName.toLowerCase() !== 'html') {\n path.push(node.parentNode);\n node = node.parentNode;\n }\n if (!node || !node.parentNode) {\n return null;\n }\n return path.reverse();\n}\n\n/**\n * Find the common parent of an array of nodes.\n * @param {Node[]} nodes\n * @return {Node}\n */\nfunction getCommonParent(nodes: Node[]): Node {\n let path: Node[] | null;\n let nextPath: Node[] | null;\n if (nodes.length === 1) {\n return nodes.pop();\n }\n while (!path && nodes.length) {\n path = getPath(nodes.pop());\n }\n while (nodes.length) {\n nextPath = getPath(nodes.pop());\n if (nextPath) {\n path = path.filter((node: Node, index: number) => {\n return nextPath.length > index && nextPath[index] === node;\n });\n }\n }\n return path ? path[path.length - 1] : document;\n}\n\n/**\n * Log the axe result node to the console\n * @param {NodeResult} node\n * @param {Function} logFn console log function to use (error, warn, log, etc.)\n */\nfunction logElement(\n node: axeCore.NodeResult | axeCore.RelatedNode,\n logFn: (...args) => void\n): void {\n const el = document.querySelector(node.target.toString());\n if (!el) {\n logFn('Selector: %c%s', boldCourier, node.target.toString());\n } else {\n logFn('Element: %o', el);\n }\n}\n\n/**\n * Log the axe result node html tot he console\n * @param {NodeResult} node\n */\nfunction logHtml(node: axeCore.NodeResult | axeCore.RelatedNode): void {\n console.log('HTML: %c%s', boldCourier, node.html);\n}\n\n/**\n * Log the failure message of a node result.\n * @param {NodeResult} node\n * @param {String} key which check array to log from (any, all, none)\n */\nfunction logFailureMessage(\n node: axeCore.NodeResult,\n key: AxeCoreNodeResultKey\n): void {\n // this exists on axe but we don't export it as part of the typescript\n // namespace, so just let me use it as I need\n const message: string = (\n axeCore as unknown as AxeWithAudit\n )._audit.data.failureSummaries[key].failureMessage(\n node[key].map(check => check.message || '')\n );\n\n console.error(message);\n}\n\n/**\n * Log as a group the node result and failure message.\n * @param {NodeResult} node\n * @param {String} key which check array to log from (any, all, none)\n */\nfunction failureSummary(\n node: axeCore.NodeResult,\n key: AxeCoreNodeResultKey\n): void {\n if (node[key].length > 0) {\n logElement(node, console.groupCollapsed);\n logHtml(node);\n logFailureMessage(node, key);\n\n let relatedNodes: axeCore.RelatedNode[] = [];\n node[key].forEach(check => {\n relatedNodes = relatedNodes.concat(check.relatedNodes);\n });\n\n if (relatedNodes.length > 0) {\n console.groupCollapsed('Related nodes');\n relatedNodes.forEach(relatedNode => {\n logElement(relatedNode, console.log);\n logHtml(relatedNode);\n });\n console.groupEnd();\n }\n\n console.groupEnd();\n }\n}\n\n/**\n * Run axe against the passed in node and report violations\n * @param {*} node\n * @param {Number} timeout force call of axe.run after the timeout has passed (if not called before)\n * @return {Promise}\n */\nfunction checkAndReport(node: Node, timeout: number): Promise<void> {\n const disableDeduplicate = conf['disableDeduplicate'];\n\n if (idleId) {\n cancelIdleCallback(idleId);\n idleId = undefined;\n }\n\n return new Promise((resolve, reject) => {\n nodes.push(node);\n idleId = requestIdleCallback(\n () => {\n let n: axeCore.ElementContext | Node = context;\n if (n === undefined) {\n n = getCommonParent(nodes.filter(node => node.isConnected));\n if (n.nodeName.toLowerCase() === 'html') {\n // if the only common parent is the body, then analyze the whole page\n n = document;\n }\n }\n axeCore.configure({ allowedOrigins: ['<unsafe_all_origins>'] });\n axeCore.run(\n n,\n { reporter: 'v2' },\n function (error: Error, results: axeCore.AxeResults) {\n if (error) {\n return reject(error);\n }\n\n results.violations = results.violations.filter(result => {\n result.nodes = result.nodes.filter(node => {\n const key: string = node.target.toString() + result.id;\n const retVal = !cache[key];\n cache[key] = key;\n return disableDeduplicate || retVal;\n });\n return !!result.nodes.length;\n });\n\n if (results.violations.length) {\n logger(results);\n }\n\n resolve();\n }\n );\n },\n {\n timeout: timeout\n }\n );\n });\n}\n\n/**\n * Check the node for violations.\n * @param {Component} component\n */\nfunction checkNode(component: React.Component): void {\n let node: Node;\n\n try {\n node = ReactDOM.findDOMNode(component);\n } catch (e) {\n console.group('%caxe error: could not check node', critical);\n console.group('%cComponent', serious);\n console.error(component);\n console.groupEnd();\n console.group('%cError', serious);\n console.error(e);\n console.groupEnd();\n console.groupEnd();\n }\n\n if (node) {\n checkAndReport(node, timeout);\n }\n}\n\n/**\n * Check the component for violations whenever the DOM updates\n * @param {Component} component\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nfunction componentAfterRender(component: any): void {\n const debounceCheckNode: Function = debounce(checkNode, timeout, true);\n after(component, 'componentDidMount', debounceCheckNode);\n after(component, 'componentDidUpdate', debounceCheckNode);\n}\n\n/**\n * Add a component to track.\n * @param {Component} component\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nfunction addComponent(component: any): void {\n const reactInstance = component._reactInternalInstance || {};\n const reactInstanceDebugID = reactInstance._debugID;\n const reactFiberInstance = component._reactInternalFiber || {};\n const reactFiberInstanceDebugID = reactFiberInstance._debugID;\n const reactInternals = component._reactInternals || {};\n const reactInternalsDebugID = reactInternals._debugID;\n\n if (reactInstanceDebugID && !components[reactInstanceDebugID]) {\n components[reactInstanceDebugID] = component;\n componentAfterRender(component);\n } else if (\n reactFiberInstanceDebugID &&\n !components[reactFiberInstanceDebugID]\n ) {\n components[reactFiberInstanceDebugID] = component;\n componentAfterRender(component);\n } else if (reactInternalsDebugID && !components[reactInternalsDebugID]) {\n components[reactInternalsDebugID] = component;\n componentAfterRender(component);\n }\n}\n\n/**\n * Log axe violations to console.\n * @param {AxeResults} results\n */\nfunction logToConsole(results: axeCore.AxeResults): void {\n console.group('%cNew axe issues', serious);\n results.violations.forEach(result => {\n let fmt: string;\n switch (result.impact) {\n case 'critical':\n fmt = critical;\n break;\n case 'serious':\n fmt = serious;\n break;\n case 'moderate':\n fmt = moderate;\n break;\n case 'minor':\n fmt = minor;\n break;\n default:\n fmt = minor;\n break;\n }\n console.groupCollapsed(\n '%c%s: %c%s %s',\n fmt,\n result.impact,\n defaultReset,\n result.help,\n result.helpUrl\n );\n result.nodes.forEach(node => {\n failureSummary(node, 'any');\n failureSummary(node, 'none');\n });\n console.groupEnd();\n });\n console.groupEnd();\n}\n\n/**\n * To support paramater of type runOnly\n */\ninterface ReactSpec extends axeCore.Spec {\n runOnly?: string[];\n disableDeduplicate?: boolean;\n}\n\n/**\n * Run axe against all changes made in a React app.\n * @parma {React} _React React instance\n * @param {ReactDOM} _ReactDOM ReactDOM instance\n * @param {Number} _timeout debounce timeout in milliseconds\n * @parma {Spec} conf React axe.configure Spec object\n * @param {ElementContext} _context axe ElementContent object\n * @param {Function} _logger Logger implementation\n */\nfunction reactAxe(\n _React: typeof React,\n _ReactDOM: typeof ReactDOM,\n _timeout: number,\n _conf = {} as ReactSpec,\n _context?: axeCore.ElementContext,\n _logger?: (results: axeCore.AxeResults) => void\n): Promise<void> {\n React = _React;\n ReactDOM = _ReactDOM;\n timeout = _timeout;\n context = _context;\n conf = _conf;\n logger = _logger || logToConsole;\n\n const runOnly = conf['runOnly'];\n if (runOnly) {\n conf['rules'] = axeCore\n .getRules(runOnly)\n .map(rule => ({ ...rule, id: rule.ruleId, enabled: true }));\n conf['disableOtherRules'] = true;\n }\n\n if (Object.keys(conf).length > 0) {\n axeCore.configure(conf);\n }\n axeCore.configure({ allowedOrigins: ['<unsafe_all_origins>'] });\n if (!_createElement) {\n _createElement = React.createElement;\n\n React.createElement = function (...args): React.Component {\n const reactEl = _createElement.apply(this, args);\n\n if (reactEl._owner && reactEl._owner._instance) {\n addComponent(reactEl._owner._instance);\n } else if (reactEl._owner && reactEl._owner.stateNode) {\n addComponent(reactEl._owner.stateNode);\n }\n\n return reactEl;\n };\n }\n\n return checkAndReport(document.body, timeout);\n}\n\n// export function just for tests so we can have a clean state\n// between tests\nexport function _reset() {\n Object.keys(cache).forEach(key => {\n delete cache[key];\n });\n\n axeCore.reset();\n}\n\nexport default reactAxe;\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,oBAAoB;AACpB,kCAAqC;AACrC,yCAA4C;AAC5C,+BAAkC;AAClC,kDAA4B;AAE5B,IAAM,mBAAmB,GAAG,GAAG,CAAC,OAAO,CAAC;AACxC,IAAM,kBAAkB,GAAG,GAAG,CAAC,MAAM,CAAC;AAEtC,IAAI,KAAK,CAAC;AACV,IAAI,QAAQ,CAAC;AACb,IAAI,MAAM,CAAC;AAEX,qDAAqD;AACrD,IAAM,UAAU,GAAG;IACjB,OAAO,EAAE,SAAS;IAClB,KAAK,EAAE,SAAS;IAChB,IAAI,EAAE,OAAO;CACd,CAAC;AAEF,uDAAuD;AACvD,IAAM,SAAS,GAAG;IAChB,OAAO,EAAE,SAAS;IAClB,KAAK,EAAE,SAAS;IAChB,IAAI,EAAE,OAAO;CACd,CA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,UAAO,EAAP,qBAAO,EAAP,IAAO;gBAAP,yBAAO;;YACrC,IAAM,OAAO,GAAG,cAAc,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;YAEjD,IAAI,OAAO,CAAC,MAAM,IAAI,OAAO,CAAC,MAAM,CAAC,SAAS,EAAE;gBAC9C,YAAY,CAAC,OAAO,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;aACxC;iBAAM,IAAI,OAAO,CAAC,MAAM,IAAI,OAAO,CAAC,MAAM,CAAC,SAAS,EAAE;gBACrD,YAAY,CAAC,OAAO,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;aACxC;YAED,OAAO,OAAO,CAAC;QACjB,CAAC,CAAC;KACH;IAED,OAAO,cAAc,CAAC,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;AAChD,CAAC;AAED,iBAAS,QAAQ,CAAC","sourcesContent":["/* global Promise */\nimport axeCore = require('axe-core');\nimport rIC = require('requestidlecallback');\nimport after = require('./after');\nimport cache from './cache';\n\nconst requestIdleCallback = rIC.request;\nconst cancelIdleCallback = rIC.cancel;\n\nlet React;\nlet ReactDOM;\nlet logger;\n\n// contrasted against Chrome default color of #ffffff\nconst lightTheme = {\n serious: '#d93251',\n minor: '#d24700',\n text: 'black'\n};\n\n// contrasted against Safari dark mode color of #535353\nconst darkTheme = {\n serious: '#ffb3b3',\n minor: '#ffd500',\n text: 'white'\n};\n\nconst theme =\n window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches\n ? darkTheme\n : lightTheme;\n\nconst boldCourier = 'font-weight:bold;font-family:Courier;';\nconst critical = `color:${theme.serious};font-weight:bold;`;\nconst serious = `color:${theme.serious};font-weight:normal;`;\nconst moderate = `color:${theme.minor};font-weight:bold;`;\nconst minor = `color:${theme.minor};font-weight:normal;`;\nconst defaultReset = `font-color:${theme.text};font-weight:normal;`;\n\nlet idleId: number | undefined;\nlet timeout: number;\nlet context: axeCore.ElementContext | undefined;\nlet conf: ReactSpec;\nlet _createElement: typeof React.createElement;\nconst components: { [id: number]: React.Component } = {};\nconst nodes: Node[] = [document.documentElement];\n\n// Returns a function, that, as long as it continues to be invoked, will not\n// be triggered. The function will be called after it stops being called for\n// N milliseconds. If `immediate` is passed, trigger the function on the\n// leading edge, instead of the trailing.\n// @see https://davidwalsh.name/javascript-debounce-function\nfunction debounce(func: Function, wait: number, immediate?: boolean): Function {\n let _timeout;\n return function (...args): void {\n const later = (): void => {\n _timeout = null;\n if (!immediate) func.apply(this, args);\n };\n const callNow = immediate && !_timeout;\n clearTimeout(_timeout);\n _timeout = setTimeout(later, wait);\n if (callNow) func.apply(this, args);\n };\n}\n\n/**\n * Return the entire parent tree of a node (from HTML down).\n * @param {Node} node\n * @return {Node[]}\n */\nfunction getPath(node: Node): Node[] {\n const path: Node[] = [node];\n while (node && node.nodeName.toLowerCase() !== 'html') {\n path.push(node.parentNode);\n node = node.parentNode;\n }\n if (!node || !node.parentNode) {\n return null;\n }\n return path.reverse();\n}\n\n/**\n * Find the common parent of an array of nodes.\n * @param {Node[]} nodes\n * @return {Node}\n */\nfunction getCommonParent(nodes: Node[]): Node {\n let path: Node[] | null;\n let nextPath: Node[] | null;\n if (nodes.length === 1) {\n return nodes.pop();\n }\n while (!path && nodes.length) {\n path = getPath(nodes.pop());\n }\n while (nodes.length) {\n nextPath = getPath(nodes.pop());\n if (nextPath) {\n path = path.filter((node: Node, index: number) => {\n return nextPath.length > index && nextPath[index] === node;\n });\n }\n }\n return path ? path[path.length - 1] : document;\n}\n\n/**\n * Log the axe result node to the console\n * @param {NodeResult} node\n * @param {Function} logFn console log function to use (error, warn, log, etc.)\n */\nfunction logElement(\n node: axeCore.NodeResult | axeCore.RelatedNode,\n logFn: (...args) => void\n): void {\n const el = document.querySelector(node.target.toString());\n if (!el) {\n logFn('Selector: %c%s', boldCourier, node.target.toString());\n } else {\n logFn('Element: %o', el);\n }\n}\n\n/**\n * Log the axe result node html tot he console\n * @param {NodeResult} node\n */\nfunction logHtml(node: axeCore.NodeResult | axeCore.RelatedNode): void {\n console.log('HTML: %c%s', boldCourier, node.html);\n}\n\n/**\n * Log the failure message of a node result.\n * @param {NodeResult} node\n * @param {String} key which check array to log from (any, all, none)\n */\nfunction logFailureMessage(\n node: axeCore.NodeResult,\n key: AxeCoreNodeResultKey\n): void {\n // this exists on axe but we don't export it as part of the typescript\n // namespace, so just let me use it as I need\n const message: string = (\n axeCore as unknown as AxeWithAudit\n )._audit.data.failureSummaries[key].failureMessage(\n node[key].map(check => check.message || '')\n );\n\n console.error(message);\n}\n\n/**\n * Log as a group the node result and failure message.\n * @param {NodeResult} node\n * @param {String} key which check array to log from (any, all, none)\n */\nfunction failureSummary(\n node: axeCore.NodeResult,\n key: AxeCoreNodeResultKey\n): void {\n if (node[key].length > 0) {\n logElement(node, console.groupCollapsed);\n logHtml(node);\n logFailureMessage(node, key);\n\n let relatedNodes: axeCore.RelatedNode[] = [];\n node[key].forEach(check => {\n relatedNodes = relatedNodes.concat(check.relatedNodes);\n });\n\n if (relatedNodes.length > 0) {\n console.groupCollapsed('Related nodes');\n relatedNodes.forEach(relatedNode => {\n logElement(relatedNode, console.log);\n logHtml(relatedNode);\n });\n console.groupEnd();\n }\n\n console.groupEnd();\n }\n}\n\n/**\n * Run axe against the passed in node and report violations\n * @param {*} node\n * @param {Number} timeout force call of axe.run after the timeout has passed (if not called before)\n * @return {Promise}\n */\nfunction checkAndReport(node: Node, timeout: number): Promise<void> {\n const disableDeduplicate = conf['disableDeduplicate'];\n\n if (idleId) {\n cancelIdleCallback(idleId);\n idleId = undefined;\n }\n\n return new Promise((resolve, reject) => {\n nodes.push(node);\n idleId = requestIdleCallback(\n () => {\n let n: axeCore.ElementContext | Node = context;\n if (n === undefined) {\n n = getCommonParent(nodes.filter(node => node.isConnected));\n if (n.nodeName.toLowerCase() === 'html') {\n // if the only common parent is the body, then analyze the whole page\n n = document;\n }\n }\n axeCore.configure({ allowedOrigins: ['<unsafe_all_origins>'] });\n axeCore.run(\n n,\n { reporter: 'v2' },\n function (error: Error, results: axeCore.AxeResults) {\n if (error) {\n return reject(error);\n }\n\n results.violations = results.violations.filter(result => {\n result.nodes = result.nodes.filter(node => {\n const key: string = node.target.toString() + result.id;\n const retVal = !cache.get(key);\n cache.set(key, key);\n return disableDeduplicate || retVal;\n });\n return !!result.nodes.length;\n });\n\n if (results.violations.length) {\n logger(results);\n }\n\n resolve();\n }\n );\n },\n {\n timeout: timeout\n }\n );\n });\n}\n\n/**\n * Check the node for violations.\n * @param {Component} component\n */\nfunction checkNode(component: React.Component): void {\n let node: Node;\n\n try {\n node = ReactDOM.findDOMNode(component);\n } catch (e) {\n console.group('%caxe error: could not check node', critical);\n console.group('%cComponent', serious);\n console.error(component);\n console.groupEnd();\n console.group('%cError', serious);\n console.error(e);\n console.groupEnd();\n console.groupEnd();\n }\n\n if (node) {\n checkAndReport(node, timeout);\n }\n}\n\n/**\n * Check the component for violations whenever the DOM updates\n * @param {Component} component\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nfunction componentAfterRender(component: any): void {\n const debounceCheckNode: Function = debounce(checkNode, timeout, true);\n after(component, 'componentDidMount', debounceCheckNode);\n after(component, 'componentDidUpdate', debounceCheckNode);\n}\n\n/**\n * Add a component to track.\n * @param {Component} component\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nfunction addComponent(component: any): void {\n const reactInstance = component._reactInternalInstance || {};\n const reactInstanceDebugID = reactInstance._debugID;\n const reactFiberInstance = component._reactInternalFiber || {};\n const reactFiberInstanceDebugID = reactFiberInstance._debugID;\n const reactInternals = component._reactInternals || {};\n const reactInternalsDebugID = reactInternals._debugID;\n\n if (reactInstanceDebugID && !components[reactInstanceDebugID]) {\n components[reactInstanceDebugID] = component;\n componentAfterRender(component);\n } else if (\n reactFiberInstanceDebugID &&\n !components[reactFiberInstanceDebugID]\n ) {\n components[reactFiberInstanceDebugID] = component;\n componentAfterRender(component);\n } else if (reactInternalsDebugID && !components[reactInternalsDebugID]) {\n components[reactInternalsDebugID] = component;\n componentAfterRender(component);\n }\n}\n\n/**\n * Log axe violations to console.\n * @param {AxeResults} results\n */\nfunction logToConsole(results: axeCore.AxeResults): void {\n console.group('%cNew axe issues', serious);\n results.violations.forEach(result => {\n let fmt: string;\n switch (result.impact) {\n case 'critical':\n fmt = critical;\n break;\n case 'serious':\n fmt = serious;\n break;\n case 'moderate':\n fmt = moderate;\n break;\n case 'minor':\n fmt = minor;\n break;\n default:\n fmt = minor;\n break;\n }\n console.groupCollapsed(\n '%c%s: %c%s %s',\n fmt,\n result.impact,\n defaultReset,\n result.help,\n result.helpUrl\n );\n result.nodes.forEach(node => {\n failureSummary(node, 'any');\n failureSummary(node, 'none');\n });\n console.groupEnd();\n });\n console.groupEnd();\n}\n\n/**\n * To support paramater of type runOnly\n */\ninterface ReactSpec extends axeCore.Spec {\n runOnly?: string[];\n disableDeduplicate?: boolean;\n}\n\n/**\n * Run axe against all changes made in a React app.\n * @parma {React} _React React instance\n * @param {ReactDOM} _ReactDOM ReactDOM instance\n * @param {Number} _timeout debounce timeout in milliseconds\n * @parma {Spec} conf React axe.configure Spec object\n * @param {ElementContext} _context axe ElementContent object\n * @param {Function} _logger Logger implementation\n */\nfunction reactAxe(\n _React: typeof React,\n _ReactDOM: typeof ReactDOM,\n _timeout: number,\n _conf = {} as ReactSpec,\n _context?: axeCore.ElementContext,\n _logger?: (results: axeCore.AxeResults) => void\n): Promise<void> {\n React = _React;\n ReactDOM = _ReactDOM;\n timeout = _timeout;\n context = _context;\n conf = _conf;\n logger = _logger || logToConsole;\n\n const runOnly = conf['runOnly'];\n if (runOnly) {\n conf['rules'] = axeCore\n .getRules(runOnly)\n .map(rule => ({ ...rule, id: rule.ruleId, enabled: true }));\n conf['disableOtherRules'] = true;\n }\n\n if (Object.keys(conf).length > 0) {\n axeCore.configure(conf);\n }\n axeCore.configure({ allowedOrigins: ['<unsafe_all_origins>'] });\n if (!_createElement) {\n _createElement = React.createElement;\n\n React.createElement = function (...args): React.Component {\n const reactEl = _createElement.apply(this, args);\n\n if (reactEl._owner && reactEl._owner._instance) {\n addComponent(reactEl._owner._instance);\n } else if (reactEl._owner && reactEl._owner.stateNode) {\n addComponent(reactEl._owner.stateNode);\n }\n\n return reactEl;\n };\n }\n\n return checkAndReport(document.body, timeout);\n}\n\nexport = reactAxe;\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@axe-core/react",
|
|
3
|
-
"version": "4.4.3-alpha.
|
|
3
|
+
"version": "4.4.3-alpha.265+7dc6a03",
|
|
4
4
|
"description": "Dynamic accessibility analysis for React using axe-core",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -77,5 +77,5 @@
|
|
|
77
77
|
"<rootDir>/test/jest.setup.js"
|
|
78
78
|
]
|
|
79
79
|
},
|
|
80
|
-
"gitHead": "
|
|
80
|
+
"gitHead": "7dc6a0355d64e22b442943670a11b347eacaa92a"
|
|
81
81
|
}
|