Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- ###############################################################################
- # jstestdriver.sh
- ###############################################################################
- # Script to run js-test-driver for the timetable project.
- # This script will work around a few limitations of js-test-driver and ExtJS4.
- #
- # The Xvfb part is based on the script found on the jstd project page:
- # http://code.google.com/p/js-test-driver/wiki/ContinuousBuild
- #
- ###############################################################################
- # USAGE
- ###############################################################################
- # There is two ways to use this script: Developer mode and Jenkins mode.
- #
- # NOTE: You *must* run this script from it's own directory (test/js)
- #
- # Developer mode
- #
- # Developer mode is a two-part process: First run this script with "server" as
- # its argument. It will make the required modifications, run the server and
- # tell you which temporary directory it is using. Now you can attach a browser
- # (or multiple browsers) by visiting http://localhost:4224 (or any other
- # configured port). After that, run the script again, with the "run" argument
- # and the temporary directory the server told you:
- # jstestdriver.sh server
- # (attach browsers)
- # jstestdriver.sh run /tmp/foobar
- # (repeat the last step until your code is extremely awesome)
- #
- # Jenkins mode
- #
- # As the name suggests, jenkins mode is intended to be used by the jenkins ci
- # server. It will create a virtual framebuffer, start the jstd server, start a
- # browser, run the tests and then shut it all down again.
- #
- ###############################################################################
- # CONFIGURATION
- ###############################################################################
- # Path to jstd jar file
- JS_TEST_DRIVER=`pwd`/JsTestDriver-1.3.2.jar
- # Port for the server
- DEV_PORT=4224
- JENKINS_PORT=4225
- # Directory used to store xml results (jenkins mode only)
- OUTPUT_DIR=`pwd`'/../../target/test-reports/'
- # Browser to start (jenkins mode only)
- BROWSER="firefox"
- adjust_files() {
- # Copy the files to a teporary directory and make adjustments necessary for
- # jstd and extjs to play together nicely.
- cp -r jstestdriver.conf unit/ ../../web-app/js/ $1
- cd $1
- # The JSTD httpd serves js files under "/test/" -> replace appFolder config so
- # files are fetched correctly with the dynamic loader
- sed -i s#"appFolder:.*'.*'"#"appFolder: '/test/js/timetable'"# \
- js/timetable/Application.js
- }
- set_up_tmp() {
- # JSTD expects source and test files to be in the same base path which does not
- # meet our directory layout. Therefore we create a temporary directory and copy
- # the files over:
- CURDIR=`pwd`
- TMPDIR=`mktemp -d`
- adjust_files $TMPDIR
- cd $TMPDIR
- }
- jenkins() {
- set_up_tmp
- # jstd requires the output dir to exist
- mkdir -p $OUTPUT_DIR
- # Start virtual framebuffer
- Xvfb :99 -ac &
- PID_XVFB="$!"
- export DISPLAY=:99
- # Finally run the tests
- java -jar $JS_TEST_DRIVER --config jstestdriver.conf --port $JENKINS_PORT\
- --browser $BROWSER --tests all --testOutput $OUTPUT_DIR
- # Remove the mess we just made
- cd $CURDIR
- rm -rf $TMPDIR
- # Kill Framebuffer (will also kill the browser)
- kill $PID_XVFB
- }
- server() {
- set_up_tmp
- echo "Starting jstestdriver server. Attach browsers by visting"\
- "'http://localhost:$DEV_PORT/', then run jstestdriver.sh run $TMPDIR'."
- # Run the server
- java -jar $JS_TEST_DRIVER --port $DEV_PORT
- # After the server returns, remove the mess we just made
- cd $CURDIR
- rm -rf $TMPDIR
- }
- run() {
- if [ -z $1 ]; then
- echo "run requires the path to jstd tmp dir as its argument"
- exit 1
- fi
- CURDIR=`pwd`
- # update files in jstd tmp dir
- adjust_files $1
- cd $1
- java -jar $JS_TEST_DRIVER --config jstestdriver.conf --tests all \
- --server http://localhost:$DEV_PORT
- cd $CURDIR
- }
- if [ "$1" == "jenkins" ]; then
- jenkins
- elif [ "$1" == "server" ]; then
- server
- elif [ "$1" == "run" ]; then
- run $2
- else
- echo "Usage: jstestdriver.sh jenkins|server|run [tmp_dir]"
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement