test: disable Chrome sandboxing when inside Docker

See the discussion in
https://github.com/docker/for-linux/issues/496

Signed-off-by: Miroslav Bajtoš <mbajtoss@gmail.com>
This commit is contained in:
Miroslav Bajtoš 2019-09-30 11:14:04 +02:00
parent cceb8a3c26
commit 8311138f3e
No known key found for this signature in database
GPG Key ID: 6F2304BA9361C7E3
3 changed files with 22 additions and 2 deletions

View File

@ -104,7 +104,7 @@ module.exports = function(grunt) {
karma: {
'unit-once': {
configFile: 'test/karma.conf.js',
browsers: ['ChromeHeadless'],
browsers: ['ChromeDocker'],
singleRun: true,
reporters: ['dots', 'junit'],

View File

@ -80,6 +80,7 @@
"grunt-eslint": "^21.0.0",
"grunt-karma": "^3.0.2",
"grunt-mocha-test": "^0.13.3",
"is-docker": "^2.0.0",
"karma": "^4.1.0",
"karma-browserify": "^6.0.0",
"karma-chrome-launcher": "^2.2.0",

View File

@ -3,12 +3,31 @@
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT
'use strict';
const isDocker = require('is-docker');
// Karma configuration
// http://karma-runner.github.io/0.12/config/configuration-file.html
'use strict';
module.exports = function(config) {
// see https://github.com/docker/for-linux/issues/496
const disableChromeSandbox = isDocker() && !process.env.TRAVIS;
if (disableChromeSandbox) {
console.log('!! Disabling Chrome sandbox to support un-privileged Docker !!');
}
config.set({
customLaunchers: {
ChromeDocker: {
base: 'ChromeHeadless',
// We must disable the Chrome sandbox when running Chrome inside Docker
// (Chrome's sandbox needs more permissions than Docker allows by default)
// See https://github.com/docker/for-linux/issues/496
flags: disableChromeSandbox ? ['--no-sandbox'] : [],
},
},
// enable / disable watching file and executing tests whenever any file changes
autoWatch: true,