-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.sh
executable file
·169 lines (134 loc) · 5.1 KB
/
test.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#!/usr/bin/env sh
set +o verbose
# Usage:
# ------
# FIXME: Document this testing script.
#
# Mostly copied from Paws.js and/or mocha-before-this:
# <https://github.com/ELLIOTTCABLE/Paws.js/blob/6f77f3e1/Scripts/test.sh>
# <https://github.com/ELLIOTTCABLE/mocha-before-this/blob/e8450e82/test.sh>
puts() { printf %s\\n "$@" ;}
pute() { printf %s\\n "~~ $*" >&2 ;}
argq() { [ $# -gt 0 ] && printf "'%s' " "$@" ;}
source_dir="$npm_package_directories_src"
unit_dir="$npm_package_directories_test"
coverage_dir="$npm_package_directories_coverage"
mocha_ui="$npm_package_mocha_ui"
mocha_reporter="$npm_package_mocha_reporter"
# FIXME: This should support *excluded* modules with a minus, as per `node-debug`:
# https://github.com/visionmedia/debug
if echo "$DEBUG" | grep -qE '(^|,\s*)(\*|giraphe(:(scripts|\*))?)($|,)'; then
pute "Script debugging enabled (in: `basename $0`)."
DEBUG_SCRIPTS=yes
VERBOSE="${VERBOSE:-7}"
fi
# Configuration-variable setup
# ----------------------------
[ -z "${SILENT##[NFnf]*}${QUIET##[NFnf]*}" ] && [ "${VERBOSE:-4}" -gt 6 ] && print_commands=yes
if [ -n "${CI##[NFnf]*}" ]; then
pute "Detected CI environment"
ci=yes
DEBUG_SCRIPTS=yes
DEBUGGER='no'
WATCH='no'
export PERMUTATE='yes'
if [ -n "${CI_PREP##[NFnf]*}" ]; then
pute "Building."
npm run-script prepare
if [ -n "${COVERAGE##[NFnf]*}" ]; then
pute "Installing 'codecov' package."
npm install 'codecov@^2.2.0'
fi
exit 0
fi
fi
if [ -n "${DEBUGGER##[NFnf]*}" ]; then
# FIXME: This should require node-debug when the *current version* of Node is old enough
#[ ! -x "./node_modules/.bin/node-debug" ] && \
# pute 'You must `npm install node-inspector` to use the $DEBUGGER flag!' && exit 127
WATCH='no'
COVERAGE='no'
invocation_guard="node --inspect --debug-brk"
fi
if [ -n "${WATCH##[NFnf]*}" ]; then
[ ! -x "./node_modules/.bin/chokidar" ] &&
pute 'You must `npm install chokidar-cli` to use the $WATCH flag!' && exit 127
fi
if [ -z "$COVERAGE" ]; then
if [ -x "./node_modules/.bin/nyc" ]; then
COVERAGE='yes'
else
COVERAGE='no'
fi
fi
if [ -n "${COVERAGE##[NFnf]*}" ]; then
[ ! -x "./node_modules/.bin/nyc" ] &&
pute 'You must `npm install nyc` to use the $COVERAGE flag!' && exit 127
coverage=yes
WATCH='no'
export NODE_ENV='coverage'
export PERMUTATE='yes'
if [ -n "$ci" ]; then
invocation_guard="nyc --show-process-tree --reporter none"
else
invocation_guard="nyc --reporter none"
fi
fi
[ -n "$DEBUG_SCRIPTS" ] && puts \
"Permutating tests: ${PERMUTATE:--}" \
"Running on CI: ${CI:--}" \
"Watching filesystem: ${WATCH:--}" \
"Running debugger: ${DEBUGGER:--}" \
"Generating coverage: ${COVERAGE:--}" \
"" \
"Verbosity: '$VERBOSE'" \
"Printing commands: ${print_commands:--}" \
"" \
"Tests directory: '$unit_dir'" \
"Coverage directory: '$coverage_dir'" \
"" >&2
[ -n "$DEBUG_SCRIPTS" ] && [ "${VERBOSE:-4}" -gt 8 ] && \
pute "Environment variables:" && env >&2
# Helper-function setup
# ---------------------
go () { [ -n "$print_commands" ] && puts '`` '"$*" >&2 ; "$@" || exit $? ;}
mochaify() {
[ -z "$coverage" ] && compilers_flag="--compilers js:babel-register"
go $invocation_guard "./node_modules/.bin/${invocation_guard:+_}mocha" \
${invocation_guard:+ --no-timeouts } \
$compilers_flag --reporter "$mocha_reporter" --ui "$mocha_ui" \
"$@" ;}
# Execution of tests
# ------------------
if [ -n "${WATCH##[NFnf]*}" ]; then
[ "${VERBOSE:-4}" -gt 7 ] && chokidar_verbosity='--verbose'
unset WATCH COVERAGE DEBUGGER
export VERBOSE
go exec chokidar \
"${chokidar_verbosity:---silent}" \
--initial --ignore '**/.*' \
"$source_dir" "$unit_dir" \
$CHOKIDAR_FLAGS -c "$0 $(argq "$@")"
fi
if [ -z "$ci" ]; then
puts ">> Rebuilding ..."
go npm --silent run-script prepare
fi
[ -z "$ci" ] && \
puts ">> Running unit tests ..."
mochaify "$unit_dir"/"*.tests.*js" "$@"
if [ -n "$coverage" ]; then
[ -n "$DEBUG_SCRIPTS" ] && \
pute "Generating coverage reports"
if [ -n "$ci" ]; then
nyc report --reporter json
nyc report --reporter text
pute "Uploading to https://Codecov.io"
codecov --disable=gcov -f "$coverage_dir"/coverage-final.json
else
puts ">> Coverage:"
puts ""
nyc report --reporter text-summary | sed '1,2d;$d;s/^/ /'
nyc check-coverage
fi
fi