/
runScreenshotTests
executable file
·76 lines (63 loc) · 1.59 KB
/
runScreenshotTests
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
#!/usr/bin/env bash
#
# This script runs screenshot tests to check if pages render identically at
# a local development server and the production server.
#
# Usage:
# ./runScreenshotTests [target_paths ...]
#
# If no target paths are specified, the script will run tests for all valid
# target paths.
#
set -e
trap "exit" INT TERM
bold_green() {
echo -e "\033[1;32m"${@}"\033[0m"
}
bold_red() {
echo -e "\033[1;31m"${@}"\033[0m"
}
magenta() {
echo -e "\033[0;35m"${@}"\033[0m"
}
gray() {
echo -e "\033[0;37m"${@}"\033[0m"
}
viewport_widths=(320 1024)
if [ $# -eq 0 ]
then
num_posts=$(ls src/posts/*.vue | wc -l)
target_paths=(/ /$(seq -s " /" 1 $num_posts))
else
target_paths=("$@")
fi
failed_tests=()
for target_path in "${target_paths[@]}"
do
for viewport_width in "${viewport_widths[@]}"
do
test_details="Target path: $(magenta $target_path) | "
test_details+="Viewport width: $(magenta $viewport_width)"
echo -en "[$(gray ....)] ${test_details} "
PUPPETEER_EXECUTABLE_PATH=`which chromium` \
PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true \
./comparePages $target_path $viewport_width && {
echo -e "\r[$(bold_green PASS)] ${test_details}"
} || {
echo -e "\r[$(bold_red FAIL)] ${test_details}"
failed_tests+=("$test_details")
}
done
done
num_failed_tests=${#failed_tests[@]}
if [ $num_failed_tests -gt 0 ]
then
echo -e "\nThe following ${num_failed_tests} tests have $(bold_red failed):\n"
for failed_test in "${failed_tests[@]}"
do
echo " - ${failed_test}"
done
exit 1
else
echo -e "\n$(bold_green SUCCESS): All tests passed!"
fi