-
Notifications
You must be signed in to change notification settings - Fork 8k
/
jest_parallel.sh
executable file
·64 lines (51 loc) · 1.69 KB
/
jest_parallel.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
#!/bin/bash
set -euo pipefail
export JOB=$BUILDKITE_PARALLEL_JOB
# a jest failure will result in the script returning an exit code of 10
exitCode=0
results=()
if [[ "$1" == 'jest.config.js' ]]; then
TEST_TYPE="unit"
else
TEST_TYPE="integration"
fi
export TEST_TYPE
echo "--- downloading jest test run order"
buildkite-agent artifact download jest_run_order.json .
configs=$(jq -r 'getpath([env.TEST_TYPE]) | .groups[env.JOB | tonumber].names | .[]' jest_run_order.json)
while read -r config; do
echo "--- $ node scripts/jest --config $config --coverage --coverageReporters json --coverageDirectory target/kibana-coverage/jest"
start=$(date +%s)
# prevent non-zero exit code from breaking the loop
set +e
NODE_OPTIONS="--max-old-space-size=14336" node ./scripts/jest \
--config="$config" --runInBand --ci --coverage \
--coverageReporters json --passWithNoTests \
--coverageDirectory target/kibana-coverage/jest
lastCode=$?
set -e
if [[ -f "target/kibana-coverage/jest/coverage-final.json" ]]; then
echo "Rename coverage-final.json to avoid overwrite"
mv target/kibana-coverage/jest/coverage-final.json "./target/kibana-coverage/jest/coverage-$(date +%s%3N).json"
else
echo "Cannot find coverage-final.json"
fi
timeSec=$(($(date +%s) - start))
if [[ $timeSec -gt 60 ]]; then
min=$((timeSec / 60))
sec=$((timeSec - (min * 60)))
duration="${min}m ${sec}s"
else
duration="${timeSec}s"
fi
results+=("- $config
duration: ${duration}
result: ${lastCode}")
if [ $lastCode -ne 0 ]; then
echo "Jest exited with code $lastCode"
echo "^^^ +++"
fi
done <<<"$configs"
echo "--- Jest configs complete"
printf "%s\n" "${results[@]}"
echo ""