Skip to content

Commit b349d46

Browse files
committed
Script running Android tests with the karma runner.
1 parent 37cf35f commit b349d46

File tree

5 files changed

+114
-0
lines changed

5 files changed

+114
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ tags
44
src/nativescript-angular/**/*.js
55
.baseDir.ts
66
.tscache
7+
.nvm
78

89
tests/app/**/*.js
10+
tests/test-output.txt
911
tests/app/nativescript-angular
1012
tests/app/global.d.ts
1113
tests/platforms

build/run-tests.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/sh
2+
set -e
3+
4+
SCRIPT=$(readlink -f "$0")
5+
BUILD_DIR=$(dirname $SCRIPT)
6+
PROJECT_DIR=$(dirname $BUILD_DIR)
7+
8+
$PROJECT_DIR/build/start-android-emulator.sh &
9+
EMULATOR_STARTER_PID=$!
10+
11+
. $PROJECT_DIR/build/tns.sh
12+
13+
activate_node_env
14+
15+
cd "$PROJECT_DIR/tests"
16+
17+
npm install
18+
rm -rf platforms/android
19+
tns platform add android
20+
21+
wait $EMULATOR_STARTER_PID
22+
tns test android | tee test-output.txt
23+
24+
if grep -q -E 'Executed[[:space:]][[:digit:]]+.*FAILED' test-output.txt ; then
25+
echo "TESTS FAILED!"
26+
exit 1
27+
else
28+
echo "TESTS SUCCEEDED."
29+
exit 0
30+
fi

build/start-android-emulator.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/sh
2+
set -e
3+
4+
wait_for_emulator() {
5+
adb wait-for-device
6+
7+
A=$(adb shell getprop sys.boot_completed | tr -d '\r')
8+
9+
while [ "$A" != "1" ]; do
10+
sleep 2
11+
A=$(adb shell getprop sys.boot_completed | tr -d '\r')
12+
done
13+
14+
adb shell input keyevent 82
15+
}
16+
17+
create_emulator() {
18+
echo no | android create avd --force -n Arm19 -t android-19 -b armeabi-v7a
19+
}
20+
21+
start_emulator() {
22+
emulator -avd Arm19 -no-skin -no-audio -no-boot-anim -no-window &
23+
}
24+
25+
create_emulator
26+
start_emulator
27+
wait_for_emulator

build/tns.sh

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/bin/sh
2+
set -e
3+
4+
export NVM_REPO="https://github.com/creationix/nvm.git"
5+
export NVM_DIR="$(pwd)/.nvm"
6+
export NODE_VER="v5.5.0"
7+
8+
install_nvm() {
9+
if [ ! -d "$NVM_DIR" ] ; then
10+
git clone --depth=1 $NVM_REPO $NVM_DIR
11+
else
12+
echo "NVM detected at $NVM_DIR"
13+
fi
14+
}
15+
16+
activate_nvm() {
17+
. "$NVM_DIR/nvm.sh"
18+
}
19+
20+
installed_under_nvm() {
21+
which $1 | grep -q "$NVM_DIR"
22+
}
23+
24+
install_node() {
25+
nvm install $NODE_VER
26+
nvm use $NODE_VER
27+
}
28+
29+
30+
install_latest_tns() {
31+
if installed_under_nvm tns ; then
32+
echo "tns already installed."
33+
else
34+
echo "n" | npm install -g nativescript
35+
fi
36+
}
37+
38+
activate_node_env() {
39+
install_nvm
40+
activate_nvm
41+
install_node
42+
install_latest_tns
43+
}

build/wait-for-emulator.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/sh
2+
3+
adb wait-for-device
4+
5+
A=$(adb shell getprop sys.boot_completed | tr -d '\r')
6+
7+
while [ "$A" != "1" ]; do
8+
sleep 2
9+
A=$(adb shell getprop sys.boot_completed | tr -d '\r')
10+
done
11+
12+
adb shell input keyevent 82

0 commit comments

Comments
 (0)