Here's an example snippet for how to configure karma.conf.js
to use Dockerized Chrome Headless and Dockerized Firefox Headless.
See also how to let Karma run JavaScript tests on Internet Explorer 11 in Windows with VirtualBox on Mac OS X
You have to npm install @rkuzsma/karma-docker-launcher
. And, because this module name is scoped, Karma won't automatically recognize it by the karma-*
prefix, so the plugins
addition below is necessary.
// karma.conf.js
module.exports = function (config) {
config.set({
plugins: [
// Karma automatically require()s packages that start with karma-*,
// but it does not recognize scoped packages, so we must be explicit.
'@rkuzsma/karma-docker-launcher',
'karma-*'
],
browsers: [
// 'PhantomJS',
'DockerFirefoxHeadless',
'DockerChromeHeadless'
],
customLaunchers: {
DockerFirefoxHeadless: {
base: 'Docker',
// I manually built this firefox-headless Docker image on my machine, based on the Dockerfile at:
// https://github.com/rkuzsma/docker-headless-browsers/tree/master/firefox-headless
image: 'firefox-headless',
containerCommand: 'firefox ' +
'-p headless ' +
'-no-remote ' +
'-headless ' +
'-url $KARMA_URL'
},
DockerChromeHeadless: {
base: 'Docker',
// Use your favorite Chrome headless docker container
// example 1:
// // a manually-built image from https://github.com/rkuzsma/docker-headless-browsers :
// image: 'chrome-headless',
// containerCommand: 'chrome ' + ...
// example 2:
// image: 'zenika/alpine-chrome',
// containerCommand: 'chromium-browser ' + ...
// example 3:
image: 'alpeware/chrome-headless-stable:ver-70.0.3538.77',
containerCommand: 'google-chrome-stable ' +
'--headless ' +
'--no-sandbox ' +
'--remote-debugging-port=9222 ' +
'--user-data-dir=/userdata ' +
'--no-default-browser-check ' +
'--no-first-run ' +
'--disable-default-apps ' +
'--disable-popup-blocking ' +
'--disable-translate ' +
'--disable-background-timer-throttling ' +
'--disable-renderer-backgrounding ' +
'--disable-device-discovery-notifications ' +
'--disable-software-rasterizer ' +
'--no-gpu ' +
'--mute-audio ' +
'--hide-scrollbars ' +
'$KARMA_URL'
}
// ...