Skip to content

Instantly share code, notes, and snippets.

@twolfson
Last active March 30, 2017 04:05
Show Gist options
  • Save twolfson/f099e18cf5eb9cc55384e7a0582fbe10 to your computer and use it in GitHub Desktop.
Save twolfson/f099e18cf5eb9cc55384e7a0582fbe10 to your computer and use it in GitHub Desktop.
Proof of concept to demonstrate how Karma fails when a launcher fails
node_modules/
vendor/

gist-karma-launcher-fail

Proof of concept to demonstrate how Karma fails when a launcher fails

Getting started

Run the following steps to get this proof of concept running:

# Clone the repository
git clone <repo_url> gist-karma-launcher-fail
cd gist-karma-launcher-fail

# Launch a container via Docker with a bash shell
# DEV: We could replace this with Vagrant but this is lighter
./run.sh

# In this Docker container, run our bootstrap script
#   Handles Node.js dependencies
cd /docker
./bootstrap.sh

# Run Karma test
npm test

Attribution

Docker setup from: https://gist.github.com/twolfson/a26174b833b66d2ad05688dceee755c8

#!/usr/bin/env bash
# Exit on first error
set -e
# If apt hasn't been updated, then update it
if ! test -f ~/.apt-get-updated; then
apt-get update
touch ~/.apt-get-updated
fi
# Install our system dependencies
if ! which curl &> /dev/null; then
apt-get install -y git curl wget man nano
fi
# https://github.com/nodesource/distributions/tree/3bc77a572f825afca8f11b4611486e652dc78188
if ! which nodejs &> /dev/null; then
curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
sudo apt-get install -y nodejs
fi
# Install a local Firefox (so it's missing system dependencies)
if ! test -d vendor/firefox; then
mkdir -p vendor
cd vendor
wget https://ftp.mozilla.org/pub/firefox/releases/52.0.2/linux-x86_64/en-US/firefox-52.0.2.tar.bz2
tar xf firefox-52.0.2.tar.bz2
cd -
fi
# Install our Node.js dependencies
cd /docker
npm install
// Karma configuration
// Generated on Thu Mar 30 2017 03:50:43 GMT+0000 (UTC)
module.exports = function(config) {
config.set({
// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '',
// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['mocha'],
// list of files / patterns to load in the browser
files: [
'test.js'
],
// list of files to exclude
exclude: [
],
// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
},
// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['progress'],
// web server port
port: 9876,
// enable / disable colors in the output (reporters and logs)
colors: true,
// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_INFO,
// enable / disable watching file and executing tests whenever any file changes
autoWatch: true,
// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: ['Firefox'],
// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: true,
// Concurrency level
// how many browser should be started simultaneous
concurrency: Infinity
});
};
{
"name": "gist-karma-launcher-fail",
"version": "1.0.0",
"description": "Proof of concept to demonstrate how Karma fails when a launcher fails",
"main": "index.js",
"scripts": {
"test": "FIREFOX_BIN=$PWD/vendor/firefox/firefox karma start"
},
"author": "Todd Wolfson <todd@twolfson.com> (http://twolfson.com/)",
"license": "Unlicense",
"dependencies": {
"karma": "~1.5.0",
"karma-firefox-launcher": "~1.0.1",
"karma-mocha": "~1.3.0",
"mocha": "~3.2.0"
}
}
#!/usr/bin/env bash
# Exit on first error
set -e
# If a docker instance exists, then stop and remove it
container_name="gist-karma-launcher-fail"
if docker ps --all | grep "$container_name" &> /dev/null; then
docker stop "$container_name" &> /dev/null
docker rm "$container_name" &> /dev/null
fi
#!/usr/bin/env bash
# Exit on first error
set -e
# If a docker instance already exists, then verify it's running and connect to it
container_name="gist-karma-launcher-fail"
if docker ps --all | grep "$container_name" &> /dev/null; then
docker start "$container_name" &> /dev/null
docker exec --interactive --tty "$container_name" /bin/bash
# Otherwise, start it up
else
docker run --name "$container_name" --interactive --tty --volume "$PWD:/docker" ubuntu:14.04 /bin/bash
fi
describe('A sample test', function () {
it('has no errors', function () {
throw new Error('Test error');
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment