From 91460b59f4f3dbace3e595c11359d3ab12f50895 Mon Sep 17 00:00:00 2001 From: Jeremy Karlsson Date: Thu, 19 Apr 2018 13:21:03 +0200 Subject: [PATCH 1/5] add ci mode --- package.json | 2 +- src/axe-driver.js | 20 ++++++++++++++------ src/axe-runner.js | 11 +++++++---- src/helpers/Driver.js | 20 +++++++++++++++++--- 4 files changed, 39 insertions(+), 14 deletions(-) diff --git a/package.json b/package.json index e1a59a6..9c65252 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "metal-a11y-checker", + "name": "@enjikaka/metal-a11y-checker", "version": "1.0.5", "description": "Accessibility test module for components", "main": "index.js", diff --git a/src/axe-driver.js b/src/axe-driver.js index 0868547..1905970 100644 --- a/src/axe-driver.js +++ b/src/axe-driver.js @@ -91,7 +91,7 @@ function sadPath(axeReport) { * Returns the first available port starting from the given number * @async * @param {number} port - * @return {number} available port + * @return {Promise.} available port */ async function getAvailablePort(port) { const availablePort = await detect(port); @@ -99,16 +99,24 @@ async function getAvailablePort(port) { return getAvailablePort(availablePort); } +/** + * @typedef ExecOptions + * @prop {string} indexHtml - used to specifiy the demo page of the component + * @prop {string} serverPath - document root + * @prop {boolean} [verbose] + * @prop {boolean} ciMode + */ + /** * Executes the test against the given url that is hosted at the * specified document root. * @async - * @param {string} indexHtml - used to specifiy the demo page of the component - * @param {string} serverPath - document root - * @param {boolean} verbose + * @param {ExecOptions} options * @return {Promise} */ -async function exec({indexHtml, serverPath, verbose}) { +async function exec(options) { + const {indexHtml, serverPath, verbose, ciMode} = options; + if (!verbose) console.log = () => {}; const port = await getAvailablePort(SERVER_PORT); @@ -120,7 +128,7 @@ async function exec({indexHtml, serverPath, verbose}) { driver.on('exit', server.stop); const url = `http://localhost:${serverConfig.port}/${indexHtml}`; - const page = await driver.connect(url); + const page = await driver.connect(url, {ciMode}); const report = await executeAxe(page); await driver.exit(); diff --git a/src/axe-runner.js b/src/axe-runner.js index eee6292..5f0f4cc 100644 --- a/src/axe-runner.js +++ b/src/axe-runner.js @@ -102,6 +102,8 @@ function traverseObj(obj, callback) { Object.keys(obj).forEach(key => callback(obj[key], key)); } +const ciMode = Boolean(argv['ci-mode']); + if (argv['packages']) { const packagesDir = argv['packages'] || 'packages'; const packagesPath = path.join(path.resolve(appDirectory), packagesDir); @@ -110,9 +112,10 @@ if (argv['packages']) { dl.list(`${packagesPath}/`, true, list => { const loop = list.reduce((promise, dir) => { return promise - .then(() => - exec({indexHtml, serverPath: path.join(packagesPath, dir)}) - ) + .then(() => { + const serverPath = path.join(packagesPath, dir); + exec({indexHtml, serverPath, ciMode}); + }) .then(report => (reports[dir] = report)); }, Promise.resolve()); @@ -122,7 +125,7 @@ if (argv['packages']) { .catch(ex => processException(ex)); }); } else { - exec({indexHtml, serverPath}) + exec({indexHtml, serverPath, ciMode}) .then(report => (decorate(report), processReport(report))) .catch(ex => processException(ex)); } diff --git a/src/helpers/Driver.js b/src/helpers/Driver.js index 4b36893..4d754c1 100644 --- a/src/helpers/Driver.js +++ b/src/helpers/Driver.js @@ -14,16 +14,30 @@ class Driver { this.browser = null; } + /** + * @typedef ConnectOptions + * @prop {boolean} ciMode + */ + /** * Creates a Puppeteer instance and connects to the given address * @param {string} address + * @param {ConnectOptions} options * @return {Promise} */ - async connect(address) { - this.browser = await puppeteer.launch(); + async connect(address, options) { + const {ciMode} = options; + const launchOptions = ciMode + ? { + args: ['--no-sandbox'], + } + : {}; + this.browser = await puppeteer.launch(launchOptions); const page = await this.browser.newPage(); await page.goto(address, {waitUntil: 'load'}); - console.log(`Connected to ${address}`); + console.log( + `Connected to ${address}${ciMode ? ', using --no-sandbox' : ''}` + ); this.emitter.emit('connect'); return page; } From 63b5681419c523fe97c175cf55e43b48ead7514a Mon Sep 17 00:00:00 2001 From: Jeremy Karlsson Date: Thu, 19 Apr 2018 13:21:15 +0200 Subject: [PATCH 2/5] what --- src/helpers/Server.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/helpers/Server.js b/src/helpers/Server.js index 898757a..abcca56 100644 --- a/src/helpers/Server.js +++ b/src/helpers/Server.js @@ -1,17 +1,17 @@ import {Promise} from 'es6-promise'; import express from 'express'; -/** +/** * Wrapper around setting up an express server with static middleware */ class Server { /** - * Starts the express server - * @param {number} port - * @param {string} dir - * @return {Promise} - * @throw {Error} - */ + * Starts the express server + * @param {number} port + * @param {string} dir + * @return {Promise} + * @throw {Error} + */ start(port, dir) { if (this.app) throw new Error('Server is already running!'); @@ -30,9 +30,9 @@ class Server { } /** - * Stops the server - * @return {Promise} - */ + * Stops the server + * @return {Promise} + */ stop() { return Promise.resolve().then(() => this.server.close()); } From 94c458ea3b2ab277a4eccace61fb2ddcb11075c8 Mon Sep 17 00:00:00 2001 From: Jeremy Karlsson Date: Thu, 19 Apr 2018 13:21:26 +0200 Subject: [PATCH 3/5] 1.0.6 --- package-lock.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index a0feece..83f0daf 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "metal-a11y-checker", - "version": "1.0.3", + "version": "1.0.6", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 9c65252..8f9a285 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@enjikaka/metal-a11y-checker", - "version": "1.0.5", + "version": "1.0.6", "description": "Accessibility test module for components", "main": "index.js", "bin": { From 686a54d58a34ef387f8182ed537cebd38d8e3c34 Mon Sep 17 00:00:00 2001 From: Jeremy Karlsson Date: Thu, 19 Apr 2018 13:22:49 +0200 Subject: [PATCH 4/5] Change name --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 8f9a285..0d8a027 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "@enjikaka/metal-a11y-checker", + "name": "karlsson-metal-a11y-checker", "version": "1.0.6", "description": "Accessibility test module for components", "main": "index.js", From 1880c7be6fa2f2524e7b2c56c462e13df2b467fe Mon Sep 17 00:00:00 2001 From: Jeremy Karlsson Date: Thu, 19 Apr 2018 14:46:50 +0200 Subject: [PATCH 5/5] Revert naming and version changes --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 0d8a027..e1a59a6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { - "name": "karlsson-metal-a11y-checker", - "version": "1.0.6", + "name": "metal-a11y-checker", + "version": "1.0.5", "description": "Accessibility test module for components", "main": "index.js", "bin": {