-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathflake.sh
executable file
·80 lines (64 loc) · 1.84 KB
/
flake.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/bin/bash
source ./print_frequency_table.sh
# Default values
jest_script="npm run test -- --json"
iterations=100
save_outputs=false
directory="."
# Parse options
while getopts ":s:i:d:jh" opt; do
case $opt in
h)
echo "Usage: $0 [-s jest_script] [-i iterations] [-j] [-h]"
echo " -s: Specify the jest test script (default: npm run test -- --json)"
echo " -i: Specify the number of test iterations (default: 100)"
echo " -j: Save jest --json outputs (default: false)"
echo " -d: Specify the directory to run the test script (default: current directory)"
echo " -h: Display this help message"
exit 0
;;
s)
jest_script="$OPTARG"
;;
i)
iterations="$OPTARG"
;;
j)
save_outputs=true
;;
d)
directory="$OPTARG"
;;
\?)
echo "Invalid option: -$OPTARG" >&2
exit 1
;;
:)
echo "Option -$OPTARG requires an argument." >&2
exit 1
;;
esac
done
failures=()
echo "jest test script: $jest_script"
echo "number of iterations: $iterations"
echo "running test command in: $directory"
echo "saving jest --json files: $save_outputs"
# Run test suite and collect failures
cd $directory
for ((i = 1; i <= $iterations; i++)); do
echo "Running Jest test suite, iteration $i ..."
jest_output=$($jest_script | tail -n +5)
if [ "$save_outputs" = true ]; then
output_file="test_results_$i.json"
echo "$jest_output" >$output_file
fi
if echo "$jest_output" | jq -e '.testResults[].assertionResults[] | select(.status=="failed")' >/dev/null; then
failing_tests=$(echo "$jest_output" | jq -r '.testResults[].assertionResults[] | select(.status=="failed") | .fullName')
readarray -t failing_tests_collection <<<"$failing_tests"
for failure in "${failing_tests_collection[@]}"; do
failures+=("$failure")
done
fi
done
print_frequency_table "${failures[@]}"