diff --git a/src/checker/checker-nightmare.js b/src/checker/checker-nightmare.js index 4c7c154e..fa48d861 100644 --- a/src/checker/checker-nightmare.js +++ b/src/checker/checker-nightmare.js @@ -18,10 +18,16 @@ if (!fs.existsSync(PATH_TO_H5O)) { throw new Error('Can’t find h5o'); } -const PATH_TO_AXE_PATCH = path.join(__dirname, '../scripts/axe-patch.js'); -if (!fs.existsSync(PATH_TO_AXE_PATCH)) { - winston.verbose(PATH_TO_AXE_PATCH); - throw new Error('Can’t find axe-patch script'); +const PATH_TO_AXE_PATCH_GETSELECTOR = path.join(__dirname, '../scripts/axe-patch-getselector.js'); +if (!fs.existsSync(PATH_TO_AXE_PATCH_GETSELECTOR)) { + winston.verbose(PATH_TO_AXE_PATCH_GETSELECTOR); + throw new Error('Can’t find axe-patch-getselector script'); +} + +const PATH_TO_AXE_PATCH_ARIALOOKUPTABLE = path.join(__dirname, '../scripts/axe-patch-arialookuptable.js'); +if (!fs.existsSync(PATH_TO_AXE_PATCH_ARIALOOKUPTABLE)) { + winston.verbose(PATH_TO_AXE_PATCH_ARIALOOKUPTABLE); + throw new Error('Can’t find axe-patch-arialookuptable script'); } const PATH_TO_ACE_AXE = path.join(__dirname, '../scripts/ace-axe.js'); @@ -54,8 +60,9 @@ function checkSingle(spineItem, epub, nightmare) { return nightmare .goto(spineItem.url) .inject('js', PATH_TO_AXE) + .inject('js', PATH_TO_AXE_PATCH_GETSELECTOR) + .inject('js', PATH_TO_AXE_PATCH_ARIALOOKUPTABLE) .inject('js', PATH_TO_H5O) - .inject('js', PATH_TO_AXE_PATCH) .inject('js', PATH_TO_ACE_AXE) .inject('js', PATH_TO_ACE_EXTRACTION) .wait(50) diff --git a/src/scripts/axe-patch-arialookuptable.js b/src/scripts/axe-patch-arialookuptable.js new file mode 100644 index 00000000..3f329044 --- /dev/null +++ b/src/scripts/axe-patch-arialookuptable.js @@ -0,0 +1,360 @@ +'use strict'; + +(function axePatch(window) { + const axe = window.axe; + const dpubRoles = { + 'doc-abstract': { + type: 'section', + attributes: { + allowed: ['aria-expanded'], + }, + owned: null, + nameFrom: ['author'], + context: null, + }, + 'doc-acknowledgments': { + type: 'landmark', + attributes: { + allowed: ['aria-expanded'], + }, + owned: null, + nameFrom: ['author'], + context: null, + }, + 'doc-afterword': { + type: 'landmark', + attributes: { + allowed: ['aria-expanded'], + }, + owned: null, + nameFrom: ['author'], + context: null, + }, + 'doc-appendix': { + type: 'landmark', + attributes: { + allowed: ['aria-expanded'], + }, + owned: null, + nameFrom: ['author'], + context: null, + }, + 'doc-backlink': { + type: 'link', + attributes: { + allowed: ['aria-expanded'], + }, + owned: null, + nameFrom: ['author', 'contents'], + context: null, + }, + 'doc-biblioentry': { + type: 'listitem', + attributes: { + allowed: ['aria-expanded', 'aria-level', 'aria-posinset', 'aria-setsize'], + }, + owned: null, + nameFrom: ['author'], + context: ['doc-bibliography'], + }, + 'doc-bibliography': { + type: 'landmark', + attributes: { + allowed: ['aria-expanded'], + }, + owned: null, + nameFrom: ['author'], + context: null, + }, + 'doc-biblioref': { + type: 'link', + attributes: { + allowed: ['aria-expanded'], + }, + owned: null, + nameFrom: ['author', 'contents'], + context: null, + }, + 'doc-chapter': { + type: 'landmark', + attributes: { + allowed: ['aria-expanded'], + }, + owned: null, + namefrom: ['author'], + context: null, + }, + 'doc-colophon': { + type: 'section', + attributes: { + allowed: ['aria-expanded'], + }, + owned: null, + namefrom: ['author'], + context: null, + }, + 'doc-conclusion': { + type: 'landmark', + attributes: { + allowed: ['aria-expanded'], + }, + owned: null, + namefrom: ['author'], + context: null, + }, + 'doc-cover': { + type: 'img', + attributes: { + allowed: ['aria-expanded'], + }, + owned: null, + namefrom: ['author'], + context: null, + }, + 'doc-credit': { + type: 'section', + attributes: { + allowed: ['aria-expanded'], + }, + owned: null, + namefrom: ['author'], + context: null, + }, + 'doc-credits': { + type: 'landmark', + attributes: { + allowed: ['aria-expanded'], + }, + owned: null, + namefrom: ['author'], + context: null, + }, + 'doc-dedication': { + type: 'section', + attributes: { + allowed: ['aria-expanded'], + }, + owned: null, + namefrom: ['author'], + context: null, + }, + 'doc-endnote': { + type: 'listitem', + attributes: { + allowed: ['aria-expanded', 'aria-level', 'aria-posinset', 'aria-setsize'], + }, + owned: null, + namefrom: ['author'], + context: ['doc-endnotes'], + }, + 'doc-endnotes': { + type: 'landmark', + attributes: { + allowed: ['aria-expanded'], + }, + owned: ['doc-endnote'], + namefrom: ['author'], + context: null, + }, + 'doc-epigraph': { + type: 'section', + attributes: { + allowed: ['aria-expanded'], + }, + owned: null, + namefrom: ['author'], + context: null, + }, + 'doc-epilogue': { + type: 'landmark', + attributes: { + allowed: ['aria-expanded'], + }, + owned: null, + namefrom: ['author'], + context: null, + }, + 'doc-errata': { + type: 'landmark', + attributes: { + allowed: ['aria-expanded'], + }, + owned: null, + namefrom: ['author'], + context: null, + }, + 'doc-example': { + type: 'section', + attributes: { + allowed: ['aria-expanded'], + }, + owned: null, + namefrom: ['author'], + context: null, + }, + 'doc-footnote': { + type: 'section', + attributes: { + allowed: ['aria-expanded'], + }, + owned: null, + namefrom: ['author'], + context: null, + }, + 'doc-foreword': { + type: 'landmark', + attributes: { + allowed: ['aria-expanded'], + }, + owned: null, + namefrom: ['author'], + context: null, + }, + 'doc-glossary': { + type: 'landmark', + attributes: { + allowed: ['aria-expanded'], + }, + owned: ['term', 'definition'], + namefrom: ['author'], + context: null, + }, + 'doc-glossref': { + type: 'link', + attributes: { + allowed: ['aria-expanded'], + }, + owned: null, + namefrom: ['author', 'contents'], + context: null, + }, + 'doc-index': { + type: 'navigation', + attributes: { + allowed: ['aria-expanded'], + }, + owned: null, + namefrom: ['author'], + context: null, + }, + 'doc-introduction': { + type: 'landmark', + attributes: { + allowed: ['aria-expanded'], + }, + owned: null, + namefrom: ['author'], + context: null, + }, + 'doc-noteref': { + type: 'link', + attributes: { + allowed: ['aria-expanded'], + }, + owned: null, + namefrom: ['author', 'contents'], + context: null, + }, + 'doc-notice': { + type: 'note', + attributes: { + allowed: ['aria-expanded'], + }, + owned: null, + namefrom: ['author'], + context: null, + }, + 'doc-pagebreak': { + type: 'separator', + attributes: { + allowed: ['aria-expanded'], + }, + owned: null, + namefrom: ['author'], + context: null, + }, + 'doc-pagelist': { + type: 'navigation', + attributes: { + allowed: ['aria-expanded'], + }, + owned: null, + namefrom: ['author'], + context: null, + }, + 'doc-part': { + type: 'landmark', + attributes: { + allowed: ['aria-expanded'], + }, + owned: null, + namefrom: ['author'], + context: null, + }, + 'doc-preface': { + type: 'landmark', + attributes: { + allowed: ['aria-expanded'], + }, + owned: null, + namefrom: ['author'], + context: null, + }, + 'doc-prologue': { + type: 'landmark', + attributes: { + allowed: ['aria-expanded'], + }, + owned: null, + namefrom: ['author'], + context: null, + }, + 'doc-pullquote': { + type: 'none', + attributes: { + allowed: ['aria-expanded'], + }, + owned: null, + namefrom: ['author'], + context: null, + }, + 'doc-qna': { + type: 'section', + attributes: { + allowed: ['aria-expanded'], + }, + owned: null, + namefrom: ['author'], + context: null, + }, + 'doc-subtitle': { + type: 'sectionhead', + attributes: { + allowed: ['aria-expanded'], + }, + owned: null, + namefrom: ['author'], + context: null, + }, + 'doc-tip': { + type: 'note', + attributes: { + allowed: ['aria-expanded'], + }, + owned: null, + namefrom: ['author'], + context: null, + }, + 'doc-toc': { + type: 'navigation', + attributes: { + allowed: ['aria-expanded'], + }, + owned: null, + namefrom: ['author'], + context: null, + }, + }; + + Object.assign(axe.commons.aria._lut.role, dpubRoles); +}(window)); diff --git a/src/scripts/axe-patch.js b/src/scripts/axe-patch-getselector.js similarity index 100% rename from src/scripts/axe-patch.js rename to src/scripts/axe-patch-getselector.js diff --git a/tests/__tests__/axe-rules.test.js b/tests/__tests__/axe-rules.test.js index 7434c77f..eefdbb3f 100644 --- a/tests/__tests__/axe-rules.test.js +++ b/tests/__tests__/axe-rules.test.js @@ -40,3 +40,8 @@ test('`bypass` rule is disabled', async () => { const report = await ace('../data/axerule-bypass'); expect(report['earl:result']['earl:outcome']).toEqual('pass'); }); + +test('DPUB ARIA roles are allowed', async () => { + const report = await ace('../data/axerule-dpubroles'); + expect(report['earl:result']['earl:outcome']).toEqual('pass'); +}); diff --git a/tests/data/axerule-dpubroles/EPUB/content_001.xhtml b/tests/data/axerule-dpubroles/EPUB/content_001.xhtml new file mode 100644 index 00000000..ff451514 --- /dev/null +++ b/tests/data/axerule-dpubroles/EPUB/content_001.xhtml @@ -0,0 +1,56 @@ + +
+Call me Ishmael.
+ + + + + +