Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --no-sandbox argument to Puppeteer when metal-a11y is called with --ci-mode #17

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 14 additions & 6 deletions src/axe-driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,24 +91,32 @@ function sadPath(axeReport) {
* Returns the first available port starting from the given number
* @async
* @param {number} port
* @return {number} available port
* @return {Promise.<number>} available port
*/
async function getAvailablePort(port) {
const availablePort = await detect(port);
if (availablePort === port) return 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);
Expand All @@ -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();
Expand Down
11 changes: 7 additions & 4 deletions src/axe-runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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());

Expand All @@ -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));
}
20 changes: 17 additions & 3 deletions src/helpers/Driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
20 changes: 10 additions & 10 deletions src/helpers/Server.js
Original file line number Diff line number Diff line change
@@ -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!');

Expand All @@ -30,9 +30,9 @@ class Server {
}

/**
* Stops the server
* @return {Promise}
*/
* Stops the server
* @return {Promise}
*/
stop() {
return Promise.resolve().then(() => this.server.close());
}
Expand Down