How to run Karma tests from docker container?
I've found this docker image to be an excellent starting point for running karma tests quickly inside a docker container on Concourse CI:
https://hub.docker.com/r/markadams/chromium-xvfb-js/
It contains node 6.x (latest) + npm and a headless chromium instance using X virtual framebuffer. Working great for me!
There is also protractor-runner project, and Karma is similar to running Protractor, and so you might be able to learn how to do it from that example. But, I prefer the suggestion to use chromium-xvfb-js
image.
Use PhantomJS instead of Chrome. Karma has PhantomJS launcher.
PhantomJS based on Blink.
Install PhantomJS:
npm karma-phantomjs-launcher --save-dev
Add to Karma config:
module.exports = function(config) { config.set({ browsers : ['PhantomJS'] });};
EDIT
Here is part od Dockerfile
ENV NODE_VERSION 0.12.7ENV NPM_VERSION 3.5.1ENV PHANTOM_JS phantomjs-1.9.8-linux-x86_64# App and testRUN set -x \ && buildDeps='curl git bzip2 file libfreetype6 libfontconfig1 python-pip python-dev libpq-dev libmemcached-dev libzmq-dev libjpeg62-turbo-dev zlib1g-dev libtiff5-dev make g++ psmisc' \ && apt-get update \ && apt-get install -y $buildDeps --no-install-recommends \ && rm -rf /var/lib/apt/lists/* \ && curl -SLO "https://bitbucket.org/ariya/phantomjs/downloads/$PHANTOM_JS.tar.bz2" \ && tar xvjf $PHANTOM_JS.tar.bz2 \ && mv $PHANTOM_JS /usr/local/share \ && ln -sf /usr/local/share/$PHANTOM_JS/bin/phantomjs /usr/local/bin \ && curl -SLO "https://nodejs.org/dist/v$NODE_VERSION/node-v$NODE_VERSION-linux-x64.tar.gz" \ && curl -SLO "https://nodejs.org/dist/v$NODE_VERSION/SHASUMS256.txt.asc" \ && gpg --verify SHASUMS256.txt.asc \ && grep " node-v$NODE_VERSION-linux-x64.tar.gz\$" SHASUMS256.txt.asc | sha256sum -c - \ && tar -xzf "node-v$NODE_VERSION-linux-x64.tar.gz" -C /usr/local --strip-components=1 \ && rm "node-v$NODE_VERSION-linux-x64.tar.gz" SHASUMS256.txt.asc \ && npm install -g npm@"$NPM_VERSION" grunt-cli \ && npm install \ && npm cache clear \ && ./node_modules/.bin/bower install --allow-root \ && npm test \ && apt-get purge -y --auto-remove $buildDeps \ && rm -rf /usr/local/bin/node /usr/local/bin/npm /usr/local/include/node /usr/local/lib/node_modules \ && rm -rf /usr/local/share/$PHANTOM_JS /usr/local/bin/phantomjs
In this case Docker made one layer. In this layer
- install libs and tools (debian jessie)
- install PhantomJS
- install NodeJS
- run tests
- remove libs and tools
- remove NodeJS
- remove PhantomJS
Tests are running and You don't have PhantomJS in production container.