forked from rero/rero-ils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcypress
executable file
·104 lines (87 loc) · 2.43 KB
/
cypress
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/usr/bin/env bash
# -*- coding: utf-8 -*-
#
# RERO ILS
# Copyright (C) 2019 RERO
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, version 3 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
NC='\033[0m' # Default color
INFO_COLOR='\033[1;97;44m' # Bold + white + blue background
SUCCESS_COLOR='\033[1;97;42m' # Bold + white + green background
ERROR_COLOR='\033[1;97;41m' # Bold + white + red background
DIR="$(cd "$(dirname "$0")" >/dev/null 2>&1 && pwd)"
PROGRAM=`basename $0`
set -e
# MESSAGES
msg() {
echo -e "${1}" 1>&2
}
# Display a colored message
# More info: https://misc.flogisoft.com/bash/tip_colors_and_formatting
# $1: choosen color
# $2: title
# $3: the message
colored_msg() {
msg "${1}[${2}]: ${3}${NC}"
}
info_msg() {
colored_msg "${INFO_COLOR}" "INFO" "${1}"
}
error_msg() {
colored_msg "${ERROR_COLOR}" "ERROR" "${1}"
}
error_msg+exit() {
error_msg "${1}" && exit 1
}
success_msg() {
colored_msg "${SUCCESS_COLOR}" "SUCCESS" "${1}"
}
install_cypress() {
info_msg "Install cypress"
npm install --prefix "tests/e2e/cypress"
}
command_exists () {
type "$1" &> /dev/null
}
# Displays program name
msg "PROGRAM: ${PROGRAM}"
set -e
export PATH=${PATH}:${DIR}/../tests/e2e/cypress/node_modules/.bin/
# Manage errors with given options
if ! options=$(getopt -o r -l reinstall -- "$@"); then
error_msg+exit "Error in given options!"
fi
# Manage options
update=false
while test $# -gt 0
do
case "$1" in
-r|--reinstall)
# Update cypress to package.json version
update=true ;;
(--) shift; break;;
(*) break;;
esac
shift
done
# Install cypress if not already done
command_exists "cypress" || install_cypress
export CYPRESS_CMD=`which cypress` \
&& info_msg "Found cypress: $(which cypress)"
# Update cypress with -r parameter
if $update ; then
npm ci --prefix "tests/e2e/cypress"
fi
# Run cypress tests
info_msg "Run e2e tests with cypress"
${CYPRESS_CMD} run -P ./tests/e2e/cypress