forked from jchavarri/graphql-ppx
-
Notifications
You must be signed in to change notification settings - Fork 2
/
tests.sh
executable file
·78 lines (63 loc) · 2.32 KB
/
tests.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
#!/bin/bash
# setopt extendedglob
function snapshotGeneratePath {
echo "$(dirname $1)/expected/$2/generate/$(basename $1).txt"
}
function snapshotCompilePath {
echo "$(dirname $1)/expected/$2/compile/$(basename $1).txt"
}
function snapshotErrorPath {
echo "$(dirname $1)/expected/$(basename $1).txt"
}
taskCount=0
function maybeWait {
let taskCount+=1
# spawn in batch of 20 processes
[[ $((taskCount % 20)) = 0 ]] && printf "." && wait
}
case $(uname) in
Darwin) platform=darwin;;
Linux) platform=linux;;
Windows) platform=win32;;
*)
echo "Unknown OS: $uname"
exit 1
esac
refmt_path="./node_modules/rescript/${platform}/refmt.exe"
ppx_path="./_build/default/src/bin/bin.exe"
bsb_path="./node_modules/rescript/${platform}/bsc.exe"
declare -a configs=('records' 'template' 'apollo' 'native')
rm -rf snapshot_tests/operations/expected/
rm -rf snapshot_tests/operations/error/expected/
for config in "${configs[@]}"; do
case $config in
"records" ) opts="" ;;
"template") opts="-template-tag-location=gql" ;;
"apollo" ) opts="-apollo-mode" ;;
"native" ) opts="-native" ;;
esac
mkdir -p snapshot_tests/operations/expected/$config/generate
mkdir -p snapshot_tests/operations/expected/$config/compile
mkdir -p snapshot_tests/operations/errors/expected
for file in snapshot_tests/operations/*.re; do
$refmt_path --parse=re --print=binary $file | $ppx_path -schema=graphql_schema.json $opts /dev/stdin /dev/stdout | $refmt_path --parse=binary &> $(snapshotGeneratePath $file $config) & maybeWait
if [[ $config != "native" ]]; then
$bsb_path -I ./utilities -w -30 -ppx "$ppx_path -schema=graphql_schema.json $opts" $file &> $(snapshotCompilePath $file $config) & maybeWait
fi
done
done
for file in snapshot_tests/operations/errors/*.re; do
$bsb_path -I ./utilities -w -30 -ppx "$ppx_path -schema=graphql_schema.json" $file 2> $(snapshotErrorPath $file $config) 1> /dev/null & maybeWait
done
wait
warningYellow='\033[0;33m'
successGreen='\033[0;32m'
reset='\033[0m'
diff=$(git ls-files --modified snapshot_tests/operations/*expected/*.txt)
printf "\033[2K\r"
if [[ $diff = "" ]]; then
printf "${successGreen}✅ No unstaged tests difference.${reset}\n"
else
printf "${warningYellow}⚠️ There are unstaged differences in tests! Did you break a test?\n${diff}\n${reset}"
exit 1
fi