diff --git a/Gruntfile.js b/Gruntfile.js index 19671a44..46ebf98b 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -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'], diff --git a/package.json b/package.json index b6dbd7e1..a98f9c80 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/test/karma.conf.js b/test/karma.conf.js index 1567fe20..6b0c0fd5 100644 --- a/test/karma.conf.js +++ b/test/karma.conf.js @@ -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,