From 94efb908b8eba880dd1ae3d50148a0315c38e75e Mon Sep 17 00:00:00 2001 From: Luca Greco Date: Tue, 9 Jan 2018 17:49:56 +0100 Subject: [PATCH] fix: Pass --no-sandbox chrome CLI option when running the integration tests on travis (#85) --- .travis.yml | 2 +- test/integration/setup.js | 23 +++++++++++++++++++ .../test-runtime-messaging-on-chrome.js | 15 ++++-------- 3 files changed, 28 insertions(+), 12 deletions(-) diff --git a/.travis.yml b/.travis.yml index 1992024..c088aac 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,7 +14,7 @@ script: - export DISPLAY=:99.0 - sh -e /etc/init.d/xvfb start - echo "RUN integration tests on chrome" && - ./test/run-chrome-smoketests.sh + TRAVIS_CI=true ./test/run-chrome-smoketests.sh after_script: npm run publish-coverage diff --git a/test/integration/setup.js b/test/integration/setup.js index a6de495..59934fd 100644 --- a/test/integration/setup.js +++ b/test/integration/setup.js @@ -1,6 +1,7 @@ const finalhandler = require("finalhandler"); const http = require("http"); const serveStatic = require("serve-static"); +const puppeteer = require("puppeteer"); exports.createHTTPServer = async (path) => { var serve = serveStatic(path); @@ -19,3 +20,25 @@ exports.createHTTPServer = async (path) => { }); }); }; + +exports.launchPuppeteer = async (puppeteerArgs) => { + if (!puppeteerArgs || !Array.isArray(puppeteerArgs)) { + throw new Error(`Invalid puppeteer arguments: ${JSON.stringify(puppeteerArgs)}`); + } + + const args = [].concat(puppeteerArgs); + + // Pass the --no-sandbox chrome CLI option when running the integration tests + // on Travis. + if (process.env.TRAVIS_CI) { + args.push("--no-sandbox"); + } + + return puppeteer.launch({ + // Chrome Extensions are not currently supported in headless mode. + headless: false, + + // Custom chrome arguments. + args, + }); +}; diff --git a/test/integration/test-runtime-messaging-on-chrome.js b/test/integration/test-runtime-messaging-on-chrome.js index a470de9..b5de93e 100644 --- a/test/integration/test-runtime-messaging-on-chrome.js +++ b/test/integration/test-runtime-messaging-on-chrome.js @@ -4,9 +4,8 @@ const path = require("path"); const waitUntil = require("async-wait-until"); const {deepEqual} = require("chai").assert; -const puppeteer = require("puppeteer"); -const {createHTTPServer} = require("./setup"); +const {createHTTPServer, launchPuppeteer} = require("./setup"); const fixtureExtensionDirName = "runtime-messaging-extension"; @@ -20,15 +19,9 @@ describe("browser.runtime.onMessage/sendMessage", function() { const url = `http://localhost:${server.address().port}`; - const browser = await puppeteer.launch({ - // Chrome Extensions are not currently supported in headless mode. - headless: false, - - // Custom chrome arguments. - args: [ - `--load-extension=${process.env.TEST_EXTENSIONS_PATH}/${fixtureExtensionDirName}`, - ], - }); + const browser = await launchPuppeteer([ + `--load-extension=${process.env.TEST_EXTENSIONS_PATH}/${fixtureExtensionDirName}`, + ]); const page = await browser.newPage();