Skip to content

Commit

Permalink
Porting preferHeadless work over
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan Felchlin committed Mar 20, 2018
1 parent 59a5e31 commit 86936e4
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 19 deletions.
17 changes: 1 addition & 16 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,38 +27,23 @@ if(process.env.TRAVIS) {
var config = karmaConfig[keys[i]];

config.customLaunchers = {
Chrome_travis_ci: {
base: 'Chrome',
flags: ['--no-sandbox']
},
ChromeHeadless_travis_ci: {
base: 'ChromeHeadless',
flags: ['--no-sandbox']
},
Chromium_travis_ci: {
base: 'Chromium',
flags: ['--no-sandbox']
},
ChromiumHeadless_travis_ci: {
base: 'ChromiumHeadless',
flags: ['--no-sandbox']
}
};

config.detectBrowsers = config.detectBrowsers || {};
config.detectBrowsers.preferHeadless = true;
config.detectBrowsers.postDetection = function(browsers) {
var chromeIndex = browsers.indexOf('Chrome');
if(chromeIndex !== -1) {
browsers[chromeIndex] = 'Chrome_travis_ci';
}
var chromeHeadlessIndex = browsers.indexOf('ChromeHeadless');
if(chromeHeadlessIndex !== -1) {
browsers[chromeHeadlessIndex] = 'ChromeHeadless_travis_ci';
}
var chromiumIndex = browsers.indexOf('Chromium');
if(chromiumIndex !== -1) {
browsers[chromiumIndex] = 'Chromium_travis_ci';
}
var chromiumHeadlessIndex = browsers.indexOf('ChromiumHeadless');
if(chromiumHeadlessIndex !== -1) {
browsers[chromiumHeadlessIndex] = 'ChromiumHeadless_travis_ci';
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ module.exports = function(config) {
// enable/disable phantomjs support, default is true
usePhantomJS: true,

// use headless mode, for browsers that support it, default is false
preferHeadless: true,

// post processing of browsers list
// here you can edit the list of browsers used by karma
postDetection: function(availableBrowser) {
Expand Down
2 changes: 1 addition & 1 deletion browsers/Chrome.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = {
name: 'ChromeHeadless',
name: 'Chrome',
DEFAULT_CMD: {
linux: ['google-chrome', 'google-chrome-stable'],
darwin: ['/Applications/Google Chrome.app/Contents/MacOS/Google Chrome'],
Expand Down
2 changes: 1 addition & 1 deletion browsers/Chromium.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = {
name: 'ChromiumHeadless',
name: 'Chromium',
DEFAULT_CMD: {
linux: [
// Try chromium-browser before chromium to avoid conflict with the legacy
Expand Down
17 changes: 16 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
'use strict';

var headlessBrowsers = [
'Chrome',
'Chromium',
'ChromeCanary',
'Firefox',
'FirefoxDeveloper',
'FirefoxAurora',
'FirefoxNightly',
];

var DetectBrowsers = function (config, logger) {
var fs = require('fs'),
os = require('os'),
Expand Down Expand Up @@ -76,9 +86,14 @@ var DetectBrowsers = function (config, logger) {
log.info('Detecting browsers is disabled. The browsers of the browsers array are used.');
return;
}

var availableBrowser = getInstalledBrowsers(browsers);

if (config.detectBrowsers.preferHeadless) {
availableBrowser = availableBrowser.map(function (browser) {
return headlessBrowsers.indexOf(browser) >= 0 ? browser + 'Headless' : browser;
});
}

// override the browsers in the config only when browsers where find by this plugin
if (availableBrowser.length >= 0) {
// check for PhantomJS option
Expand Down

0 comments on commit 86936e4

Please sign in to comment.