This repository has been archived by the owner on Oct 7, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
run-tests.sh
executable file
·66 lines (52 loc) · 1.39 KB
/
run-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
#!/bin/bash
#
# Script to run unit tests on code. Unit tests are created in Mocha:
# https://mochajs.org/
#
##### INSTALLATION ######
# Set env variables for eslint and mocha
cd "$(git rev-parse --show-toplevel)"
ESLINT="node_modules/.bin/eslint"
MOCHA="node_modules/.bin/mocha"
pwd
# Ensure eslint is installed
if [[ ! -x "$ESLINT" ]]; then
printf "\t\033[41mPlease install ESlint\033[0m (npm install eslint)\n"
exit 1
fi
# Review staged files
STAGED_FILES=($(git diff --cached --name-only --diff-filter=ACM | grep ".jsx\{0,1\}$"))
##### MOCHA / JS UNIT TESTS #####
# Counters for failed tests and lints
testFailed=0
lintFailed=0
# Run Mocha tests
$MOCHA --compilers js:babel-core/register test --recursive
if [[ $? != 0 ]] ; then
testFailed=1
fi
if [[ $testFailed == 0 ]]; then
printf "\n\033[42mAll test passed\033[0m\n"
printf "\n\033[42mCOMMIT SUCCEEDED\033[0m\n"
exit 0
else
printf "\n\033[41mCOMMIT FAILED:\033[0m Fix tests and try again\n"
exit 1
fi
# Run linting
echo "ESLint'ing ${#STAGED_FILES[@]} files"
if [[ "$STAGED_FILES" = "" ]]; then
exit 0
fi
for file in ${STAGED_FILES}; do
git show :$file | $ESLINT --stdin --stdin-filename "$file"
if [[ $? != 0 ]] ; then
lintFailed=1
fi
done;
if [[ $lintFailed == 0 ]]; then
printf "\n\033[42mJsLint Successfull\033[0m\n"
else
printf "\n\033[41mCOMMIT FAILED:\033[0m Fix eslint errors and try again\n"
exit 1
fi