| 1 | #!/bin/sh
|
|---|
| 2 |
|
|---|
| 3 | if [ -z $1 ]; then
|
|---|
| 4 | echo "Usage: $0 [NUMBER[-NUMBER]][,NUMBER[-NUMBER]]..."
|
|---|
| 5 | exit 1
|
|---|
| 6 | fi
|
|---|
| 7 |
|
|---|
| 8 | # Create array to store numbers of the tests
|
|---|
| 9 | TESTNUMBERS=()
|
|---|
| 10 |
|
|---|
| 11 | # Location of test scripts
|
|---|
| 12 | SCRIPTDIR=$ISSM_DIR/jenkins/javascript/karma/scripts
|
|---|
| 13 |
|
|---|
| 14 | OLDIFS=$IFS
|
|---|
| 15 | IFS=, # Overwrite the in-field-separator to detect ranges of numbers as numbers separated by commas
|
|---|
| 16 |
|
|---|
| 17 | # Add the test numbers to the array
|
|---|
| 18 | for range in $1; do
|
|---|
| 19 | if [[ ! "$range" =~ "-" ]]; then # check if it is a range of numbers or just a single number
|
|---|
| 20 | if [ ! -f "$SCRIPTDIR/test$range.js" ]; then
|
|---|
| 21 | >&2 echo "Warning: test$num.js does not exist."
|
|---|
| 22 | else
|
|---|
| 23 | TESTNUMBERS+=($range)
|
|---|
| 24 | fi
|
|---|
| 25 | else
|
|---|
| 26 | SEQUENCE=($(seq -w -s ' ' $(sed "s/-/$IFS/" <<< ${range})))
|
|---|
| 27 |
|
|---|
| 28 | IFS=' '
|
|---|
| 29 | for num in ${SEQUENCE[@]}; do
|
|---|
| 30 | if [ ! -f "$SCRIPTDIR/test$num.js" ]; then
|
|---|
| 31 | >&2 echo "Warning: test$num.js does not exist."
|
|---|
| 32 | fi
|
|---|
| 33 | done
|
|---|
| 34 |
|
|---|
| 35 | TESTNUMBERS=("${TESTNUMBERS[@]}" "${SEQUENCE[@]}")
|
|---|
| 36 | fi
|
|---|
| 37 | done
|
|---|
| 38 |
|
|---|
| 39 | IFS=$OLDIFS # Reset the in-field-separator
|
|---|
| 40 |
|
|---|
| 41 | # Include necessary functions and constants
|
|---|
| 42 | cat << EOF
|
|---|
| 43 | window.jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000; // Change timeout for Jasmine tests
|
|---|
| 44 | var AJAX_TIMEOUT = 5000;
|
|---|
| 45 | function onAjaxSuccess(data, status, jqxhr) {
|
|---|
| 46 | console.log("Success");
|
|---|
| 47 | }
|
|---|
| 48 | function onAjaxError(jqxhr, status, err) {
|
|---|
| 49 | console.log("Unexpected error: " + err);
|
|---|
| 50 | }
|
|---|
| 51 | EOF
|
|---|
| 52 |
|
|---|
| 53 | # Create stubs for individual tests
|
|---|
| 54 | for num in ${TESTNUMBERS[@]}; do
|
|---|
| 55 | cat << EOF
|
|---|
| 56 | describe("test$num", function() {
|
|---|
| 57 | it("contains test$num", function(done) {
|
|---|
| 58 | $.ajax({
|
|---|
| 59 | url: 'http://localhost:8080/test$num.js',
|
|---|
| 60 | dataType: 'script',
|
|---|
| 61 | success: onAjaxSuccess,
|
|---|
| 62 | error: onAjaxError,
|
|---|
| 63 | complete: function(jqxhr, status) { done(); },
|
|---|
| 64 | timeout: AJAX_TIMEOUT
|
|---|
| 65 | });
|
|---|
| 66 | });
|
|---|
| 67 | });
|
|---|
| 68 | EOF
|
|---|
| 69 | done
|
|---|