forked from bem-node/bem-node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.sh
executable file
·124 lines (119 loc) · 2.75 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
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
#!/bin/bash
MOCHA='./node_modules/.bin/mocha -R spec'
PHANTOM='./node_modules/.bin/mocha-phantomjs --web-security=false http://127.0.0.1:3000/'
ENB=./node_modules/.bin/enb
JSHINT=./node_modules/.bin/jshint
RUN_CLIENT=
RUN_SERVER=
RUN_LINT=
TEST_NAME=
function checkfail {
EXIT_CODE=$1
if [ $EXIT_CODE -gt 0 ]; then
exit $EXIT_CODE;
fi
}
function kn {
killall node 2>/dev/null
}
function client {
echo Client tests
if [ $1 ]; then
kn
node tests/$1/$1.server.js & $PHANTOM
else
for D in `find tests/*/*server.js -type f`; do
echo " Testing $D"
kn
node $D & $PHANTOM
checkfail $?
done
fi;
}
function server {
echo Server tests
if [ $1 ]; then
kn
$MOCHA tests/$1/$1.server.tests.js
else
for D in `find tests/*/*server.tests.js -type f`; do
echo " Testing $D"
kn
$MOCHA $D
checkfail $?
done
fi
}
function coverage {
for D in `find tests/*/*server.tests.js -type f`; do
killall node 2>/dev/null
$MOCHA -R html-cov --require blanket $D > coverage.html
echo $ open coverage.html
done
}
function lint {
find blocks tests.blocks -type f | grep -vEe 'deps.js' | xargs $JSHINT 1>&2
}
if [ $1 ]; then
while test $# -gt 0; do
case "$1" in
-n|--name)
if [[ $2 =~ ^[a-z\-]+$ ]]; then
TEST_NAME=$2;
else
echo "Use: -n <name-of-test>"
fi;
shift;
;;
-g|--grep)
if [[ $2 =~ ^[^\-].*$ ]]; then
MOCHA="$MOCHA -g $2";
PHANTOM="$PHANTOM?grep=$2"
else
echo "Use: -g <grep>"
fi;
shift;
;;
--coverage)
coverage
;;
-l|--lint|--jslint)
#lint;
RUN_LINT=true;
;;
-c|--client)
#client
RUN_CLIENT=true;
;;
-s|--server)
RUN_SERVER=true;
#server
;;
-b|--build)
RUN_MAKE=true;
;;
*)
echo Unknown option: "$1"
echo "Use: -c (--client) -s (--server) -b (--build)"
;;
esac;
shift;
done;
else
RUN_LINT=false
RUN_CLIENT=true
RUN_SERVER=true
RUN_MAKE=true
fi;
if [ $RUN_LINT ]; then
lint;
fi;
if [ $RUN_MAKE ]; then
$ENB make;
fi;
if [ $RUN_CLIENT ]; then
client $TEST_NAME
fi;
if [ $RUN_SERVER ]; then
server $TEST_NAME
fi;