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