From 4357a2f795ead4760d9ee5bb4cbe775b03b80b7b Mon Sep 17 00:00:00 2001 From: Chris Andrejewski Date: Sat, 29 Jul 2017 17:31:57 -0400 Subject: [PATCH 01/21] Add Chrome Headless support --- lib/local/chrome.js | 21 +++++++++++++++++++++ lib/local/index.js | 38 +++++++++++++++++++++++++++++++++++++- package.json | 1 + test/local.js | 43 +++++++++++++++++++++++++++++++++++++++---- 4 files changed, 98 insertions(+), 5 deletions(-) create mode 100644 lib/local/chrome.js diff --git a/lib/local/chrome.js b/lib/local/chrome.js new file mode 100644 index 0000000..fe04c9f --- /dev/null +++ b/lib/local/chrome.js @@ -0,0 +1,21 @@ +var chromeLauncher = require('chrome-launcher'); + +function chromeWithFlags (flags) { + return function startChrome (url) { + return chromeLauncher + .launch({ + startingUrl: url, + flags: flags + }) + .then(function (chrome) { + return function stopChrome () { + return chrome.kill(); + }; + }); + }; +} + +module.exports = { + chromeHeadfull: chromeWithFlags([]), + chromeHeadless: chromeWithFlags(['--headless', '--disable-gpu']) +}; diff --git a/lib/local/index.js b/lib/local/index.js index 33826cc..1913011 100644 --- a/lib/local/index.js +++ b/lib/local/index.js @@ -2,6 +2,7 @@ var _ = require('underscore'); var Q = require('q'); var debug = require('debug')('launchpad:local'); +var chrome = require('./chrome'); var instance = require('./instance'); var getBrowser = require('./browser'); var getVersion = require('./version'); @@ -28,6 +29,13 @@ module.exports = function (settings, callback) { var api = function(url, options, callback) { var name = options.browser; + if (name === 'chromeHeadfull') { + return api.chromeHeadfull(url, options, callback); + } + if (name === 'chromeHeadless') { + return api.chromeHeadless(url, options, callback); + } + debug('Launching browser', url, options); getBrowser(_.extend({ name: name }, platform[name])).then(function(browser) { if(browser === null) { @@ -42,7 +50,7 @@ module.exports = function (settings, callback) { if(options.args) { args = args.concat(options.args); } - + // Convert the command if set (some browsers need some customization) if(browser.getCommand) { browser.command = browser.getCommand(browser, url, args, options); @@ -80,7 +88,35 @@ module.exports = function (settings, callback) { }; }); + api.chromeHeadfull = instafy(chrome.chromeHeadfull); + api.chromeHeadless = instafy(chrome.chromeHeadless); + callback(null, api); }; +function instafy (promiseLauncher) { + return function _instafy (url, options, callback) { + if (!callback) { + callback = options; + options = {}; + } + + nodeify(promiseLauncher(url, options), function (error, stop) { + if (error) return callback(error); + + var instanceStop = function (callback) { + nodeify(stop(), callback); + }; + + callback(null, {stop: instanceStop}); + }); + }; +} + +function nodeify (promise, callback) { + promise + .then(function (stop) {callback(null, stop);}) + .catch(function (error) {callback(error);}); +} + module.exports.platform = platform; diff --git a/package.json b/package.json index 3cbf861..905d062 100644 --- a/package.json +++ b/package.json @@ -53,6 +53,7 @@ "dependencies": { "async": "^2.0.1", "browserstack": "^1.2.0", + "chrome-launcher": "^0.3.2", "debug": "^2.2.0", "plist": "^2.0.1", "q": "^1.4.1", diff --git a/test/local.js b/test/local.js index f8a4436..100d360 100644 --- a/test/local.js +++ b/test/local.js @@ -5,6 +5,7 @@ var decache = require('decache'); var useragent = require('useragent'); var familyMapping = { canary: 'chrome', + electron: 'chrome', chromium: process.platform === 'darwin' ? 'chrome' : 'chromium', phantom: 'phantomjs', nodeWebkit: 'chrome' @@ -16,10 +17,8 @@ var server = http.createServer(function (req, res) { describe('Local browser launcher tests', function() { + var local = require('../lib/local'); describe('Default env settings', function () { - - var local = require('../lib/local'); - it('does local browser and version discovery', function (done) { local(function (error, launcher) { launcher.browsers(function (error, browsers) { @@ -32,7 +31,7 @@ describe('Local browser launcher tests', function() { }); }); }); - + Object.keys(local.platform).forEach(function (name) { it('Launches ' + name + ' browser on ' + process.platform, function (done) { local(function (error, launcher) { @@ -56,6 +55,42 @@ describe('Local browser launcher tests', function() { }); }); + describe('Supported Chrome Launcher', function () { + var url = 'http://localhost:6785'; + + it('should launch Chrome', function (done) { + local(function (error, launcher) { + if (error) return done(error); + + launcher.chromeHeadfull(url, function (error, instance) { + if (error) return done(error); + + server.once('request', function (req) { + var userAgent = useragent.parse(req.headers['user-agent']); + assert.equal(userAgent.family.toLowerCase(), 'chrome', 'Should be Chrome useragent'); + instance.stop(done); + }); + }); + }); + }); + + it('should launch Headless Chrome', function (done) { + local(function (error, launcher) { + if (error) return done(error); + + launcher.chromeHeadless(url, function (error, instance) { + if (error) return done(error); + + server.once('request', function (req) { + var userAgent = useragent.parse(req.headers['user-agent']); + assert.equal(userAgent.family.toLowerCase(), 'chrome', 'Should be Chrome useragent'); + instance.stop(done); + }); + }); + }); + }); + }); + describe('Custom env settings', function () { var node_modules = path.join(__dirname, '..', 'node_modules'); From 133115446f70d9aa9c3c85241acbdb9790ba9945 Mon Sep 17 00:00:00 2001 From: Chris Andrejewski Date: Sat, 29 Jul 2017 17:52:33 -0400 Subject: [PATCH 02/21] Give me some debug help --- test/local.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/test/local.js b/test/local.js index 100d360..56b0f89 100644 --- a/test/local.js +++ b/test/local.js @@ -32,7 +32,11 @@ describe('Local browser launcher tests', function() { }); }); - Object.keys(local.platform).forEach(function (name) { + var browsers = Object.keys(local.platform); + + console.log('Launch schedule:', browsers); + + browsers.forEach(function (name) { it('Launches ' + name + ' browser on ' + process.platform, function (done) { local(function (error, launcher) { launcher[name]('http://localhost:6785', function (error, instance) { @@ -46,7 +50,8 @@ describe('Local browser launcher tests', function() { var userAgent = useragent.parse(req.headers['user-agent']); var expected = familyMapping[name] || name; - assert.equal(userAgent.family.toLowerCase(), expected, 'Got expected browser family'); + console.log({name: name, family: userAgent.family}); + assert.equal(userAgent.family.toLowerCase(), expected, 'User agent family should match browser family'); instance.stop(done); }); }); From 4decaa44287aa7f85bc0a126485402e4a7ff58d1 Mon Sep 17 00:00:00 2001 From: Chris Andrejewski Date: Sat, 29 Jul 2017 17:57:15 -0400 Subject: [PATCH 03/21] Remove unneed Electron fix --- test/local.js | 1 - 1 file changed, 1 deletion(-) diff --git a/test/local.js b/test/local.js index 56b0f89..2878c21 100644 --- a/test/local.js +++ b/test/local.js @@ -5,7 +5,6 @@ var decache = require('decache'); var useragent = require('useragent'); var familyMapping = { canary: 'chrome', - electron: 'chrome', chromium: process.platform === 'darwin' ? 'chrome' : 'chromium', phantom: 'phantomjs', nodeWebkit: 'chrome' From cfe5dc8cec34763927aa086e0ceafd54bac7178a Mon Sep 17 00:00:00 2001 From: Chris Andrejewski Date: Sat, 29 Jul 2017 18:14:21 -0400 Subject: [PATCH 04/21] Install Chrome on Trusty --- .travis.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.travis.yml b/.travis.yml index fc80815..c9d2de8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,4 @@ +dist: trusty sudo: true language: node_js before_install: @@ -11,3 +12,5 @@ os: node_js: - 4 - node +addons: + chrome: stable From 6ce4c80b9d7c61515014bf6ec54f346bf2549bf8 Mon Sep 17 00:00:00 2001 From: Chris Andrejewski Date: Sat, 29 Jul 2017 18:56:04 -0400 Subject: [PATCH 05/21] Add Firefox now? --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index c9d2de8..34e42de 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,3 +14,4 @@ node_js: - node addons: chrome: stable + firefox: "51.0" From a146ed26aa9c9c4a9cf674f6903abfc9944a4358 Mon Sep 17 00:00:00 2001 From: Chris Andrejewski Date: Sat, 29 Jul 2017 19:20:12 -0400 Subject: [PATCH 06/21] Skip Firefox --- test/local.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/local.js b/test/local.js index 2878c21..521c69a 100644 --- a/test/local.js +++ b/test/local.js @@ -36,6 +36,10 @@ describe('Local browser launcher tests', function() { console.log('Launch schedule:', browsers); browsers.forEach(function (name) { + if (name === 'firefox') { + return; + } + it('Launches ' + name + ' browser on ' + process.platform, function (done) { local(function (error, launcher) { launcher[name]('http://localhost:6785', function (error, instance) { From f038240271e0c98d715fb3410b74126f762c85a1 Mon Sep 17 00:00:00 2001 From: Chris Andrejewski Date: Sat, 29 Jul 2017 19:38:54 -0400 Subject: [PATCH 07/21] Skip Firefox for now --- test/local.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/local.js b/test/local.js index 521c69a..7d8b6b3 100644 --- a/test/local.js +++ b/test/local.js @@ -36,11 +36,14 @@ describe('Local browser launcher tests', function() { console.log('Launch schedule:', browsers); browsers.forEach(function (name) { + var testTitle = 'Should launch ' + name + ' browser on ' + process.platform; + if (name === 'firefox') { + it.skip(testTitle); return; } - it('Launches ' + name + ' browser on ' + process.platform, function (done) { + it(testTitle, function (done) { local(function (error, launcher) { launcher[name]('http://localhost:6785', function (error, instance) { if (error) { From 745bf5f43eef0512928df2041a4506a46b0250d4 Mon Sep 17 00:00:00 2001 From: Chris Andrejewski Date: Sat, 29 Jul 2017 20:32:10 -0400 Subject: [PATCH 08/21] Use an ES3 version on chrome-launcher --- lib/local/chrome.js | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/local/chrome.js b/lib/local/chrome.js index fe04c9f..90b1c88 100644 --- a/lib/local/chrome.js +++ b/lib/local/chrome.js @@ -1,4 +1,4 @@ -var chromeLauncher = require('chrome-launcher'); +var chromeLauncher = require('chrome-launcher-4'); function chromeWithFlags (flags) { return function startChrome (url) { diff --git a/package.json b/package.json index 905d062..848f796 100644 --- a/package.json +++ b/package.json @@ -53,7 +53,7 @@ "dependencies": { "async": "^2.0.1", "browserstack": "^1.2.0", - "chrome-launcher": "^0.3.2", + "chrome-launcher-4": "0.0.1", "debug": "^2.2.0", "plist": "^2.0.1", "q": "^1.4.1", From c44bd2f4b83c704abd4e16c60d1862d8ffe00c00 Mon Sep 17 00:00:00 2001 From: Chris Andrejewski Date: Sat, 29 Jul 2017 20:51:50 -0400 Subject: [PATCH 09/21] Use ES3 chrome-launcher-4 for real --- package.json | 2 +- test/local.js | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/package.json b/package.json index 848f796..db8c489 100644 --- a/package.json +++ b/package.json @@ -53,7 +53,7 @@ "dependencies": { "async": "^2.0.1", "browserstack": "^1.2.0", - "chrome-launcher-4": "0.0.1", + "chrome-launcher-4": "0.0.2", "debug": "^2.2.0", "plist": "^2.0.1", "q": "^1.4.1", diff --git a/test/local.js b/test/local.js index 7d8b6b3..baa1644 100644 --- a/test/local.js +++ b/test/local.js @@ -32,9 +32,6 @@ describe('Local browser launcher tests', function() { }); var browsers = Object.keys(local.platform); - - console.log('Launch schedule:', browsers); - browsers.forEach(function (name) { var testTitle = 'Should launch ' + name + ' browser on ' + process.platform; @@ -56,7 +53,6 @@ describe('Local browser launcher tests', function() { var userAgent = useragent.parse(req.headers['user-agent']); var expected = familyMapping[name] || name; - console.log({name: name, family: userAgent.family}); assert.equal(userAgent.family.toLowerCase(), expected, 'User agent family should match browser family'); instance.stop(done); }); From f44f6317df74e5e5a9cb1d89e847776087267465 Mon Sep 17 00:00:00 2001 From: Chris Andrejewski Date: Sun, 30 Jul 2017 13:37:32 -0400 Subject: [PATCH 10/21] Try Firefox ESR --- .travis.yml | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 34e42de..4b8891a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,5 @@ dist: trusty -sudo: true +sudo: false language: node_js before_install: - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo apt-get update; fi @@ -14,4 +14,4 @@ node_js: - node addons: chrome: stable - firefox: "51.0" + firefox: "52.2.1" diff --git a/package.json b/package.json index db8c489..fbf7f02 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ "node": ">= 4" }, "scripts": { - "test": "xvfb-maybe grunt test --stack", + "test": "DEBUG=launchpad:* xvfb-maybe grunt test --stack", "publish": "git push origin && git push origin --tags", "release:major": "npm version major && npm publish", "release:minor": "npm version minor && npm publish", From e86c46425bba67a84be3f7ecd4354d48972a24cb Mon Sep 17 00:00:00 2001 From: Chris Andrejewski Date: Sun, 30 Jul 2017 13:39:33 -0400 Subject: [PATCH 11/21] Needs sudo --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 4b8891a..55a851c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,5 @@ dist: trusty -sudo: false +sudo: required language: node_js before_install: - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo apt-get update; fi From dc93c1c353639b4b2aa62c173cb6e21d4619fb2b Mon Sep 17 00:00:00 2001 From: Chris Andrejewski Date: Sun, 30 Jul 2017 13:43:18 -0400 Subject: [PATCH 12/21] Add Firefox test back --- test/local.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/test/local.js b/test/local.js index baa1644..9443a22 100644 --- a/test/local.js +++ b/test/local.js @@ -35,11 +35,6 @@ describe('Local browser launcher tests', function() { browsers.forEach(function (name) { var testTitle = 'Should launch ' + name + ' browser on ' + process.platform; - if (name === 'firefox') { - it.skip(testTitle); - return; - } - it(testTitle, function (done) { local(function (error, launcher) { launcher[name]('http://localhost:6785', function (error, instance) { From 96d3b64966305c6583c2d4bd0cf295b0aeb25dc6 Mon Sep 17 00:00:00 2001 From: Chris Andrejewski Date: Sun, 30 Jul 2017 13:59:09 -0400 Subject: [PATCH 13/21] xvfb fun --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 55a851c..3ed1bb9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,7 @@ dist: trusty sudo: required language: node_js before_install: + - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then export DISPLAY=:99.0 && sh -e /etc/init.d/xvfb start; fi - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo apt-get update; fi - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo apt-get install chromium-browser; fi - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew update; fi @@ -14,4 +15,3 @@ node_js: - node addons: chrome: stable - firefox: "52.2.1" From 1826ccc8c7f472e0dd77c9ed2f092a741216daed Mon Sep 17 00:00:00 2001 From: Chris Andrejewski Date: Sun, 30 Jul 2017 14:11:04 -0400 Subject: [PATCH 14/21] Firefox 51 bay bee --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 3ed1bb9..8ebb779 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,3 +15,4 @@ node_js: - node addons: chrome: stable + firefox: "51.0" From 335f46009f31295da579982a4fda7b5820643513 Mon Sep 17 00:00:00 2001 From: Chris Andrejewski Date: Sun, 30 Jul 2017 14:22:06 -0400 Subject: [PATCH 15/21] Back to precise --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 8ebb779..f1d207a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,4 @@ -dist: trusty +dist: precise sudo: required language: node_js before_install: From 44b62ce39ce923cc60f7a3cfb1e2d99048eab1f2 Mon Sep 17 00:00:00 2001 From: Chris Andrejewski Date: Sun, 30 Jul 2017 14:26:12 -0400 Subject: [PATCH 16/21] Minimum travis changes --- .travis.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index f1d207a..99ec780 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,6 @@ -dist: precise -sudo: required +sudo: true language: node_js before_install: - - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then export DISPLAY=:99.0 && sh -e /etc/init.d/xvfb start; fi - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo apt-get update; fi - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo apt-get install chromium-browser; fi - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew update; fi @@ -15,4 +13,3 @@ node_js: - node addons: chrome: stable - firefox: "51.0" From 10763dd56e38a456049fd1eec2161262512f8fe1 Mon Sep 17 00:00:00 2001 From: Chris Andrejewski Date: Sun, 30 Jul 2017 14:33:08 -0400 Subject: [PATCH 17/21] Use Chrome beta --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 99ec780..38c12d3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,4 +12,4 @@ node_js: - 4 - node addons: - chrome: stable + chrome: beta From 936bc272ec90223a279a19e80feca75ed42f12f4 Mon Sep 17 00:00:00 2001 From: Chris Andrejewski Date: Sun, 30 Jul 2017 14:35:49 -0400 Subject: [PATCH 18/21] Must use trusty --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 38c12d3..37350ca 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,4 @@ +dist: trusty sudo: true language: node_js before_install: From 906977430a5970499318739c6b4a51f04953cf73 Mon Sep 17 00:00:00 2001 From: Chris Andrejewski Date: Sun, 30 Jul 2017 14:40:37 -0400 Subject: [PATCH 19/21] Use precise Firefox version --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 37350ca..de004ea 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,3 +14,4 @@ node_js: - node addons: chrome: beta + firefox: "38.4.0esr" From 1714bf4515ca9165815e1f86281d3584b2ac3793 Mon Sep 17 00:00:00 2001 From: Chris Andrejewski Date: Sun, 30 Jul 2017 14:48:40 -0400 Subject: [PATCH 20/21] I give up on Firefox --- .travis.yml | 3 +-- test/local.js | 5 +++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index de004ea..c9d2de8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,5 +13,4 @@ node_js: - 4 - node addons: - chrome: beta - firefox: "38.4.0esr" + chrome: stable diff --git a/test/local.js b/test/local.js index 9443a22..baa1644 100644 --- a/test/local.js +++ b/test/local.js @@ -35,6 +35,11 @@ describe('Local browser launcher tests', function() { browsers.forEach(function (name) { var testTitle = 'Should launch ' + name + ' browser on ' + process.platform; + if (name === 'firefox') { + it.skip(testTitle); + return; + } + it(testTitle, function (done) { local(function (error, launcher) { launcher[name]('http://localhost:6785', function (error, instance) { From a6dfe718bf5b0be2ce42284894d5e1ce161ffcbf Mon Sep 17 00:00:00 2001 From: Chris Andrejewski Date: Sun, 30 Jul 2017 15:02:40 -0400 Subject: [PATCH 21/21] Remove DEBUG var --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index fbf7f02..db8c489 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ "node": ">= 4" }, "scripts": { - "test": "DEBUG=launchpad:* xvfb-maybe grunt test --stack", + "test": "xvfb-maybe grunt test --stack", "publish": "git push origin && git push origin --tags", "release:major": "npm version major && npm publish", "release:minor": "npm version minor && npm publish",