Add support for HeadlessChrome in karma

Motivation for this change:
  As a tester, I want to execute npm unit tests in a headless
  chrome environment.

Notes on implementation:
  * Running headless chrome requires verion chrome 59 or greater[1]
  * --no-sandbox flag is a workaround for running as root[2]
  * HeadlessChrome base was added in karma-chrome-launcher v2.1.0[3]
    - upgrading to this package caused a CHROME_BIN not set error[4].
      Setting CHROME_BIN to chromium-browser fixes the issue.
  * Using Chrome without the upgraded packages causes an error during
    the coverage report generation
    - TypeError: Cannot read property 'start' of undefined[5]

[1] https://github.com/karma-runner/karma-chrome-launcher#available-browsers
[2] https://github.com/karma-runner/karma-chrome-launcher/issues/158
[3] https://github.com/karma-runner/karma-chrome-launcher/releases/tag/v2.1.0
[4] http://paste.openstack.org/show/715433/
[5] https://review.openstack.org/#/c/456556/9

Change-Id: I907708d73b5fe5345f3a56d8d638c51e7d3aa6f7
This commit is contained in:
mccasland, trevor (tm2086) 2018-03-27 09:17:04 -05:00
parent 4cc5c7e449
commit fd387956f4
2 changed files with 10 additions and 2 deletions

View File

@ -58,7 +58,7 @@
"karma": "~0.12.0",
"karma-babel-preprocessor": "^4.0.1",
"karma-browserify": "^4.0.0",
"karma-chrome-launcher": "^0.2.2",
"karma-chrome-launcher": "^2.1.0",
"karma-cli": "0.0.4",
"karma-coverage": "0.2.6",
"karma-jasmine": "^0.3.6",

View File

@ -4,6 +4,8 @@ var istanbul = require('browserify-istanbul');
var isparta = require('isparta');
var ngAnnotate = require('browserify-ngannotate');
process.env.CHROME_BIN = 'chromium-browser'; // eslint-disable-line no-process-env
module.exports = function(config) {
config.set({
@ -34,7 +36,13 @@ module.exports = function(config) {
autoWatch: true,
browsers: ['Chrome'],
browsers: ['ChromeHeadlessNoSandbox'],
customLaunchers: {
ChromeHeadlessNoSandbox: {
base: 'ChromeHeadless',
flags: ['--no-sandbox']
}
},
singleRun: true,