forked from privly/privly-jetpack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_test.sh
executable file
·68 lines (55 loc) · 1.62 KB
/
run_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
# Runs the Jetpack extension unit tests.
# Check for dependencies
if ! [ -f node/node_modules/istanbul/lib/cli.js ]; then
echo "You need to have 'istanbul' installed to run the tests."
echo "Run 'npm install' inside the 'node' directory."
exit 1
fi
# Start node server
node node/server.js &
if [ -z "$TRAVIS" ]; then
# Local Env
echo "Local Environment"
export JPM_FIREFOX_BINARY=`which firefox`
else
# Travis CI
echo "Travis CI"
export JPM_FIREFOX_BINARY=$TRAVIS_BUILD_DIR/../firefox/firefox
fi
current_dir=`pwd`
current_dir+="/"
# Remove all changes made to test.json.
git checkout test.json
sed -i "s:replace_with_path:$current_dir:g" test.json
# Generate the instrumented files
node/node_modules/istanbul/lib/cli.js instrument lib/ -o lib/instrument/
# All instrumented files end with .in.js and are placed in lib/
for f in lib/instrument/*; do
filename=${f##*/}
# Splits the file based on '.' delimiter
array=(${filename//\./ })
name=${array[0]}
cp lib/instrument/$filename lib/$name.in.js
done
# Run the tests, Save the output
jpm --prefs test.json run | tee test.output
# Check for test failure,
# Set the exit status accordingly.
isFail=`grep "FAILURE" test.output`
rm test.output
if [ ! -z "$isFail" ]; then
echo "You have some work to do: tests are failing."
exit 1
fi
# Cleanup
# Remove the instrumented files
rm lib/*.in.js
rm -r lib/instrument/
# Remove all changes made to test.json.
git checkout test.json
# Don't post the coverage info to coveralls when run locally
if ! [ -z "$TRAVIS" ]; then
cat coverage/lcov.info | node/node_modules/coveralls/bin/coveralls.js
fi
killall -9 node
exit 0