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

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

Add script for generating test spec file

  • Property svn:executable set to *
File size: 1.4 KB
Line 
1#!/bin/sh
2
3# Create array to store numbers of the tests
4TESTNUMBERS=()
5
6# Location of test scripts
7SCRIPTDIR=$ISSM_DIR/jenkins/javascript/karma/scripts
8
9OLDIFS=$IFS
10IFS=, # Overwrite the in-field-separator to detect ranges of numbers as numbers separated by commas
11
12# Add the test numbers to the array
13for 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
20done
21
22IFS=$OLDIFS # Reset the in-field-separator
23
24# Include necessary functions and constants
25cat << EOF
26window.jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000; // Change timeout for Jasmine tests
27var AJAX_TIMEOUT = 5000;
28function onAjaxSuccess(data, status, jqxhr) {
29 console.log("Success");
30}
31function onAjaxError(jqxhr, status, err) {
32 console.log("Unexpected error: " + err);
33}
34EOF
35
36# Create stubs for individual tests
37for num in ${TESTNUMBERS[@]}; do
38cat << EOF
39describe("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});
51EOF
52done
Note: See TracBrowser for help on using the repository browser.