Advertisement
c089

Untitled

Apr 23rd, 2011
417
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 4.23 KB | None | 0 0
  1. #!/bin/bash
  2. ###############################################################################
  3. # jstestdriver.sh
  4. ###############################################################################
  5. # Script to run js-test-driver for the timetable project.
  6. # This script will work around a few limitations of js-test-driver and ExtJS4.
  7. #
  8. # The Xvfb part is based on the script found on the jstd project page:
  9. # http://code.google.com/p/js-test-driver/wiki/ContinuousBuild
  10. #
  11. ###############################################################################
  12. # USAGE
  13. ###############################################################################
  14. # There is two ways to use this script: Developer mode and Jenkins mode.
  15. #
  16. # NOTE: You *must* run this script from it's own directory (test/js)
  17. #
  18. # Developer mode
  19. #
  20. # Developer mode is a two-part process: First run this script with "server" as
  21. # its argument. It will make the required modifications, run the server and
  22. # tell you which temporary directory it is using. Now you can attach a browser
  23. # (or multiple browsers) by visiting http://localhost:4224 (or any other
  24. # configured port). After that, run the script again, with the "run" argument
  25. # and the temporary directory the server told you:
  26. # jstestdriver.sh server
  27. # (attach browsers)
  28. # jstestdriver.sh run /tmp/foobar
  29. # (repeat the last step until your code is extremely awesome)
  30. #
  31. # Jenkins mode
  32. #
  33. # As the name suggests, jenkins mode is intended to be used by the jenkins ci
  34. # server. It will create a virtual framebuffer, start the jstd server, start a
  35. # browser, run the tests and then shut it all down again.
  36. #
  37. ###############################################################################
  38. # CONFIGURATION
  39. ###############################################################################
  40. # Path to jstd jar file
  41. JS_TEST_DRIVER=`pwd`/JsTestDriver-1.3.2.jar
  42. # Port for the server
  43. DEV_PORT=4224
  44. JENKINS_PORT=4225
  45. # Directory used to store xml results (jenkins mode only)
  46. OUTPUT_DIR=`pwd`'/../../target/test-reports/'
  47. # Browser to start (jenkins mode only)
  48. BROWSER="firefox"
  49.  
  50.  
  51. adjust_files() {
  52.     # Copy the files to a teporary directory and make adjustments necessary for
  53.     # jstd and extjs to play together nicely.
  54.     cp -r jstestdriver.conf unit/ ../../web-app/js/ $1
  55.     cd $1
  56.     # The JSTD httpd serves js files under "/test/" -> replace appFolder config so
  57.     # files are fetched correctly with the dynamic loader
  58.     sed -i s#"appFolder:.*'.*'"#"appFolder: '/test/js/timetable'"# \
  59.         js/timetable/Application.js
  60. }
  61.  
  62. set_up_tmp() {
  63.     # JSTD expects source and test files to be in the same base path which does not
  64.     # meet our directory layout. Therefore we create a temporary directory and copy
  65.     # the files over:
  66.     CURDIR=`pwd`
  67.     TMPDIR=`mktemp -d`
  68.     adjust_files $TMPDIR
  69.     cd $TMPDIR
  70. }
  71.  
  72. jenkins() {
  73.     set_up_tmp
  74.  
  75.     # jstd requires the output dir to exist
  76.     mkdir -p $OUTPUT_DIR
  77.  
  78.     # Start virtual framebuffer
  79.     Xvfb :99 -ac &
  80.     PID_XVFB="$!"
  81.     export DISPLAY=:99
  82.  
  83.     # Finally run the tests
  84.     java -jar $JS_TEST_DRIVER --config jstestdriver.conf --port $JENKINS_PORT\
  85.         --browser $BROWSER --tests all --testOutput $OUTPUT_DIR
  86.  
  87.     # Remove the mess we just made
  88.     cd $CURDIR
  89.     rm -rf $TMPDIR
  90.  
  91.     # Kill Framebuffer (will also kill the browser)
  92.     kill $PID_XVFB
  93. }
  94.  
  95. server() {
  96.     set_up_tmp
  97.  
  98.     echo "Starting jstestdriver server. Attach browsers by visting"\
  99.         "'http://localhost:$DEV_PORT/', then run jstestdriver.sh run $TMPDIR'."
  100.  
  101.     # Run the server
  102.     java -jar $JS_TEST_DRIVER --port $DEV_PORT
  103.  
  104.     # After the server returns, remove the mess we just made
  105.     cd $CURDIR
  106.     rm -rf $TMPDIR
  107. }
  108.  
  109. run() {
  110.     if [ -z $1 ]; then
  111.         echo "run requires the path to jstd tmp dir as its argument"
  112.         exit 1
  113.     fi
  114.  
  115.     CURDIR=`pwd`
  116.  
  117.     # update files in jstd tmp dir
  118.     adjust_files $1
  119.     cd $1
  120.     java -jar $JS_TEST_DRIVER --config jstestdriver.conf --tests all \
  121.         --server http://localhost:$DEV_PORT
  122.     cd $CURDIR
  123. }
  124.  
  125. if [ "$1" == "jenkins" ]; then
  126.     jenkins
  127. elif [ "$1" == "server" ]; then
  128.     server
  129. elif [ "$1" == "run" ]; then
  130.     run $2
  131. else
  132.     echo "Usage: jstestdriver.sh jenkins|server|run [tmp_dir]"
  133. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement