Skip to content

Commit da00c3a

Browse files
committed
fix(android): stabilize runtime test harness
1 parent 86dec82 commit da00c3a

7 files changed

Lines changed: 53 additions & 22 deletions

File tree

platforms/android/test-app/app/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ android {
225225

226226
compileSdk computeCompileSdkVersion()
227227
buildToolsVersion = computeBuildToolsVersion()
228+
ndkVersion = project.findProperty("ndkVersion") ?: "27.1.12297006"
228229

229230
defaultConfig {
230231
def manifest = new XmlSlurper().parse(file(android.sourceSets.main.manifest.srcFile))

platforms/android/test-app/app/src/main/assets/app/Infrastructure/Jasmine/jasmine-2.0.1/boot.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ var TerminalReporter = require('../jasmine-reporters/terminal_reporter').Termina
137137
verbosity: 5
138138
}));
139139

140-
// env.addReporter(new JUnitXmlReporter());
140+
env.addReporter(new JUnitXmlReporter());
141141

142142
env.specFilter = function(spec) {
143143
return true;

platforms/android/test-app/app/src/main/assets/app/Infrastructure/Jasmine/jasmine-reporters/junit_reporter.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,12 @@
206206

207207
// Attempt writing with each possible environment.
208208
// Track errors in case no write succeeds
209+
try {
210+
if (typeof __JUnitSaveResults === "function") {
211+
__JUnitSaveResults(text);
212+
return;
213+
}
214+
} catch (f) { errors.push(' tns-android attempt: ' + f.message); }
209215
try {
210216
phantomWrite(path, filename, text);
211217
return;
@@ -214,10 +220,6 @@
214220
nodeWrite(path, filename, text);
215221
return;
216222
} catch (f) { errors.push(' NodeJS attempt: ' + f.message); }
217-
try {
218-
__JUnitSaveResults(text);
219-
return;
220-
} catch (f) { errors.push(' tns-android attempt: ' + f.message); }
221223

222224
// If made it here, no write succeeded. Let user know.
223225
log("Warning: writing junit report failed for '" + path + "', '" +

platforms/android/test-app/app/src/main/assets/app/MyActivity.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ var MyActivity = (function (_super) {
3131
_super.prototype.onCreate.call(this, bundle);
3232
require('./tests/testsWithContext').run(this);
3333
//run jasmine
34-
// execute();
34+
execute();
3535
var layout = new android.widget.LinearLayout(this);
3636
layout.setOrientation(1);
3737
this.setContentView(layout);

platforms/android/test-app/runtests.gradle

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,21 @@ def getBuildArguments = { ->
3131
arguments.add("./gradlew")
3232
}
3333
arguments.add(":app:installDebug")
34+
if (project.hasProperty("engine")) {
35+
arguments.add("-Pengine=${engine}")
36+
if (!project.hasProperty("ns_engine")) {
37+
arguments.add("-Pns_engine=${engine}")
38+
}
39+
}
40+
if (project.hasProperty("ns_engine")) {
41+
arguments.add("-Pns_engine=${ns_engine}")
42+
}
43+
if (project.hasProperty("ndkDirectory")) {
44+
arguments.add("-PndkDirectory=${ndkDirectory}")
45+
}
46+
if (project.hasProperty("ndkVersion")) {
47+
arguments.add("-PndkVersion=${ndkVersion}")
48+
}
3449
if (onlyX86) {
3550
arguments.add("-PonlyX86")
3651
}
@@ -50,14 +65,26 @@ task installApk(type: Exec) {
5065
}
5166
}
5267

68+
task clearInstalledAppData(type: Exec) {
69+
doFirst {
70+
println "Clearing test application data"
71+
72+
if (isWinOs) {
73+
commandLine "cmd", "/c", "adb", runOnDeviceOrEmulator, "shell", "pm", "clear", "com.tns.testapplication"
74+
} else {
75+
commandLine "adb", runOnDeviceOrEmulator, "shell", "pm", "clear", "com.tns.testapplication"
76+
}
77+
}
78+
}
79+
5380
task runAdbAsRoot(type: Exec) {
5481
doFirst {
5582
println "Running adb as root"
5683

5784
if (isWinOs) {
58-
commandLine "cmd", "/c", "adb", "-e", "root"
85+
commandLine "cmd", "/c", "adb", runOnDeviceOrEmulator, "root"
5986
} else {
60-
commandLine "adb", "-e", "root"
87+
commandLine "adb", runOnDeviceOrEmulator, "root"
6188
}
6289
sleep(10 * 1000) // wait 10s to make sure adb properly restarts, otherwise error: closed might happen on next command
6390
}
@@ -68,9 +95,9 @@ task deletePreviousResultXml(type: Exec) {
6895
println "Removing previous android_unit_test_results.xml"
6996

7097
if (isWinOs) {
71-
commandLine "cmd", "/c", "adb", runOnDeviceOrEmulator, "-e", "shell", "rm", "-rf", "/data/data/com.tns.testapplication/android_unit_test_results.xml"
98+
commandLine "cmd", "/c", "adb", runOnDeviceOrEmulator, "shell", "rm", "-rf", "/data/data/com.tns.testapplication/android_unit_test_results.xml"
7299
} else {
73-
commandLine "adb", runOnDeviceOrEmulator, "-e", "shell", "rm", "-rf", "/data/data/com.tns.testapplication/android_unit_test_results.xml"
100+
commandLine "adb", runOnDeviceOrEmulator, "shell", "rm", "-rf", "/data/data/com.tns.testapplication/android_unit_test_results.xml"
74101
}
75102
}
76103
}
@@ -80,9 +107,9 @@ task startInstalledApk(type: Exec) {
80107
println "Starting test application"
81108

82109
if (isWinOs) {
83-
commandLine "cmd", "/c", "adb", runOnDeviceOrEmulator, "-e", "shell", "am", "start", "-n", "com.tns.testapplication/com.tns.NativeScriptActivity", "-a", "android.intent.action.MAIN", "-c", "android.intent.category.LAUNCHER"
110+
commandLine "cmd", "/c", "adb", runOnDeviceOrEmulator, "shell", "am", "start", "-n", "com.tns.testapplication/com.tns.NativeScriptActivity", "-a", "android.intent.action.MAIN", "-c", "android.intent.category.LAUNCHER"
84111
} else {
85-
commandLine "adb", runOnDeviceOrEmulator, "-e", "shell", "am", "start", "-n", "com.tns.testapplication/com.tns.NativeScriptActivity", "-a", "android.intent.action.MAIN", "-c", "android.intent.category.LAUNCHER"
112+
commandLine "adb", runOnDeviceOrEmulator, "shell", "am", "start", "-n", "com.tns.testapplication/com.tns.NativeScriptActivity", "-a", "android.intent.action.MAIN", "-c", "android.intent.category.LAUNCHER"
86113
}
87114
}
88115
}
@@ -133,7 +160,8 @@ task runtests {
133160
runAdbAsRoot.dependsOn(waitForEmulatorToStart)
134161
deletePreviousResultXml.dependsOn(runAdbAsRoot)
135162
installApk.dependsOn(deletePreviousResultXml)
136-
startInstalledApk.dependsOn(installApk)
163+
clearInstalledAppData.dependsOn(installApk)
164+
startInstalledApk.dependsOn(clearInstalledAppData)
137165
createDistFolder.dependsOn(startInstalledApk)
138166
waitForUnitTestResultFile.dependsOn(createDistFolder)
139167
copyResultToDist.dependsOn(waitForUnitTestResultFile)
@@ -142,4 +170,4 @@ verifyResults.dependsOn(runtests)
142170

143171
task runtestsAndVerifyResults {
144172
dependsOn verifyResults
145-
}
173+
}

platforms/android/test-app/runtime/build.gradle

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,7 @@ android {
101101
}
102102
}
103103

104-
if (hasNdkVersion) {
105-
ndkVersion ndkVersion
106-
} else {
107-
ndkVersion defaultNdkVersion
108-
}
104+
ndkVersion = project.findProperty("ndkVersion") ?: defaultNdkVersion
109105

110106
defaultConfig {
111107
minSdkVersion NS_DEFAULT_MIN_SDK_VERSION as int

platforms/android/test-app/tools/try_to_find_test_result_file.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@ function closeProcessAfter(timeout) {
2525
}
2626

2727
function tryToGetFile() {
28-
var checkApp = checkIfAppIsRunning("adb " + runOnDeviceOrEmulator + " -e shell \"ps | grep com.tns.testapplication\"", checkIfProcessIsRunning);
29-
pullfile = execFindFile("adb " + runOnDeviceOrEmulator + " -e pull /data/data/com.tns.testapplication/android_unit_test_results.xml", checkIfFileExists);
28+
var adbTarget = "adb " + runOnDeviceOrEmulator;
29+
pullfile = execFindFile(adbTarget + " pull /data/data/com.tns.testapplication/android_unit_test_results.xml", function (err, stout, stderr) {
30+
checkIfFileExists(err, stout, stderr, adbTarget);
31+
});
3032
pullfile.stdout.pipe(process.stdout, { end: false });
3133
pullfile.stderr.pipe(process.stderr, { end: false });
3234
}
@@ -42,7 +44,7 @@ function checkIfProcessIsRunning(err, stdout, stderr) {
4244

4345
}
4446

45-
function checkIfFileExists(err, stout, stderr) {
47+
function checkIfFileExists(err, stout, stderr, adbTarget) {
4648

4749
//if you find file in /data/data/com.tns.testapplication exit process
4850
if (!err) {
@@ -56,5 +58,7 @@ function checkIfFileExists(err, stout, stderr) {
5658
console.log('Tests results file not found!');
5759
process.exit(1);
5860
}
61+
62+
checkIfAppIsRunning(adbTarget + " shell \"pidof com.tns.testapplication || ps -A | grep com.tns.testapplication\"", checkIfProcessIsRunning);
5963
}
6064
}

0 commit comments

Comments
 (0)