source: issm/trunk-jpl/jenkins/javascript/karma/scripts/specs/generate-spec.sh@ 20783

Last change on this file since 20783 was 20783, checked in by ayfeng, 9 years ago

Add usage message and error handling for spec generation script

  • Property svn:executable set to *
File size: 1.8 KB
Line 
1#!/bin/sh
2
3if [ -z $1 ]; then
4 echo "Usage: $0 [NUMBER[-NUMBER]][,NUMBER[-NUMBER]]..."
5 exit 1
6fi
7
8# Create array to store numbers of the tests
9TESTNUMBERS=()
10
11# Location of test scripts
12SCRIPTDIR=$ISSM_DIR/jenkins/javascript/karma/scripts
13
14OLDIFS=$IFS
15IFS=, # Overwrite the in-field-separator to detect ranges of numbers as numbers separated by commas
16
17# Add the test numbers to the array
18for 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
37done
38
39IFS=$OLDIFS # Reset the in-field-separator
40
41# Include necessary functions and constants
42cat << EOF
43window.jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000; // Change timeout for Jasmine tests
44var AJAX_TIMEOUT = 5000;
45function onAjaxSuccess(data, status, jqxhr) {
46 console.log("Success");
47}
48function onAjaxError(jqxhr, status, err) {
49 console.log("Unexpected error: " + err);
50}
51EOF
52
53# Create stubs for individual tests
54for num in ${TESTNUMBERS[@]}; do
55cat << EOF
56describe("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});
68EOF
69done
Note: See TracBrowser for help on using the repository browser.