diff --git a/packages/ace-axe-runner-electron/src/index.js b/packages/ace-axe-runner-electron/src/index.js index 71631710..bcbc7b95 100644 --- a/packages/ace-axe-runner-electron/src/index.js +++ b/packages/ace-axe-runner-electron/src/index.js @@ -3,9 +3,18 @@ const LOG_DEBUG = false; const ACE_LOG_PREFIX = "[ACE-AXE]"; +let cliOption_MILLISECONDS_TIMEOUT_EXTENSION = undefined; + function createAxeRunner(eventEmmitter, CONCURRENT_INSTANCES) { return { + setTimeout: function (ms) { + try { + cliOption_MILLISECONDS_TIMEOUT_EXTENSION = parseInt(ms, 10); + } catch(_e) { + // ignore + } + }, concurrency: CONCURRENT_INSTANCES, launch: function () { if (LOG_DEBUG) console.log(`${ACE_LOG_PREFIX} axeRunner will launch ...`); @@ -42,7 +51,7 @@ function createAxeRunner(eventEmmitter, CONCURRENT_INSTANCES) { }, close: function () { if (LOG_DEBUG) console.log(`${ACE_LOG_PREFIX} axeRunner will close ...`); - + // // ipcRenderer // eventEmmitter.send('AXE_RUNNER_CLOSE', {}); // return Promise.resolve(); @@ -79,7 +88,7 @@ function createAxeRunner(eventEmmitter, CONCURRENT_INSTANCES) { }, run: function (url, scripts, scriptContents, basedir) { if (LOG_DEBUG) console.log(`${ACE_LOG_PREFIX} axeRunner will run ... ${url}`); - + return new Promise((resolve, reject) => { // ipcRenderer const callback = (event, arg) => { @@ -110,10 +119,11 @@ function createAxeRunner(eventEmmitter, CONCURRENT_INSTANCES) { scripts, scriptContents, basedir, + cliOption_MILLISECONDS_TIMEOUT_EXTENSION, }); }); } }; } -module.exports = { createAxeRunner }; \ No newline at end of file +module.exports = { createAxeRunner }; diff --git a/packages/ace-axe-runner-electron/src/init.js b/packages/ace-axe-runner-electron/src/init.js index d62630dc..c3b4dd2e 100644 --- a/packages/ace-axe-runner-electron/src/init.js +++ b/packages/ace-axe-runner-electron/src/init.js @@ -39,6 +39,8 @@ const fsOriginal = require('original-fs'); const isDev = process && process.env && (process.env.NODE_ENV === 'development' || process.env.DEBUG_PROD === 'true'); const showWindow = false; +let cliOption_MILLISECONDS_TIMEOUT_EXTENSION = undefined; + const LOG_DEBUG_URLS = process.env.LOG_DEBUG_URLS === "1"; const LOG_DEBUG = false; @@ -242,8 +244,8 @@ function loadUrl(browserWindow) { } catch(_e) { // ignore } - const MILLISECONDS_TIMEOUT_INITIAL = _MILLISECONDS_TIMEOUT_INITIAL || 10000; // 10s check to load the browser window web contents + execute Axe checkers - const MILLISECONDS_TIMEOUT_EXTENSION = _MILLISECONDS_TIMEOUT_EXTENSION || 480000; // 480s (8mn) extension (window contents usually loads fast, but Axe runtime takes time...) + const MILLISECONDS_TIMEOUT_INITIAL = _MILLISECONDS_TIMEOUT_INITIAL || 5000; // 5s check to load the browser window web contents + execute Axe checkers + const MILLISECONDS_TIMEOUT_EXTENSION = cliOption_MILLISECONDS_TIMEOUT_EXTENSION || _MILLISECONDS_TIMEOUT_EXTENSION || 240000; // 240s (4mn) extension (window contents usually loads fast, but Axe runtime takes time...) const timeoutFunc = () => { if (browserWindow.ace__replySent) { @@ -572,6 +574,7 @@ function axeRunnerInit(eventEmmitter, CONCURRENT_INSTANCES) { const uarel = payload.url; const scripts = payload.scripts; const scriptContents = payload.scriptContents; + cliOption_MILLISECONDS_TIMEOUT_EXTENSION = payload.cliOption_MILLISECONDS_TIMEOUT_EXTENSION; if (LOG_DEBUG_URLS) { console.log("######## URL 1"); diff --git a/packages/ace-axe-runner-puppeteer/src/index.js b/packages/ace-axe-runner-puppeteer/src/index.js index 2c09d4a0..759d75bf 100644 --- a/packages/ace-axe-runner-puppeteer/src/index.js +++ b/packages/ace-axe-runner-puppeteer/src/index.js @@ -22,10 +22,19 @@ try { } catch(_e) { // ignore } -const MILLISECONDS_TIMEOUT_INITIAL = _MILLISECONDS_TIMEOUT_INITIAL || 10000; // 10s check to load the browser window web contents + execute Axe checkers -const MILLISECONDS_TIMEOUT_EXTENSION = _MILLISECONDS_TIMEOUT_EXTENSION || 480000; // 480s (8mn) extension (window contents usually loads fast, but Axe runtime takes time...) +const MILLISECONDS_TIMEOUT_INITIAL = _MILLISECONDS_TIMEOUT_INITIAL || 5000; // 5s check to load the browser window web contents +const MILLISECONDS_TIMEOUT_EXTENSION = _MILLISECONDS_TIMEOUT_EXTENSION || 240000; // 240s (4mn) runtime (window contents usually loads fast, but Axe runtime takes time...) + +let cliOption_MILLISECONDS_TIMEOUT_EXTENSION = undefined; module.exports = { + setTimeout: function (ms) { + try { + cliOption_MILLISECONDS_TIMEOUT_EXTENSION = parseInt(ms, 10); + } catch(_e) { + // ignore + } + }, concurrency: 4, launch: async function() { const args = []; @@ -41,7 +50,7 @@ module.exports = { args, headless: true, timeout: MILLISECONDS_TIMEOUT_INITIAL, // 30000 default - protocolTimeout: MILLISECONDS_TIMEOUT_EXTENSION, // 180000 default + protocolTimeout: cliOption_MILLISECONDS_TIMEOUT_EXTENSION || MILLISECONDS_TIMEOUT_EXTENSION, // 180000 default }); return Promise.resolve(); }, @@ -157,7 +166,7 @@ module.exports = { } catch (err) { // ProtocolError: Runtime.callFunctionOn timed out. Increase the 'protocolTimeout' setting in launch/connect calls for a higher timeout if needed. if (err && err.toString && err.toString().indexOf("protocolTimeout") >= 0) { - err = new Error(`Timeout :( ${MILLISECONDS_TIMEOUT_EXTENSION}ms`); + err = new Error(`Timeout :( ${cliOption_MILLISECONDS_TIMEOUT_EXTENSION || MILLISECONDS_TIMEOUT_EXTENSION}ms`); } try { await page.close(); diff --git a/packages/ace-cli-shared/src/index.js b/packages/ace-cli-shared/src/index.js index c121895e..38625d37 100755 --- a/packages/ace-cli-shared/src/index.js +++ b/packages/ace-cli-shared/src/index.js @@ -33,6 +33,8 @@ const meowHelpMessage = ` -s, --silent do not display any output -l, --lang language code for localized messages (e.g. "fr"), default is "en" + + -T, --timeout (default is 240000 per document) Examples $ ace -o out ~/Documents/book.epub @@ -76,6 +78,10 @@ const meowOptions = { lang: { alias: 'l', type: 'string' + }, + timeout: { + alias: 'T', + type: 'string' } } }; @@ -149,6 +155,7 @@ ${overrides.map(file => ` - ${file}`).join('\n')} silent: cli.flags.silent, jobId: '', lang: cli.flags.lang, + timeout: cli.flags.timeout || undefined, }, axeRunner) .then(async (jobData) => { var reportJson = jobData[1]; diff --git a/packages/ace-core/src/core/ace.js b/packages/ace-core/src/core/ace.js index e1b1a2d3..2f3eaeaa 100644 --- a/packages/ace-core/src/core/ace.js +++ b/packages/ace-core/src/core/ace.js @@ -18,6 +18,8 @@ tmp.setGracefulCleanup(); module.exports = function ace(epubPath, options, axeRunner) { + if (options.timeout) axeRunner.setTimeout(options.timeout); + return new Promise((resolve, reject) => { function l10nDoneCallback() { @@ -25,20 +27,20 @@ module.exports = function ace(epubPath, options, axeRunner) { if (options.initLogger) { logger.initLogger({ verbose: options.verbose, silent: options.silent, fileName: options.fileName }); } - + // the jobid option just gets returned in the resolve/reject // so the calling function can track which job finished var jobId = 'jobid' in options ? options.jobid : ''; winston.verbose(`Ace ${pkg.version}, Node ${process.version}, ${os.type()} ${os.release()}`); winston.verbose("Options:", options); - + // Check that the EPUB exists const epubPathResolved = path.resolve(options.cwd, epubPath); if (!fs.existsSync(epubPathResolved)) { winston.error(`Couldn’t find EPUB file '${epubPath}'`); return reject(jobId); } - + // Process options /* eslint-disable no-param-reassign */ if (typeof options.tmpdir === 'string') { @@ -57,11 +59,11 @@ module.exports = function ace(epubPath, options, axeRunner) { } else { delete options.outdir; } - + winston.info("Processing " + epubPath); - + /* eslint-enable no-param-reassign */ - + // Unzip the EPUB const epub = new EPUB(epubPathResolved); epub.extract() diff --git a/packages/ace-http/src/index.js b/packages/ace-http/src/index.js index edbc39dd..9360b9c2 100644 --- a/packages/ace-http/src/index.js +++ b/packages/ace-http/src/index.js @@ -42,6 +42,8 @@ const meowHelpMessage = ` -s, --silent do not display any output -l, --lang language code for localized messages (e.g. "fr"), default is "en" + + -T, --timeout (default is 240000 per document) Examples $ ace-http -p 3000`; const meowOptions = { @@ -151,6 +153,7 @@ function postJob(req, res, next) { "outputDir": tmp.dirSync({ unsafeCleanup: true }).name, "epubPath": req.file.path, "lang": cli.flags.lang, + "timeout": cli.flags.timeout || undefined, } }; newJob(jobdata); @@ -189,7 +192,7 @@ function newJob(jobdata) { joblist.push(jobdata); // execute the job with Ace - ace(jobdata.internal.epubPath, {'jobid': jobdata.internal.id, 'outdir': jobdata.internal.outputDir, 'lang': jobdata.internal.lang}, axeRunner) + ace(jobdata.internal.epubPath, {'jobid': jobdata.internal.id, 'outdir': jobdata.internal.outputDir, 'lang': jobdata.internal.lang, 'timeout': jobdata.internal.timeout}, axeRunner) .then((jobData) => { var jobId = jobData[0]; var idx = joblist.findIndex(job => job.internal.id === jobId); diff --git a/scripts/compareAxeRunners.sh b/scripts/compareAxeRunners.sh index 45e7c669..594d582b 100755 --- a/scripts/compareAxeRunners.sh +++ b/scripts/compareAxeRunners.sh @@ -7,15 +7,19 @@ echo "ElectronAxeRunner ..." #node ./packages/ace-axe-runner-electron/bin/ace.js #node ./packages/ace/bin/ace-electron.js -# defaults: ACE_TIMEOUT_INITIAL=10000 ACE_TIMEOUT_EXTENSION=480000 -# ACE_TIMEOUT_INITIAL=4000 ACE_TIMEOUT_EXTENSION=150000 -ACE_PERF=1 node ./packages/ace/bin/ace-electron.js -f -s -o ./CompareAxeRunners/ElectronAxeRunner "$1" +# defaults: ACE_TIMEOUT_INITIAL=5000 ACE_TIMEOUT_EXTENSION=240000 +# ACE_TIMEOUT_INITIAL ==> load and Axe +# ACE_TIMEOUT_EXTENSION ==> Axe... +# -T/--timeout 100 means 100 milliseconds over the initial 5 seconds for Axe to do its job +ACE_PERF=1 node ./packages/ace/bin/ace-electron.js -T 100 -l en -f -s -o ./CompareAxeRunners/ElectronAxeRunner "$1" echo "PuppeteerAxeRunner ..." -# defaults: ACE_TIMEOUT_INITIAL=10000 ACE_TIMEOUT_EXTENSION=480000 -# ACE_TIMEOUT_INITIAL=4000 ACE_TIMEOUT_EXTENSION=150000 -ACE_PERF=1 node ./packages/ace-cli/bin/ace.js -f -s -o ./CompareAxeRunners/PuppeteerAxeRunner "$1" +# defaults: ACE_TIMEOUT_INITIAL=5000 ACE_TIMEOUT_EXTENSION=240000 +# ACE_TIMEOUT_INITIAL ==> load +# ACE_TIMEOUT_EXTENSION ==> Axe... +# -T/--timeout 5100 means 5 seconds and 100 milliseconds for Axe to do its job +ACE_PERF=1 node ./packages/ace-cli/bin/ace.js -T 5100 -l en -f -s -o ./CompareAxeRunners/PuppeteerAxeRunner "$1" node ./scripts/normalise_report_json.js ./CompareAxeRunners/PuppeteerAxeRunner/report.json node ./scripts/normalise_report_json.js ./CompareAxeRunners/ElectronAxeRunner/report.json diff --git a/scripts/compareAxeRunners_VERBOSE.sh b/scripts/compareAxeRunners_VERBOSE.sh index 4b3957b8..ad818810 100755 --- a/scripts/compareAxeRunners_VERBOSE.sh +++ b/scripts/compareAxeRunners_VERBOSE.sh @@ -7,15 +7,19 @@ echo "ElectronAxeRunner ..." #node ./packages/ace-axe-runner-electron/bin/ace.js #node ./packages/ace/bin/ace-electron.js -# defaults: ACE_TIMEOUT_INITIAL=10000 ACE_TIMEOUT_EXTENSION=480000 -# ACE_TIMEOUT_INITIAL=4000 ACE_TIMEOUT_EXTENSION=150000 -ACE_PERF=1 node ./packages/ace/bin/ace-electron.js -l en -f -V -o ./CompareAxeRunners/ElectronAxeRunner "$1" +# defaults: ACE_TIMEOUT_INITIAL=5000 ACE_TIMEOUT_EXTENSION=240000 +# ACE_TIMEOUT_INITIAL ==> load and Axe +# ACE_TIMEOUT_EXTENSION ==> Axe... +# -T/--timeout 100 means 100 milliseconds over the initial 5 seconds for Axe to do its job +ACE_PERF=1 node ./packages/ace/bin/ace-electron.js -T 100 -l en -f -V -o ./CompareAxeRunners/ElectronAxeRunner "$1" echo "PuppeteerAxeRunner ..." -# defaults: ACE_TIMEOUT_INITIAL=10000 ACE_TIMEOUT_EXTENSION=480000 -# ACE_TIMEOUT_INITIAL=4000 ACE_TIMEOUT_EXTENSION=150000 -ACE_PERF=1 node ./packages/ace-cli/bin/ace.js -l en -f -V -o ./CompareAxeRunners/PuppeteerAxeRunner "$1" +# defaults: ACE_TIMEOUT_INITIAL=5000 ACE_TIMEOUT_EXTENSION=240000 +# ACE_TIMEOUT_INITIAL ==> load +# ACE_TIMEOUT_EXTENSION ==> Axe... +# -T/--timeout 5100 means 5 seconds and 100 milliseconds for Axe to do its job +ACE_PERF=1 node ./packages/ace-cli/bin/ace.js -T 5100 -l en -f -V -o ./CompareAxeRunners/PuppeteerAxeRunner "$1" node ./scripts/normalise_report_json.js ./CompareAxeRunners/PuppeteerAxeRunner/report.json node ./scripts/normalise_report_json.js ./CompareAxeRunners/ElectronAxeRunner/report.json diff --git a/tests/__tests__/__snapshots__/cli.test.js.snap b/tests/__tests__/__snapshots__/cli.test.js.snap index 506d584f..43159370 100644 --- a/tests/__tests__/__snapshots__/cli.test.js.snap +++ b/tests/__tests__/__snapshots__/cli.test.js.snap @@ -46,6 +46,8 @@ exports[`Running the CLI with no input should fail 2`] = ` -s, --silent do not display any output -l, --lang language code for localized messages (e.g. \"fr\"), default is \"en\" + + -T, --timeout (default is 240000 per document) Examples $ ace -o out ~/Documents/book.epub @@ -75,6 +77,8 @@ exports[`Running the CLI with the -h option should print help 1`] = ` -s, --silent do not display any output -l, --lang language code for localized messages (e.g. \"fr\"), default is \"en\" + + -T, --timeout (default is 240000 per document) Examples $ ace -o out ~/Documents/book.epub diff --git a/website/content/docs/cli.md b/website/content/docs/cli.md index 1ef60fe5..29817146 100644 --- a/website/content/docs/cli.md +++ b/website/content/docs/cli.md @@ -74,6 +74,8 @@ Ace by DAISY, an Accessibility Checker for EPUB -s, --silent do not display any output -l, --lang language code for localized messages (e.g. "fr"), default is "en" + + -T, --timeout (default is 240000 per document) Examples $ ace -o out ~/Documents/book.epub diff --git a/website/content/docs/http-api.md b/website/content/docs/http-api.md index 4c2f5d6e..e59d0ef6 100644 --- a/website/content/docs/http-api.md +++ b/website/content/docs/http-api.md @@ -30,6 +30,8 @@ Ace by DAISY, an Accessibility Checker for EPUB -s, --silent do not display any output -l, --lang language code for localized messages (e.g. "fr"), default is "en" + + -T, --timeout (default is 240000 per document) Examples $ ace-http -p 3000 ```