diff --git a/packages/ace-core/package.json b/packages/ace-core/package.json index 7a869fe8..7dcbc2c8 100644 --- a/packages/ace-core/package.json +++ b/packages/ace-core/package.json @@ -22,6 +22,7 @@ "@daisy/epub-utils": "^0.8.0", "@daisy/puppeteer-utils": "^0.7.0", "axe-core": "~2.6.1", + "file-url": "^2.0.2", "h5o": "^0.11.3", "p-map": "^1.2.0", "puppeteer": "^1.0.0", diff --git a/packages/ace-core/src/checker/checker-chromium.js b/packages/ace-core/src/checker/checker-chromium.js index 417f0e7b..baaa3383 100644 --- a/packages/ace-core/src/checker/checker-chromium.js +++ b/packages/ace-core/src/checker/checker-chromium.js @@ -1,15 +1,19 @@ 'use strict'; -const fs = require('fs'); +const fileUrl = require('file-url'); +const fs = require('fs-extra'); const path = require('path'); const pMap = require('p-map'); const puppeteer = require('puppeteer'); const os = require('os'); +const tmp = require('tmp'); const winston = require('winston'); const axe2ace = require('@daisy/ace-report-axe'); const utils = require('@daisy/puppeteer-utils'); +tmp.setGracefulCleanup(); + const scripts = [ path.resolve(require.resolve('axe-core'), '../axe.min.js'), require.resolve('../scripts/vendor/outliner.min.js'), @@ -21,8 +25,22 @@ const scripts = [ async function checkSingle(spineItem, epub, browser) { winston.verbose(`- Processing ${spineItem.relpath}`); try { + let url = spineItem.url; + let ext = path.extname(spineItem.filepath); + + // File extensions other than 'xhtml' or 'html' are not propertly loaded + // by puppeteer, so we copy the file to a new `.xhtml` temp file. + if (ext !== 'xhtml' && ext !== 'html') { + winston.warn(`Copying document with extension '${ext}' to a temporary '.xhtml' fileā¦`); + const tmpdir = tmp.dirSync({ unsafeCleanup: true }).name; + const tmpFile = path.join(tmpdir, `${path.basename(spineItem.filepath, ext)}.xhtml`) + fs.copySync(spineItem.filepath, tmpFile); + url = fileUrl(tmpFile); + winston.debug(`checking copied file at ${url}`) + } + const page = await browser.newPage(); - await page.goto(spineItem.url); + await page.goto(url); await utils.addScripts(scripts, page); const results = await page.evaluate(() => new Promise((resolve, reject) => { diff --git a/tests/__tests__/regression.test.js b/tests/__tests__/regression.test.js index 5e2dbc61..16acf060 100644 --- a/tests/__tests__/regression.test.js +++ b/tests/__tests__/regression.test.js @@ -65,3 +65,8 @@ test('issue #114: Description list item does not have a
Call me Ishmael.
+ + diff --git a/tests/data/issue-122/EPUB/content_002.ace b/tests/data/issue-122/EPUB/content_002.ace new file mode 100644 index 00000000..c55a9e8b --- /dev/null +++ b/tests/data/issue-122/EPUB/content_002.ace @@ -0,0 +1,9 @@ + + +Call me Ishmael.
+ + diff --git a/tests/data/issue-122/EPUB/nav.xhtml b/tests/data/issue-122/EPUB/nav.xhtml new file mode 100644 index 00000000..d233bae0 --- /dev/null +++ b/tests/data/issue-122/EPUB/nav.xhtml @@ -0,0 +1,13 @@ + + +