From e3215ff88dd4ad75dafc217303671694f4b95d00 Mon Sep 17 00:00:00 2001 From: Romain Deltour Date: Tue, 3 Oct 2017 23:06:49 +0200 Subject: [PATCH] =?UTF-8?q?fix:=20disable=20aXe=E2=80=99s=20`bypass`=20rul?= =?UTF-8?q?e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The `bypass` rule ensures each page has at least one mechanism for a user to bypass navigation and jump straight to the content. This makes no real sense for EPUBs, where an HTML document may well contain the continuity of previous content. Closes #40 --- src/scripts/ace-axe.js | 5 +++ tests/__tests__/axe-rules.test.js | 42 +++++++++++++++++++ .../axerule-bypass/EPUB/content_001.xhtml | 9 ++++ tests/data/axerule-bypass/EPUB/nav.xhtml | 12 ++++++ tests/data/axerule-bypass/EPUB/package.opf | 16 +++++++ .../axerule-bypass/META-INF/container.xml | 6 +++ tests/data/axerule-bypass/mimetype | 1 + 7 files changed, 91 insertions(+) create mode 100644 tests/__tests__/axe-rules.test.js create mode 100644 tests/data/axerule-bypass/EPUB/content_001.xhtml create mode 100644 tests/data/axerule-bypass/EPUB/nav.xhtml create mode 100644 tests/data/axerule-bypass/EPUB/package.opf create mode 100644 tests/data/axerule-bypass/META-INF/container.xml create mode 100644 tests/data/axerule-bypass/mimetype diff --git a/src/scripts/ace-axe.js b/src/scripts/ace-axe.js index 7e838621..32594b8d 100644 --- a/src/scripts/ace-axe.js +++ b/src/scripts/ace-axe.js @@ -81,6 +81,11 @@ daisy.ace.run = function(done) { }; window.axe.run( + { + "rules": { + "bypass": { enabled: false }, + } + }, function(axeError, axeResult) { if (axeError) { done(axeError, null); diff --git a/tests/__tests__/axe-rules.test.js b/tests/__tests__/axe-rules.test.js new file mode 100644 index 00000000..7434c77f --- /dev/null +++ b/tests/__tests__/axe-rules.test.js @@ -0,0 +1,42 @@ +'use strict'; + +const fs = require('fs'); +const path = require('path'); +const tmp = require('tmp'); + +const runAce = require('../runAceJS'); + +tmp.setGracefulCleanup(); + +let outdir; +let tmpdir; +let reportPath; + +beforeEach(() => { + outdir = tmp.dirSync({ prefix: 'ace_out_', unsafeCleanup: true }); + tmpdir = tmp.dirSync({ prefix: 'ace_tmp_', unsafeCleanup: true }); + reportPath = path.join(outdir.name, 'ace.json'); +}); + +afterEach(() => { + outdir.removeCallback(); + tmpdir.removeCallback(); +}); + + +function ace(epub, options = {}) { + return runAce(path.join(__dirname, epub), Object.assign({ + outdir: outdir.name, + tmp: tmpdir.name, + }, options)) + .then(() => { + expect(fs.existsSync(reportPath)).toBeTruthy(); + return JSON.parse(fs.readFileSync(reportPath, 'utf8')); + }) + .catch(err => console.log(err)); +} + +test('`bypass` rule is disabled', async () => { + const report = await ace('../data/axerule-bypass'); + expect(report['earl:result']['earl:outcome']).toEqual('pass'); +}); diff --git a/tests/data/axerule-bypass/EPUB/content_001.xhtml b/tests/data/axerule-bypass/EPUB/content_001.xhtml new file mode 100644 index 00000000..6e5ed4ff --- /dev/null +++ b/tests/data/axerule-bypass/EPUB/content_001.xhtml @@ -0,0 +1,9 @@ + + +Minimal EPUB + + +link +

Call me Ishmael.

+ + diff --git a/tests/data/axerule-bypass/EPUB/nav.xhtml b/tests/data/axerule-bypass/EPUB/nav.xhtml new file mode 100644 index 00000000..1d538c19 --- /dev/null +++ b/tests/data/axerule-bypass/EPUB/nav.xhtml @@ -0,0 +1,12 @@ + + +Minimal Nav + + + + + diff --git a/tests/data/axerule-bypass/EPUB/package.opf b/tests/data/axerule-bypass/EPUB/package.opf new file mode 100644 index 00000000..8e218285 --- /dev/null +++ b/tests/data/axerule-bypass/EPUB/package.opf @@ -0,0 +1,16 @@ + + + + Minimal EPUB 3.0 + en + NOID + 2017-01-01T00:00:01Z + + + + + + + + + diff --git a/tests/data/axerule-bypass/META-INF/container.xml b/tests/data/axerule-bypass/META-INF/container.xml new file mode 100644 index 00000000..2cf00654 --- /dev/null +++ b/tests/data/axerule-bypass/META-INF/container.xml @@ -0,0 +1,6 @@ + + + + + + diff --git a/tests/data/axerule-bypass/mimetype b/tests/data/axerule-bypass/mimetype new file mode 100644 index 00000000..57ef03f2 --- /dev/null +++ b/tests/data/axerule-bypass/mimetype @@ -0,0 +1 @@ +application/epub+zip \ No newline at end of file