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3C,CAAC","sourcesContent":["/**\n@license\nCopyright (c) 2018 The Polymer Project Authors. All rights reserved.\nThis code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt\nThe complete set of authors may be found at http://polymer.github.io/AUTHORS.txt\nThe complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt\nCode distributed by Google as part of the polymer project is also\nsubject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt\n*/\n\nimport { ElementContext, RunOptions } from 'axe-core';\n\ndeclare global {\n namespace axe {\n const run: typeof import('axe-core').run;\n }\n}\n\nexport interface AxeReportOptions extends RunOptions {\n cleanup?: () => Promise<void>\n axeConfig?: RunOptions\n}\n\n/**\n This is an [axe-core](https://github.com/dequelabs/axe-core) reporter that returns an\n Error containing every a11y violation for an element. Use this if you want to\n include `axe-core` in automated Mocha tests, etc. Note that this helper does not\n include `axe-core` for you; you must do this separately.\n\n The `axeReport` function takes an optional second argument:\n {cleanup: {...}, axeConfig: {...}}, where `cleanup` is a callback to be\n called after the test is ran (so that you can remove the element from the DOM, etc)\n and `axeConfig` are the optional extra config parameters to pass to axe.\n\n Example (in a Mocha test):\n\n import 'axe-core/axe.min.js';\n import { axeReport } from 'pwa-helpers/axe-report.js';\n\n describe('button', function() {\n\n it('is accessible', function() {\n const button = document.createElement('button');\n button.textContent = 'click this'; // Test should fail without this line.\n return axeReport(button);\n\n // If you need to run any cleanup code after the test is run, you\n // can use the `cleanup` object. For example,\n // document.body.appendChild(button);\n // return axeReport(el, { cleanup() { el.remove(); } });\n });\n });\n*/\nexport async function axeReport(dom: ElementContext, config:AxeReportOptions = {}) {\n const {cleanup, axeConfig} = config;\n const defaultConfig: RunOptions = {\n runOnly: {\n type: 'tag',\n values: ['wcag2a', 'wcag2aa', 'section508']\n },\n // Ignore tests that are passing.\n resultTypes: ['violations']\n };\n const {violations} = await axe.run(dom, axeConfig || defaultConfig);\n if (cleanup) {\n await cleanup();\n }\n if (!violations.length) {\n return;\n }\n const errorMessage = ['Accessibility Violations', '---'];\n for (const violation of violations) {\n errorMessage.push(violation.help);\n for (const node of violation.nodes) {\n if (node.failureSummary) {\n errorMessage.push(node.failureSummary);\n }\n errorMessage.push(node.html);\n }\n errorMessage.push('---');\n }\n throw new Error(errorMessage.join('\\n'));\n}\n"]}
\No newline at end of file