test(travis): run unit tests on travis + saucelabs

test-unit-sauce
Brian Ford 9 years ago
parent d7008a1368
commit 8c67a3e77e

@ -0,0 +1,21 @@
language: node_js
node_js:
- "0.10"
env:
global:
- BROWSER_PROVIDER_READY_FILE=/tmp/sauce-connect-ready
- LOGS_DIR=/tmp/angular-hint-build/logs
- SAUCE_USERNAME=angular-ci
- SAUCE_ACCESS_KEY=9b988f434ff8-fbca-8aa4-4ae3-35442987
install:
- mkdir -p $LOGS_DIR
- ./scripts/sauce_connect_setup.sh
- npm install
- npm install -g gulp
- npm install -g karma-cli
- ./scripts/wait_for_browser_provider.sh
script:
- ./scripts/test_on_sauce.sh

@ -0,0 +1,21 @@
/*
* karma.conf.js and karma.es5.conf.js optionally load this
*/
var CUSTOM_LAUNCHERS = {
'SL_Chrome': {
base: 'SauceLabs',
browserName: 'chrome',
version: '35'
}
};
module.exports = function(options) {
options.sauceLabs = {
testName: 'AngularJS Batarang Unit Tests',
startConnect: true
};
options.customLaunchers = CUSTOM_LAUNCHERS;
options.browsers = Object.keys(CUSTOM_LAUNCHERS);
options.reporters = ['dots', 'saucelabs'];
};

@ -0,0 +1,24 @@
/*
* karma.conf.js optionally loads this
*/
module.exports = function(options) {
if (!isTravis()) {
return;
} else if (!options.sauceLabs) {
throw new Error('This should be loaded after karma.sauce config');
}
options.sauceLabs.build = 'TRAVIS #' + process.env.TRAVIS_BUILD_NUMBER + ' (' + process.env.TRAVIS_BUILD_ID + ')';
options.sauceLabs.tunnelIdentifier = process.env.TRAVIS_JOB_NUMBER;
options.sauceLabs.startConnect = false;
// TODO(vojta): remove once SauceLabs supports websockets.
// This speeds up the capturing a bit, as browsers don't even try to use websocket.
options.transports = ['xhr-polling'];
options.singleRun = true;
};
function isTravis() {
return !!process.env.TRAVIS;
}

@ -2,8 +2,11 @@
* This karma conf tests just the panel app
*/
var sauceConfig = require('./config/karma.sauce.conf');
var travisConfig = require('./config/karma.travis.conf');
module.exports = function(config) {
config.set({
var options = {
frameworks: ['browserify', 'jasmine'],
files: [
'node_modules/angular/angular.js',
@ -17,5 +20,12 @@ module.exports = function(config) {
'hint.js': [ 'browserify' ]
},
browsers: ['Chrome'],
});
};
if (process.argv.indexOf('--sauce') > -1) {
sauceConfig(options);
travisConfig(options);
}
config.set(options);
};

@ -0,0 +1,29 @@
#!/bin/bash
#
# Switch a dependency to git repo.
# Remove the NPM package and link it to a repo in parent directory.
DEP_NAME=$1
SCRIPT_DIR=$(dirname $0)
cd $SCRIPT_DIR/..
if [ -L ./node_modules/$DEP_NAME ]; then
echo "$DEP_NAME is already a symlink"
else
PKG_INFO=($($SCRIPT_DIR/read-pkg-url.js ./node_modules/$DEP_NAME/package.json))
URL=${PKG_INFO[0]}
DIR_NAME=${PKG_INFO[1]}
echo "Switching $DEP_NAME"
rm -rf ./node_modules/$DEP_NAME
if [ -d ../$DIR_NAME ]; then
echo "Repo already cloned in ../$DIR_NAME"
else
cd ..
git clone $URL $DIR_NAME
cd -
fi
echo "Link ./node_modules/$DEP_NAME -> ../$DIR_NAME"
ln -s ../../$DIR_NAME ./node_modules/$DEP_NAME
fi

@ -0,0 +1,15 @@
#!/bin/bash
#
# Switch a dependency to NPM.
# Remove the symlink and install from NPM.
DEP_NAME=$1
SCRIPT_DIR=$(dirname $0)
cd $SCRIPT_DIR/..
if [ ! -L ./node_modules/$DEP_NAME ]; then
echo "$DEP_NAME is not a symlink"
else
rm ./node_modules/$DEP_NAME
npm install $DEP_NAME
fi

@ -0,0 +1,11 @@
#!/bin/bash
LOG_FILES=$LOGS_DIR/*
for FILE in $LOG_FILES; do
echo -e "\n\n\n"
echo "=================================================================="
echo " $FILE"
echo "=================================================================="
cat $FILE
done

@ -0,0 +1,8 @@
#!/usr/bin/env node
var fs = require('fs');
var pkg = JSON.parse(fs.readFileSync(process.argv[2]));
var url = pkg.repository.url;
var dirname = url.replace(/^.*\//, '').replace(/\.git$/, '');
console.log(url + ' ' + dirname);

@ -0,0 +1,50 @@
#!/bin/bash
set -e
# Setup and start Sauce Connect for your TravisCI build
# This script requires your .travis.yml to include the following two private env variables:
# SAUCE_USERNAME
# SAUCE_ACCESS_KEY
# Follow the steps at https://saucelabs.com/opensource/travis to set that up.
#
# Curl and run this script as part of your .travis.yml before_script section:
# before_script:
# - curl https://gist.github.com/santiycr/5139565/raw/sauce_connect_setup.sh | bash
CONNECT_URL="https://saucelabs.com/downloads/sc-4.3-linux.tar.gz"
CONNECT_DIR="/tmp/sauce-connect-$RANDOM"
CONNECT_DOWNLOAD="sc-latest-linux.tar.gz"
CONNECT_LOG="$LOGS_DIR/sauce-connect"
CONNECT_STDOUT="$LOGS_DIR/sauce-connect.stdout"
CONNECT_STDERR="$LOGS_DIR/sauce-connect.stderr"
# Get Connect and start it
mkdir -p $CONNECT_DIR
cd $CONNECT_DIR
curl $CONNECT_URL -o $CONNECT_DOWNLOAD 2> /dev/null 1> /dev/null
mkdir sauce-connect
tar --extract --file=$CONNECT_DOWNLOAD --strip-components=1 --directory=sauce-connect > /dev/null
rm $CONNECT_DOWNLOAD
SAUCE_ACCESS_KEY=`echo $SAUCE_ACCESS_KEY | rev`
ARGS=""
# Set tunnel-id only on Travis, to make local testing easier.
if [ ! -z "$TRAVIS_JOB_NUMBER" ]; then
ARGS="$ARGS --tunnel-identifier $TRAVIS_JOB_NUMBER"
fi
if [ ! -z "$BROWSER_PROVIDER_READY_FILE" ]; then
ARGS="$ARGS --readyfile $BROWSER_PROVIDER_READY_FILE"
fi
echo "Starting Sauce Connect in the background, logging into:"
echo " $CONNECT_LOG"
echo " $CONNECT_STDOUT"
echo " $CONNECT_STDERR"
sauce-connect/bin/sc -u $SAUCE_USERNAME -k $SAUCE_ACCESS_KEY -v $ARGS \
--logfile $CONNECT_LOG 2> $CONNECT_STDERR 1> $CONNECT_STDOUT &

@ -0,0 +1,8 @@
#! /bin/bash
SCRIPT_DIR=$(dirname $0)
cd $SCRIPT_DIR/..
SAUCE_ACCESS_KEY=`echo $SAUCE_ACCESS_KEY | rev`
gulp
karma start --sauce

@ -0,0 +1,7 @@
#!/bin/bash
# Wait for Connect to be ready before exiting
while [ ! -f $BROWSER_PROVIDER_READY_FILE ]; do
sleep .5
done