From d5d25513d9f14320cbe9b4a45aa49081503d79c0 Mon Sep 17 00:00:00 2001 From: Vladimir Enchev Date: Mon, 5 Oct 2015 11:21:55 +0300 Subject: [PATCH 01/42] tests execution now will start immediately --- apps/tests/app/mainPage.ts | 49 ++++++-------------------------------- 1 file changed, 7 insertions(+), 42 deletions(-) diff --git a/apps/tests/app/mainPage.ts b/apps/tests/app/mainPage.ts index d7be1412c..214ed88c6 100644 --- a/apps/tests/app/mainPage.ts +++ b/apps/tests/app/mainPage.ts @@ -1,50 +1,15 @@ -import pages = require("ui/page"); -import gridModule = require("ui/layouts/grid-layout"); -import tests = require("../testRunner"); -import bm = require("ui/button"); +import tests = require("../testRunner"); import trace = require("trace"); -import textViewModule = require("ui/text-view"); +import {Page} from "ui/page"; +import {GridLayout} from "ui/layouts/grid-layout"; -class MyTraceWriter implements trace.TraceWriter { - public write(message: any, category: string) { - if (textView && message && message.toLowerCase().indexOf("failed") !== -1) { - if (textView.android) { - textView.text = message + "\r\n" + textView.text; - } - else { - textView.text = message + "\n" + textView.text; - } - } - } -} - -trace.addWriter(new MyTraceWriter()); trace.enable(); trace.addCategories(trace.categories.Test + "," + trace.categories.Error); -var textView = new textViewModule.TextView(); -textView.editable = false; -textView.style.fontSize = 8; - export function createPage() { - var button = new bm.Button(); - button.text = "Run Tests"; - button.on(bm.Button.tapEvent, function () { - tests.runAll(); - }); + tests.runAll(); - var grid = new gridModule.GridLayout(); - - grid.addRow(new gridModule.ItemSpec(1, gridModule.GridUnitType.auto)); - grid.addRow(new gridModule.ItemSpec()); - - gridModule.GridLayout.setRow(textView, 1); - - grid.addChild(button); - grid.addChild(textView); - - var page = new pages.Page(); - page.content = grid; + var page = new Page(); + page.content = new GridLayout(); return page; -} -//export var Page = page; +} \ No newline at end of file From 7c691a9365b97f2dc952be34d454e358b6289b6f Mon Sep 17 00:00:00 2001 From: Erjan Gavalji Date: Tue, 6 Oct 2015 13:14:05 +0300 Subject: [PATCH 02/42] Call the commands to run the tests --- expect.exp | 9 +++++++++ gruntfile.js | 26 +++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100755 expect.exp diff --git a/expect.exp b/expect.exp new file mode 100755 index 000000000..cd52e3e24 --- /dev/null +++ b/expect.exp @@ -0,0 +1,9 @@ +#! /usr/bin/expect + +#exp_internal 1 + +set timeout 600 + +spawn grunt +expect "TypeScript compilation complete" +send \003 diff --git a/gruntfile.js b/gruntfile.js index dae465869..1c5e3f259 100644 --- a/gruntfile.js +++ b/gruntfile.js @@ -364,7 +364,27 @@ module.exports = function(grunt) { }, mochaNode: { cmd: "grunt simplemocha:node" - } + }, +// setupTestsApp: { +////TODO: TNS PATH MIGHT GET PASSED FROM OUTSIDE! +// cmd: [ +// "pkill emulator64-arm && true", +// "emulator -avd Api19 -no-skin -no-audio -no-window &", +// "tns create TestsApp", +// "cd TestsApp", +// "rm app/*.*", +// "cp -r " + pathModule.join(localCfg.outAppsDir, "tests") + "/* ./app/", +// "tns platform add android", +// DO THE REPLACEMENTS IN THE Info.plist and AndroidManifest.xml +// "tns build android", +// +// "adb kill-server", +// "adb start-server", +// +// "adb install ./platforms/android/build/outputs/apk/TestsApp-debug.apk", +// "adb shell am start -n org.nativescript.TestsApp/com.tns.NativeScriptActivity", +// "expect -c ' +// } }, multidest: { copyLicenseFiles: { @@ -557,4 +577,8 @@ module.exports = function(grunt) { "env:nodeTests", "exec:mochaNode", //spawn a new process to use the new NODE_PATH ]); + + grunt.registerTask("testsapp", [ + "exec:..." + ]); }; From c23ce6481cb311d4ecc3a5a8e3e701813f983a79 Mon Sep 17 00:00:00 2001 From: Erjan Gavalji Date: Wed, 7 Oct 2015 16:11:07 +0300 Subject: [PATCH 03/42] Make the test run as a bash script first --- expect.exp | 12 +++++++--- gruntfile.js | 17 ++++++++----- runtestsapp.sh | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 85 insertions(+), 9 deletions(-) create mode 100755 runtestsapp.sh diff --git a/expect.exp b/expect.exp index cd52e3e24..7483184b4 100755 --- a/expect.exp +++ b/expect.exp @@ -2,8 +2,14 @@ #exp_internal 1 -set timeout 600 +#set timeout 600 -spawn grunt -expect "TypeScript compilation complete" +#spawn grunt +#expect "TypeScript compilation complete" +#send \003 + + +set timeout 600 +spawn adb logcat +expect 'Done.' send \003 diff --git a/gruntfile.js b/gruntfile.js index 1c5e3f259..e08999367 100644 --- a/gruntfile.js +++ b/gruntfile.js @@ -365,17 +365,21 @@ module.exports = function(grunt) { mochaNode: { cmd: "grunt simplemocha:node" }, + setupTestsApp: { + cmd: "./runtestsapp.sh" + } // setupTestsApp: { ////TODO: TNS PATH MIGHT GET PASSED FROM OUTSIDE! // cmd: [ -// "pkill emulator64-arm && true", -// "emulator -avd Api19 -no-skin -no-audio -no-window &", +// 'pkill ".*emulator64-arm" && true', +// "emulator -avd Api19 -no-skin -no-audio &", +//// "emulator -avd Api19 -no-skin -no-audio -no-window &", // "tns create TestsApp", // "cd TestsApp", // "rm app/*.*", // "cp -r " + pathModule.join(localCfg.outAppsDir, "tests") + "/* ./app/", // "tns platform add android", -// DO THE REPLACEMENTS IN THE Info.plist and AndroidManifest.xml +////TODO: DO THE REPLACEMENTS IN THE Info.plist and AndroidManifest.xml // "tns build android", // // "adb kill-server", @@ -383,8 +387,9 @@ module.exports = function(grunt) { // // "adb install ./platforms/android/build/outputs/apk/TestsApp-debug.apk", // "adb shell am start -n org.nativescript.TestsApp/com.tns.NativeScriptActivity", -// "expect -c ' -// } +//// "expect -c ' + ].join(" && ") + } }, multidest: { copyLicenseFiles: { @@ -579,6 +584,6 @@ module.exports = function(grunt) { ]); grunt.registerTask("testsapp", [ - "exec:..." + "exec:setupTestsApp" ]); }; diff --git a/runtestsapp.sh b/runtestsapp.sh new file mode 100755 index 000000000..1a774fef8 --- /dev/null +++ b/runtestsapp.sh @@ -0,0 +1,65 @@ +workingdir=__TESTSAPP__ +startdir=$(pwd) +rm -rd $workingdir +mkdir $workingdir +cd $workingdir + +#if [ 1 == 2 ] ; then + echo "------------------------------------------------" + echo "Killing the emulator..." + time pkill ".*emulator64-x86" && true + + echo "------------------------------------------------" + echo "Starting the emulator..." + time emulator -avd Api19 -no-skin -no-audio & + #emulator -avd Api19 -no-skin -no-audio -no-window & + + echo "------------------------------------------------" + echo "Creating the app..." + time tns create TestsApp + cd TestsApp + + echo "------------------------------------------------" + echo "Removing the original template files..." + time rm app/*.* + + echo "------------------------------------------------" + echo "Copying the test app files..." + time cp -r ./bin/dist/apps/tests* ./app/ + + echo "------------------------------------------------" + echo "Adding the android platform..." + time tns platform add android + # #DO THE REPLACEMENTS IN THE Info.plist and AndroidManifest.xml + + echo "------------------------------------------------" + echo "Building the application..." + time tns build android + + echo "------------------------------------------------" + echo "Killing the adb server..." + time adb kill-server + + echo "------------------------------------------------" + echo "Starting the adb server..." + time adb start-server + +#fi + +echo "------------------------------------------------" +echo "Uninstalling the app..." +time adb uninstall org.nativescript.TestApp + +echo "------------------------------------------------" +echo "Installing the app..." +time adb install ./platforms/android/build/outputs/apk/TestsApp-debug.apk + +echo "------------------------------------------------" +echo "Starting the app..." +time adb shell am start -n org.nativescript.TestsApp/com.tns.NativeScriptActivity + +cd $startdir + +echo "------------------------------------------------" +echo "Waiting for the tests to finish executing..." +./expect.exp From 0f670c898705f2d0040f0edc149515360a4b27f8 Mon Sep 17 00:00:00 2001 From: Erjan Gavalji Date: Wed, 7 Oct 2015 17:11:17 +0300 Subject: [PATCH 04/42] Fix the grunt file. Fix uninstallation. Add a tee command --- expect.exp | 4 ++-- gruntfile.js | 4 ++-- runtestsapp.sh | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/expect.exp b/expect.exp index 7483184b4..22b575a5c 100755 --- a/expect.exp +++ b/expect.exp @@ -10,6 +10,6 @@ set timeout 600 -spawn adb logcat -expect 'Done.' +spawn adb logcat | tee __TESTRESULT__.txt +expect '=== ALL TESTS COMPLETE ===' send \003 diff --git a/gruntfile.js b/gruntfile.js index e08999367..a616fc8ce 100644 --- a/gruntfile.js +++ b/gruntfile.js @@ -388,8 +388,8 @@ module.exports = function(grunt) { // "adb install ./platforms/android/build/outputs/apk/TestsApp-debug.apk", // "adb shell am start -n org.nativescript.TestsApp/com.tns.NativeScriptActivity", //// "expect -c ' - ].join(" && ") - } +// ].join(" && ") +// } }, multidest: { copyLicenseFiles: { diff --git a/runtestsapp.sh b/runtestsapp.sh index 1a774fef8..37ff0274b 100755 --- a/runtestsapp.sh +++ b/runtestsapp.sh @@ -48,7 +48,7 @@ cd $workingdir echo "------------------------------------------------" echo "Uninstalling the app..." -time adb uninstall org.nativescript.TestApp +time adb uninstall org.nativescript.TestsApp echo "------------------------------------------------" echo "Installing the app..." From 4bad17d3ac76e23a97500906617f41ba785ba801 Mon Sep 17 00:00:00 2001 From: Erjan Gavalji Date: Wed, 7 Oct 2015 17:36:14 +0300 Subject: [PATCH 05/42] Fix app copying --- runtestsapp.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/runtestsapp.sh b/runtestsapp.sh index 37ff0274b..0d157e433 100755 --- a/runtestsapp.sh +++ b/runtestsapp.sh @@ -25,11 +25,11 @@ cd $workingdir echo "------------------------------------------------" echo "Copying the test app files..." - time cp -r ./bin/dist/apps/tests* ./app/ + time cp -r ../../bin/dist/apps/tests/* ./app/ echo "------------------------------------------------" echo "Adding the android platform..." - time tns platform add android + time tns platform add android #--frameworkPath=/Users/erjan/tns-android.tgz # #DO THE REPLACEMENTS IN THE Info.plist and AndroidManifest.xml echo "------------------------------------------------" From ac78de2128dcff79d62c3578272dd2aea63548f4 Mon Sep 17 00:00:00 2001 From: Erjan Gavalji Date: Thu, 8 Oct 2015 15:42:59 +0300 Subject: [PATCH 06/42] Output to a log file. Simulate adjusting the androidmanifest --- apps/tests/app/mainPage.ts | 12 +++++++++--- expect.exp | 4 +++- runtestsapp.sh | 6 +++++- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/apps/tests/app/mainPage.ts b/apps/tests/app/mainPage.ts index 214ed88c6..ddfe17f91 100644 --- a/apps/tests/app/mainPage.ts +++ b/apps/tests/app/mainPage.ts @@ -7,9 +7,15 @@ trace.enable(); trace.addCategories(trace.categories.Test + "," + trace.categories.Error); export function createPage() { - tests.runAll(); +// tests.runAll(); var page = new Page(); - page.content = new GridLayout(); + page.on("navigatedTo", function() { + setTimeout(function() { + tests.runAll(); + }, 3000); + }); +// page.content = new GridLayout(); return page; -} \ No newline at end of file +} + diff --git a/expect.exp b/expect.exp index 22b575a5c..a3abc321c 100755 --- a/expect.exp +++ b/expect.exp @@ -10,6 +10,8 @@ set timeout 600 -spawn adb logcat | tee __TESTRESULT__.txt +#spawn (adb logcat | tee ./__TESTRESULT__.txt) +log_file -noappend ./__TESTRESULT__.txt +spawn adb logcat expect '=== ALL TESTS COMPLETE ===' send \003 diff --git a/runtestsapp.sh b/runtestsapp.sh index 0d157e433..0448201da 100755 --- a/runtestsapp.sh +++ b/runtestsapp.sh @@ -4,6 +4,8 @@ rm -rd $workingdir mkdir $workingdir cd $workingdir +#android create avd -t "android-21" -n Api21 -b "default/x86" + #if [ 1 == 2 ] ; then echo "------------------------------------------------" echo "Killing the emulator..." @@ -11,7 +13,7 @@ cd $workingdir echo "------------------------------------------------" echo "Starting the emulator..." - time emulator -avd Api19 -no-skin -no-audio & + time emulator -avd Api19 -no-skin -no-audio & # -gpu on #emulator -avd Api19 -no-skin -no-audio -no-window & echo "------------------------------------------------" @@ -30,7 +32,9 @@ cd $workingdir echo "------------------------------------------------" echo "Adding the android platform..." time tns platform add android #--frameworkPath=/Users/erjan/tns-android.tgz + # #DO THE REPLACEMENTS IN THE Info.plist and AndroidManifest.xml + cp /Users/erjan/work/spikes/__DEL__/AndroidManifest.xml platforms/android/src/main/ echo "------------------------------------------------" echo "Building the application..." From 77da614b3de8d6674d941904e24d70965bcc317f Mon Sep 17 00:00:00 2001 From: Erjan Gavalji Date: Fri, 9 Oct 2015 10:48:08 +0300 Subject: [PATCH 07/42] Attempt fixing the slow run by changing the main page and removing the noskin in the emulator. Time the expect run --- apps/tests/app/mainPage.ts | 11 ++++------- expect.exp | 2 +- runtestsapp.sh | 5 +++-- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/apps/tests/app/mainPage.ts b/apps/tests/app/mainPage.ts index ddfe17f91..04200e127 100644 --- a/apps/tests/app/mainPage.ts +++ b/apps/tests/app/mainPage.ts @@ -7,15 +7,12 @@ trace.enable(); trace.addCategories(trace.categories.Test + "," + trace.categories.Error); export function createPage() { -// tests.runAll(); - var page = new Page(); - page.on("navigatedTo", function() { - setTimeout(function() { + var navigatedToHandler = function() { tests.runAll(); - }, 3000); - }); -// page.content = new GridLayout(); + page.off("navigatedTo", navigatedToHandler); + }; + page.on("navigatedTo", navigatedToHandler); return page; } diff --git a/expect.exp b/expect.exp index a3abc321c..ebbd5ea98 100755 --- a/expect.exp +++ b/expect.exp @@ -9,7 +9,7 @@ #send \003 -set timeout 600 +set timeout 1200 #spawn (adb logcat | tee ./__TESTRESULT__.txt) log_file -noappend ./__TESTRESULT__.txt spawn adb logcat diff --git a/runtestsapp.sh b/runtestsapp.sh index 0448201da..5fcacba95 100755 --- a/runtestsapp.sh +++ b/runtestsapp.sh @@ -13,7 +13,8 @@ cd $workingdir echo "------------------------------------------------" echo "Starting the emulator..." - time emulator -avd Api19 -no-skin -no-audio & # -gpu on + #time emulator -avd Api19 -no-skin -no-audio & # -gpu on + time emulator -avd Api19 -no-audio & # -gpu on #emulator -avd Api19 -no-skin -no-audio -no-window & echo "------------------------------------------------" @@ -66,4 +67,4 @@ cd $startdir echo "------------------------------------------------" echo "Waiting for the tests to finish executing..." -./expect.exp +time ./expect.exp From 9868ee5b5c10d4c431fc91c00d41c070447a589a Mon Sep 17 00:00:00 2001 From: Erjan Gavalji Date: Fri, 9 Oct 2015 17:52:31 +0300 Subject: [PATCH 08/42] Add a windows-counterpart of the runner --- win-runtestsapp.sh | 71 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 win-runtestsapp.sh diff --git a/win-runtestsapp.sh b/win-runtestsapp.sh new file mode 100644 index 000000000..1e7a24ea8 --- /dev/null +++ b/win-runtestsapp.sh @@ -0,0 +1,71 @@ +workingdir=__TESTSAPP__ +startdir=$(pwd) +rm -rd $workingdir +mkdir $workingdir +cd $workingdir + +#android create avd -t "android-21" -n Api21 -b "default/x86" + +#if [ 1 == 2 ] ; then + echo "------------------------------------------------" + echo "Killing the emulator..." +# time pkill ".*emulator64-x86" && true + + echo "------------------------------------------------" + echo "Starting the emulator..." + #time emulator -avd Api19 -no-skin -no-audio & # -gpu on + time emulator -avd Api19 -no-audio & # -gpu on + #emulator -avd Api19 -no-skin -no-audio -no-window & + + echo "------------------------------------------------" + echo "Creating the app..." + time tns create TestsApp + cd TestsApp + + echo "------------------------------------------------" + echo "Removing the original template files..." + time rm app/*.* + + echo "------------------------------------------------" + echo "Copying the test app files..." + time cp -r ../../bin/dist/apps/tests/* ./app/ + + echo "------------------------------------------------" + echo "Adding the android platform..." + time tns platform add android #--frameworkPath=/Users/erjan/tns-android.tgz + + # #DO THE REPLACEMENTS IN THE Info.plist and AndroidManifest.xml + cp /Users/erjan/work/spikes/__DEL__/AndroidManifest.xml platforms/android/src/main/ + + echo "------------------------------------------------" + echo "Building the application..." + time tns build android + + echo "------------------------------------------------" + echo "Killing the adb server..." + time adb kill-server + + echo "------------------------------------------------" + echo "Starting the adb server..." + time adb start-server + +#fi + +echo "------------------------------------------------" +echo "Uninstalling the app..." +time adb uninstall org.nativescript.TestsApp + +echo "------------------------------------------------" +echo "Installing the app..." +time adb install ./platforms/android/build/outputs/apk/TestsApp-debug.apk + +echo "------------------------------------------------" +echo "Starting the app..." +time adb shell am start -n org.nativescript.TestsApp/com.tns.NativeScriptActivity + +cd $startdir + +echo "------------------------------------------------" +echo "Waiting for the tests to finish executing..." +adb logcat + From 90c6f8f47949b7067ed776fc87748c0b8f20d167 Mon Sep 17 00:00:00 2001 From: Erjan Gavalji Date: Sat, 10 Oct 2015 12:57:37 +0300 Subject: [PATCH 09/42] Add a linux (qemu-accelerated) emulator start --- linux-runtestapp.sh | 70 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100755 linux-runtestapp.sh diff --git a/linux-runtestapp.sh b/linux-runtestapp.sh new file mode 100755 index 000000000..52cfc274f --- /dev/null +++ b/linux-runtestapp.sh @@ -0,0 +1,70 @@ +workingdir=__TESTSAPP__ +startdir=$(pwd) +rm -rd $workingdir +mkdir $workingdir +cd $workingdir + +#android create avd -t "android-21" -n Api21 -b "default/x86" + +#if [ 1 == 2 ] ; then + echo "------------------------------------------------" + echo "Killing the emulator..." + time pkill ".*emulator64-x86" && true + + echo "------------------------------------------------" + echo "Starting the emulator..." + #time emulator -avd Api19 -no-skin -no-audio & # -gpu on + time emulator -avd Api21 -qemu -m 2048 -enable-kvm & + #emulator -avd Api19 -no-skin -no-audio -no-window & + + echo "------------------------------------------------" + echo "Creating the app..." + time tns create TestsApp + cd TestsApp + + echo "------------------------------------------------" + echo "Removing the original template files..." + time rm app/*.* + + echo "------------------------------------------------" + echo "Copying the test app files..." + time cp -r ../../bin/dist/apps/tests/* ./app/ + + echo "------------------------------------------------" + echo "Adding the android platform..." + time tns platform add android #--frameworkPath=/Users/erjan/tns-android.tgz + + # #DO THE REPLACEMENTS IN THE Info.plist and AndroidManifest.xml +# cp /Users/erjan/work/spikes/__DEL__/AndroidManifest.xml platforms/android/src/main/ + + echo "------------------------------------------------" + echo "Building the application..." + time tns build android + + echo "------------------------------------------------" + echo "Killing the adb server..." + time adb kill-server + + echo "------------------------------------------------" + echo "Starting the adb server..." + time adb start-server + +#fi + +echo "------------------------------------------------" +echo "Uninstalling the app..." +time adb uninstall org.nativescript.TestsApp + +echo "------------------------------------------------" +echo "Installing the app..." +time adb install ./platforms/android/build/outputs/apk/TestsApp-debug.apk + +echo "------------------------------------------------" +echo "Starting the app..." +time adb shell am start -n org.nativescript.TestsApp/com.tns.NativeScriptActivity + +cd $startdir + +echo "------------------------------------------------" +echo "Waiting for the tests to finish executing..." +time ./expect.exp From 5aa502a9476beba2365b317d4ca14c3ac79a391f Mon Sep 17 00:00:00 2001 From: Erjan Gavalji Date: Mon, 12 Oct 2015 16:58:59 +0300 Subject: [PATCH 10/42] Fix the run in android --- apps/tests/app/mainPage.ts | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/apps/tests/app/mainPage.ts b/apps/tests/app/mainPage.ts index 04200e127..7d3c09f99 100644 --- a/apps/tests/app/mainPage.ts +++ b/apps/tests/app/mainPage.ts @@ -1,18 +1,22 @@ -import tests = require("../testRunner"); -import trace = require("trace"); -import {Page} from "ui/page"; -import {GridLayout} from "ui/layouts/grid-layout"; +import {Page} from "ui/page"; +import tests = require("../testRunner"); trace.enable(); trace.addCategories(trace.categories.Test + "," + trace.categories.Error); +let started = false; +let page = new Page(); + +page.on(Page.navigatedToEvent, function () { + if (!started) { + started = true; + setTimeout(function () { + tests.runAll(); + }, 10); + } +}); + export function createPage() { - var page = new Page(); - var navigatedToHandler = function() { - tests.runAll(); - page.off("navigatedTo", navigatedToHandler); - }; - page.on("navigatedTo", navigatedToHandler); return page; } From d4a702409d10e89a10c276330e933742caa78382 Mon Sep 17 00:00:00 2001 From: Erjan Gavalji Date: Wed, 14 Oct 2015 15:35:39 +0300 Subject: [PATCH 11/42] Fix the compilation --- apps/tests/app/mainPage.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/tests/app/mainPage.ts b/apps/tests/app/mainPage.ts index 7d3c09f99..d204b2b47 100644 --- a/apps/tests/app/mainPage.ts +++ b/apps/tests/app/mainPage.ts @@ -1,4 +1,5 @@ import {Page} from "ui/page"; +import * as trace from "trace"; import tests = require("../testRunner"); trace.enable(); From 2c42783907126c36a6180fc0392a49ecb11bfbd3 Mon Sep 17 00:00:00 2001 From: Erjan Gavalji Date: Thu, 15 Oct 2015 10:37:18 +0300 Subject: [PATCH 12/42] Reduce the timeout of the test run. Start in no-window --- expect.exp | 2 +- runtestsapp.sh | 68 ++++++++++++++++++++++++-------------------------- 2 files changed, 34 insertions(+), 36 deletions(-) diff --git a/expect.exp b/expect.exp index ebbd5ea98..a3abc321c 100755 --- a/expect.exp +++ b/expect.exp @@ -9,7 +9,7 @@ #send \003 -set timeout 1200 +set timeout 600 #spawn (adb logcat | tee ./__TESTRESULT__.txt) log_file -noappend ./__TESTRESULT__.txt spawn adb logcat diff --git a/runtestsapp.sh b/runtestsapp.sh index 5fcacba95..4bf5bf37c 100755 --- a/runtestsapp.sh +++ b/runtestsapp.sh @@ -4,52 +4,48 @@ rm -rd $workingdir mkdir $workingdir cd $workingdir +# Creating the emulator with: #android create avd -t "android-21" -n Api21 -b "default/x86" -#if [ 1 == 2 ] ; then - echo "------------------------------------------------" - echo "Killing the emulator..." - time pkill ".*emulator64-x86" && true +echo "------------------------------------------------" +echo "Killing the emulator..." +time pkill ".*emulator64-x86" && true - echo "------------------------------------------------" - echo "Starting the emulator..." - #time emulator -avd Api19 -no-skin -no-audio & # -gpu on - time emulator -avd Api19 -no-audio & # -gpu on - #emulator -avd Api19 -no-skin -no-audio -no-window & +echo "------------------------------------------------" +echo "Starting the emulator..." +time emulator -avd Api19 -no-audio --no-window & - echo "------------------------------------------------" - echo "Creating the app..." - time tns create TestsApp - cd TestsApp +echo "------------------------------------------------" +echo "Creating the app..." +time tns create TestsApp +cd TestsApp - echo "------------------------------------------------" - echo "Removing the original template files..." - time rm app/*.* +echo "------------------------------------------------" +echo "Removing the original template files..." +time rm app/*.* - echo "------------------------------------------------" - echo "Copying the test app files..." - time cp -r ../../bin/dist/apps/tests/* ./app/ +echo "------------------------------------------------" +echo "Copying the test app files..." +time cp -r ../../bin/dist/apps/tests/* ./app/ - echo "------------------------------------------------" - echo "Adding the android platform..." - time tns platform add android #--frameworkPath=/Users/erjan/tns-android.tgz +echo "------------------------------------------------" +echo "Adding the android platform..." +time tns platform add android #--frameworkPath=/Users/erjan/tns-android.tgz - # #DO THE REPLACEMENTS IN THE Info.plist and AndroidManifest.xml - cp /Users/erjan/work/spikes/__DEL__/AndroidManifest.xml platforms/android/src/main/ +# #DO THE REPLACEMENTS IN THE Info.plist and AndroidManifest.xml +cp /Users/erjan/work/spikes/__DEL__/AndroidManifest.xml platforms/android/src/main/ - echo "------------------------------------------------" - echo "Building the application..." - time tns build android +echo "------------------------------------------------" +echo "Building the application..." +time tns build android - echo "------------------------------------------------" - echo "Killing the adb server..." - time adb kill-server +echo "------------------------------------------------" +echo "Killing the adb server..." +time adb kill-server - echo "------------------------------------------------" - echo "Starting the adb server..." - time adb start-server - -#fi +echo "------------------------------------------------" +echo "Starting the adb server..." +time adb start-server echo "------------------------------------------------" echo "Uninstalling the app..." @@ -68,3 +64,5 @@ cd $startdir echo "------------------------------------------------" echo "Waiting for the tests to finish executing..." time ./expect.exp + +#pkill ".*emulator64-x86" && true From 2edb5a8fb21aaddddfa74f9e5186ce2c27af97dc Mon Sep 17 00:00:00 2001 From: Erjan Gavalji Date: Thu, 15 Oct 2015 10:54:36 +0300 Subject: [PATCH 13/42] Move the testsapp folder under the build folder --- runtestsapp.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/runtestsapp.sh b/runtestsapp.sh index 4bf5bf37c..b792d8aeb 100755 --- a/runtestsapp.sh +++ b/runtestsapp.sh @@ -1,4 +1,4 @@ -workingdir=__TESTSAPP__ +workingdir=./build/__TESTSAPP__ startdir=$(pwd) rm -rd $workingdir mkdir $workingdir @@ -13,7 +13,7 @@ time pkill ".*emulator64-x86" && true echo "------------------------------------------------" echo "Starting the emulator..." -time emulator -avd Api19 -no-audio --no-window & +time emulator -avd Api19 -no-audio -no-window & echo "------------------------------------------------" echo "Creating the app..." @@ -26,7 +26,7 @@ time rm app/*.* echo "------------------------------------------------" echo "Copying the test app files..." -time cp -r ../../bin/dist/apps/tests/* ./app/ +time cp -r ../../../bin/dist/apps/tests/* ./app/ echo "------------------------------------------------" echo "Adding the android platform..." From f9851c1ac6a5077ab2faf811397cf0e914ee9fd3 Mon Sep 17 00:00:00 2001 From: Erjan Gavalji Date: Thu, 15 Oct 2015 14:30:03 +0300 Subject: [PATCH 14/42] Kill the emulator at end --- runtestsapp.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtestsapp.sh b/runtestsapp.sh index b792d8aeb..3eef5c7a4 100755 --- a/runtestsapp.sh +++ b/runtestsapp.sh @@ -65,4 +65,4 @@ echo "------------------------------------------------" echo "Waiting for the tests to finish executing..." time ./expect.exp -#pkill ".*emulator64-x86" && true +pkill ".*emulator64-x86" && true From 54440f4266d9a894c685bd061b9f26abaf999b22 Mon Sep 17 00:00:00 2001 From: Erjan Gavalji Date: Thu, 15 Oct 2015 14:50:43 +0300 Subject: [PATCH 15/42] Copying the latest android widgets... --- runtestsapp.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/runtestsapp.sh b/runtestsapp.sh index 3eef5c7a4..74b19dff2 100755 --- a/runtestsapp.sh +++ b/runtestsapp.sh @@ -32,6 +32,9 @@ echo "------------------------------------------------" echo "Adding the android platform..." time tns platform add android #--frameworkPath=/Users/erjan/tns-android.tgz +# GET THIS ONE FROM SOME PLACE... +cp /Volumes/distributions/DailyBuilds/NativeScript/android-widgets/Stable/widgets.jar platforms/android/libs/ + # #DO THE REPLACEMENTS IN THE Info.plist and AndroidManifest.xml cp /Users/erjan/work/spikes/__DEL__/AndroidManifest.xml platforms/android/src/main/ From fd494a6a29f4c2643e11fda1943148f8040dcac0 Mon Sep 17 00:00:00 2001 From: Erjan Gavalji Date: Thu, 15 Oct 2015 15:41:55 +0300 Subject: [PATCH 16/42] Extract the variables in the runner script --- runtestsapp.sh | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/runtestsapp.sh b/runtestsapp.sh index 74b19dff2..49364a92a 100755 --- a/runtestsapp.sh +++ b/runtestsapp.sh @@ -1,5 +1,15 @@ -workingdir=./build/__TESTSAPP__ +workingdir=./.testsapprun startdir=$(pwd) + +emuProcId=".*emulator64-x86" +emuAvdName=Api19 +androidRuntimePath=/Users/erjan/tns-android.tgz + +testsAppName=TestsApp +pathToApk=./platforms/android/build/outputs/apk/$testsAppName-debug.apk +deployedAppName=org.nativescript.$testsAppName +mainActivityName=com.tns.NativeScriptActivity + rm -rd $workingdir mkdir $workingdir cd $workingdir @@ -9,16 +19,16 @@ cd $workingdir echo "------------------------------------------------" echo "Killing the emulator..." -time pkill ".*emulator64-x86" && true +time pkill $emuProcId && true echo "------------------------------------------------" echo "Starting the emulator..." -time emulator -avd Api19 -no-audio -no-window & +time emulator -avd $emuAvdName -no-audio -no-window & echo "------------------------------------------------" echo "Creating the app..." -time tns create TestsApp -cd TestsApp +time tns create $testsAppName +cd $testsAppName echo "------------------------------------------------" echo "Removing the original template files..." @@ -26,18 +36,18 @@ time rm app/*.* echo "------------------------------------------------" echo "Copying the test app files..." -time cp -r ../../../bin/dist/apps/tests/* ./app/ +time cp -r ../../bin/dist/apps/tests/* ./app/ echo "------------------------------------------------" echo "Adding the android platform..." -time tns platform add android #--frameworkPath=/Users/erjan/tns-android.tgz - -# GET THIS ONE FROM SOME PLACE... -cp /Volumes/distributions/DailyBuilds/NativeScript/android-widgets/Stable/widgets.jar platforms/android/libs/ +time tns platform add android --frameworkPath=$androidRuntimePath # #DO THE REPLACEMENTS IN THE Info.plist and AndroidManifest.xml cp /Users/erjan/work/spikes/__DEL__/AndroidManifest.xml platforms/android/src/main/ +# GET THIS ONE FROM SOME PLACE... +cp /Volumes/distributions/DailyBuilds/NativeScript/android-widgets/Stable/widgets.jar platforms/android/libs/ + echo "------------------------------------------------" echo "Building the application..." time tns build android @@ -52,15 +62,15 @@ time adb start-server echo "------------------------------------------------" echo "Uninstalling the app..." -time adb uninstall org.nativescript.TestsApp +time adb uninstall $deployedAppName echo "------------------------------------------------" echo "Installing the app..." -time adb install ./platforms/android/build/outputs/apk/TestsApp-debug.apk +time adb install $pathToApk echo "------------------------------------------------" echo "Starting the app..." -time adb shell am start -n org.nativescript.TestsApp/com.tns.NativeScriptActivity +time adb shell am start -n $deployedAppName/$mainActivityName cd $startdir @@ -68,4 +78,4 @@ echo "------------------------------------------------" echo "Waiting for the tests to finish executing..." time ./expect.exp -pkill ".*emulator64-x86" && true +pkill $emuProcId && true From b5e83c1f7521962d65fbddcef10425277a3932d0 Mon Sep 17 00:00:00 2001 From: Erjan Gavalji Date: Thu, 15 Oct 2015 16:43:57 +0300 Subject: [PATCH 17/42] Modify the expectation in the expect script to be a string. Remove the test folder upon completion --- expect.exp | 2 +- runtestsapp.sh | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/expect.exp b/expect.exp index a3abc321c..6b56dedd2 100755 --- a/expect.exp +++ b/expect.exp @@ -13,5 +13,5 @@ set timeout 600 #spawn (adb logcat | tee ./__TESTRESULT__.txt) log_file -noappend ./__TESTRESULT__.txt spawn adb logcat -expect '=== ALL TESTS COMPLETE ===' +expect "=== ALL TESTS COMPLETE ===" send \003 diff --git a/runtestsapp.sh b/runtestsapp.sh index 49364a92a..70b822fb5 100755 --- a/runtestsapp.sh +++ b/runtestsapp.sh @@ -79,3 +79,5 @@ echo "Waiting for the tests to finish executing..." time ./expect.exp pkill $emuProcId && true + +rm -rd $workingdir From f04fc617a0f09731632304d777c8a17b6024b58c Mon Sep 17 00:00:00 2001 From: Erjan Gavalji Date: Thu, 15 Oct 2015 17:42:17 +0300 Subject: [PATCH 18/42] Change the output file to be an argument to the expect script. Pass it from the runner. Ignore the output file name --- .gitignore | 2 ++ expect.exp | 4 ++-- runtestsapp.sh | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index ddc017468..59f24406e 100644 --- a/.gitignore +++ b/.gitignore @@ -27,3 +27,5 @@ obj/ .baseDir.ts .ctags-exclude tags + +TestRunResult.txt diff --git a/expect.exp b/expect.exp index 6b56dedd2..5a084c782 100755 --- a/expect.exp +++ b/expect.exp @@ -8,10 +8,10 @@ #expect "TypeScript compilation complete" #send \003 - +set outfile [lindex $argv 0]; set timeout 600 #spawn (adb logcat | tee ./__TESTRESULT__.txt) -log_file -noappend ./__TESTRESULT__.txt +log_file -noappend $outfile spawn adb logcat expect "=== ALL TESTS COMPLETE ===" send \003 diff --git a/runtestsapp.sh b/runtestsapp.sh index 70b822fb5..ee3af583b 100755 --- a/runtestsapp.sh +++ b/runtestsapp.sh @@ -4,6 +4,7 @@ startdir=$(pwd) emuProcId=".*emulator64-x86" emuAvdName=Api19 androidRuntimePath=/Users/erjan/tns-android.tgz +outfile=./TestRunResult.txt testsAppName=TestsApp pathToApk=./platforms/android/build/outputs/apk/$testsAppName-debug.apk @@ -76,7 +77,7 @@ cd $startdir echo "------------------------------------------------" echo "Waiting for the tests to finish executing..." -time ./expect.exp +time ./expect.exp $outfile pkill $emuProcId && true From 2f7329ca6f95ddfb6a86d0c04255d6cc42e0db26 Mon Sep 17 00:00:00 2001 From: Erjan Gavalji Date: Thu, 15 Oct 2015 17:45:49 +0300 Subject: [PATCH 19/42] Call the testapprun from grunt --- gruntfile.js | 26 ++------------------------ 1 file changed, 2 insertions(+), 24 deletions(-) diff --git a/gruntfile.js b/gruntfile.js index a616fc8ce..ccf174b34 100644 --- a/gruntfile.js +++ b/gruntfile.js @@ -365,31 +365,9 @@ module.exports = function(grunt) { mochaNode: { cmd: "grunt simplemocha:node" }, - setupTestsApp: { + runTestsApp: { cmd: "./runtestsapp.sh" } -// setupTestsApp: { -////TODO: TNS PATH MIGHT GET PASSED FROM OUTSIDE! -// cmd: [ -// 'pkill ".*emulator64-arm" && true', -// "emulator -avd Api19 -no-skin -no-audio &", -//// "emulator -avd Api19 -no-skin -no-audio -no-window &", -// "tns create TestsApp", -// "cd TestsApp", -// "rm app/*.*", -// "cp -r " + pathModule.join(localCfg.outAppsDir, "tests") + "/* ./app/", -// "tns platform add android", -////TODO: DO THE REPLACEMENTS IN THE Info.plist and AndroidManifest.xml -// "tns build android", -// -// "adb kill-server", -// "adb start-server", -// -// "adb install ./platforms/android/build/outputs/apk/TestsApp-debug.apk", -// "adb shell am start -n org.nativescript.TestsApp/com.tns.NativeScriptActivity", -//// "expect -c ' -// ].join(" && ") -// } }, multidest: { copyLicenseFiles: { @@ -584,6 +562,6 @@ module.exports = function(grunt) { ]); grunt.registerTask("testsapp", [ - "exec:setupTestsApp" + "exec:runTestsApp" ]); }; From a875096b08bf4f2960706d2d8714f6ef524c7950 Mon Sep 17 00:00:00 2001 From: Erjan Gavalji Date: Fri, 16 Oct 2015 16:56:43 +0300 Subject: [PATCH 20/42] Start moving the code to grunt --- .gitignore | 1 + build/run-testsapp.grunt.js | 67 +++ gruntfile.js | 1073 ++++++++++++++++++----------------- package.json | 7 +- runtestsapp.sh | 10 - 5 files changed, 610 insertions(+), 548 deletions(-) create mode 100644 build/run-testsapp.grunt.js diff --git a/.gitignore b/.gitignore index 59f24406e..6fefaa005 100644 --- a/.gitignore +++ b/.gitignore @@ -15,6 +15,7 @@ dist/ !css-value/**/*.* !fetch/**/*.* !apps/TelerikNEXT/lib/**/*.* +!build/*.* CrossPlatformModules.sln.ide/ *.suo CrossPlatformModules.suo diff --git a/build/run-testsapp.grunt.js b/build/run-testsapp.grunt.js new file mode 100644 index 000000000..678727570 --- /dev/null +++ b/build/run-testsapp.grunt.js @@ -0,0 +1,67 @@ +module.exports = { + run: function(grunt) { + + var localCfg = { + emulatorProcessIdentifier:".*emulator64-x86", + emuAvdName:"Api19", + androidRuntimePath:"/Users/erjan/tns-android.tgz", + outfile:"./TestRunResult.txt", + + workingDir=".testsapprun", + testsAppName:"TestsApp", + pathToApk:"./platforms/android/build/outputs/apk/TestsApp-debug.apk", + deployedAppName:"org.nativescript.$testsAppName", + mainActivityName:"com.tns.NativeScriptActivity" + } + + grunt.initConfig({ + clean: { + workingDir: { + src: localCfg.workingDir + } + }, + mkdir: { + workindDir: { + options: { + create [localCfg.workingDir], + mode: 0700 + } + } + } + exec: { + killEmulator: { + cmd: "pkill '" + localCfg.emulatorProcessIdentifier + "'", + exitCode: [0, 1] + }, + runTestsApp: { + cmd: "./runtestsapp.sh", + stdout: false, + cwd: "../" + } + } + }); + +// grunt.loadNpmTasks("grunt-contrib-copy"); +// grunt.loadNpmTasks("grunt-tslint"); +// grunt.loadNpmTasks("grunt-multi-dest"); +// grunt.loadNpmTasks("grunt-shell"); +// grunt.loadNpmTasks("grunt-env"); +// grunt.loadNpmTasks("grunt-simple-mocha"); + grunt.loadNpmTasks("grunt-exec"); + grunt.loadNpmTasks("grunt-mkdir"); + grunt.loadNpmTasks("grunt-contrib-clean"); + + grunt.registerTask("testsapp", [ + "clean:workingDir", + "mkdir:workingDir", + "exec:killEmulator", + "exec:runTestsApp", + + + + + "exec:killEmulator", + "clean:workingDir" + ]); + } +} diff --git a/gruntfile.js b/gruntfile.js index ccf174b34..67b0d8a1c 100644 --- a/gruntfile.js +++ b/gruntfile.js @@ -1,567 +1,570 @@ module.exports = function(grunt) { - var fs=require("fs"); - var pathModule=require("path"); - var filterTypeScriptFiles = function(content, srcPath) { - var matchRule = /^.*@private/ig; - if (matchRule.test(content)) - { - return false; - } - var processed = content; - processed = processed.replace(/\/\/[\/\s]*@private((.|\s)*?)\/\/[\/\s]*@endprivate/gm, ""); - return processed; - }; + if (grunt.cli.tasks.indexOf("testsapp") >= 0) { + var tsTester = require("./build/run-testsapp.grunt.js"); + tsTester.run(grunt); + } else { - var updatePackageDef = function(content, update) - { - var contentAsObject = JSON.parse(content); - update(contentAsObject); - return JSON.stringify(contentAsObject, null, "\t"); - } - var updateModulesPackageDef = function(content, srcPath) { - return updatePackageDef(content, function(contentAsObject) { - contentAsObject.version = localCfg.packageVersion; - if (localCfg.commitSHA) { - contentAsObject.repository.url += "/commit/" + localCfg.commitSHA; - } - }); - }; + var fs=require("fs"); + var pathModule=require("path"); - var updateAppPackageDef = function(content, srcPath) { - var currentAppName = grunt.task.current.data.appName; - return updatePackageDef(content, function(contentAsObject) { - contentAsObject.version = localCfg.packageVersion; - contentAsObject.author = "Telerik "; - var specificKeywords = ["telerik", "mobile", "nativescript", "{N}", "tns", "appbuilder"]; - if (currentAppName.indexOf("template-") == 0) { - var templateName = currentAppName.substring("template-".length); - contentAsObject.name = "tns-" + currentAppName; - contentAsObject.description = "Nativescript " + templateName + " project template"; - specificKeywords.push("template"); - } - else { - contentAsObject.name = "tns-samples-" + currentAppName; - contentAsObject.description = "Nativescript " + currentAppName + " sample application"; - specificKeywords.push("sample"); - } - contentAsObject.license = "BSD"; - addKeywords(contentAsObject, specificKeywords); - - if (!contentAsObject.repository) { - contentAsObject.repository = {}; - } - if (!contentAsObject.repository.url) { - contentAsObject.repository.url = localCfg.mainPackageContent.repository.url; - } - if (localCfg.commitSHA) { - contentAsObject.repository.url += "/commit/" + localCfg.commitSHA; - } - }); - }; - - var addKeywords = function(packageObject, newKeywords) { - if (!packageObject.keywords) { - packageObject.keywords = newKeywords; - return; - } - - if (typeof(packageObject.keywords) == "string") { - packageObject.keywords = packageObject.keywords.split(" "); - } - packageObject.keywords = packageObject.keywords.concat(newKeywords); - }; - - var updateDefinitionsPackageDef = function(content, srcPath) { - return updatePackageDef(content, function(contentAsObject) { - contentAsObject.version = localCfg.packageVersion; - contentAsObject.name = "tns-definitions"; - contentAsObject.description = "NativeScript Module definitions"; - contentAsObject.license = "Apache-2.0"; - if (localCfg.commitSHA) { - contentAsObject.repository.url += "/commit/" + localCfg.commitSHA; - } - }); - }; - - var getCommitSha = function() { - if (process.env.GIT_COMMIT) { - return process.env.GIT_COMMIT; - } - return ""; - }; - - var assignGitSHA = function(err, stdout, stderr, cb) { - if (!localCfg.commitSHA) { - localCfg.commitSHA = stdout.replace("\n", ""); - } - cb(); - }; - - var getPackageVersion = function() { - var buildVersion = process.env.PACKAGE_VERSION; - if (!buildVersion) { - return localCfg.mainPackageContent.version; - } - return localCfg.mainPackageContent.version + "-" + buildVersion; - }; - - var processAppFile = function(content, srcPath) { - return content; - }; - - var getSubDirs = function(dir) { - var allObjects = fs.readdirSync(dir); - var allDirs = []; - for (var i=0; i/", - cwd: localCfg.srcDir - }, - license: { - expand: true, - src: [ - "./LICENSE", - ], - dest: "<%= localCfg.outModulesDir %>/", - cwd: localCfg.srcDir - }, - appLicense: { - expand: true, - src: ["./LICENSE"], - cwd: localCfg.srcAppsDir, - dest: "__dummy__" - }, - definitionFiles: { - src: [ - localCfg.srcDir + "/**/*.d.ts", - pathModule.join(localCfg.srcDir, "LICENSE"), - //Exclude the d.ts files in the apps folder - these are part of the apps and are already packed there! - "!" + localCfg.srcDir + "/apps/**" - ].concat(localCfg.defaultExcludes).concat(localCfg.excludedModules), - dest: localCfg.outDefinitionsDir + "/", - expand: true, - options: { - process: filterTypeScriptFiles - } - }, - modulesPackageDef: { - expand: true, - src: localCfg.packageJsonFilePath, - dest: localCfg.outModulesDir + "/", - options: { - process: updateModulesPackageDef - } - }, - definitionsPackageDef: { - src: localCfg.packageJsonFilePath, - dest: localCfg.outDefinitionsDir + "/", - options: { - process: updateDefinitionsPackageDef - } - }, - appPackageDef: { - expand: true, - flatten: true, - src: "__app_package_json", - dest: "__dummy__", - options: { - process: updateAppPackageDef - } - }, - childPackageFiles: { - expand: true, - src: [ - localCfg.srcDir + "/**/package.json", - "!./package.json", - "!./Deploy/**/*.*", - "!./bin/**/*.*", - "!./Tests/**/*.*", - "!" + localCfg.outDir + "/**/*.*" - ].concat(localCfg.excludedModules), - dest: localCfg.outModulesDir + "/" - }, - rawAppsFiles: { - expand: true, - src: [ - "**/*.*", - "**/*", - "!**/*.map", - "!**/*.ts" - ], - dest: localCfg.outAppsDir, - cwd: localCfg.srcAppsDir, - dot: true - }, - readyAppFiles: { - expand: true, - src: ["./**/*.*"], - dest: localCfg.outAppsDir + "/", - cwd: localCfg.outModulesDir + "/apps/", - options: { - process: processAppFile - } - }, - readyTsAppFiles: { - expand: true, - src: ["./**/*.*", "!./**/*.map"], - dest: localCfg.outTsAppsDir + "/", - cwd: localCfg.srcAppsDir - }, - readyPackages: { - expand: true, - src: ["./**/*.tgz"], - dest: localCfg.outDir + "/", - cwd: localCfg.outDir, - flatten: true - } - }, - ts: { - build: { - src: localCfg.typeScriptSrc, - outDir: localCfg.outModulesDir, - options: { - fast: 'never', - module: "commonjs", - target: "es5", - sourceMap: false, - declaration: false, - removeComments: "<%= !grunt.option('leavecomments') || '' %>", - compiler: "node_modules/typescript/bin/tsc", - noEmitOnError: true, - experimentalDecorators: true, - noEmitHelpers: true - } - }, - buildNodeTests: { - src: [ - 'js-libs/easysax/**/*.ts', - 'xml/**/*.ts', - 'node-tests/**/*.ts', - ], - outDir: localCfg.outModulesDir, - options: { - fast: 'never', - module: "commonjs", - target: "es5", - sourceMap: false, - declaration: false, - removeComments: "<%= !grunt.option('leavecomments') || '' %>", - compiler: "node_modules/typescript/bin/tsc", - noEmitOnError: true - } - } - }, - tslint: { - build: { - files: { - src: localCfg.typeScriptSrcForTsLint + grunt.initConfig({ + localCfg : localCfg, + pkg: grunt.file.readJSON('package.json'), + clean: { + build: { + src: [localCfg.outDir] }, - options: { - configuration: grunt.file.readJSON("./build/tslint.json") - } - } - }, - exec: { - packModules: { - cmd: "npm pack", - cwd: localCfg.outModulesDir + "/" - }, - packDefinitions: { - cmd: "npm pack", - cwd: localCfg.outDefinitionsDir + "/" - }, - packApp: { - cmd: "npm pack", - cwd: "__dummy__" - }, - mochaNode: { - cmd: "grunt simplemocha:node" - }, - runTestsApp: { - cmd: "./runtestsapp.sh" - } - }, - multidest: { - copyLicenseFiles: { - tasks: ["copy:appLicense"], - dest: function() { - var apps = getSubDirs(localCfg.srcAppsDir); - var targetDirs = []; - apps.forEach(function(item){ - targetDirs.push(pathModule.join(localCfg.outAppsDir, item.name)); - targetDirs.push(pathModule.join(localCfg.outTsAppsDir, item.name)); - }); - return targetDirs; - }() - } - }, - shell: { - getGitSHA: { - command: "git rev-parse HEAD", - options: { - callback: assignGitSHA + typeScriptLeftovers: { + expand: true, + src: [ + "./.baseDir.*", + "./_references.js", + "./**/*.map" + ], + cwd: localCfg.outModulesDir + }, + nodeTests: { + src: localCfg.nodeTestsDir, + }, + readyAppFiles: { + src: [localCfg.outModulesDir + "/apps/**"] } }, - }, - simplemocha: { - node: { - src: localCfg.nodeTestsDir + '/**/*.js' - } - }, - env: { - nodeTests: { - NODE_PATH: localCfg.outModulesDir, - } - } - }); + copy: { + jsLibs: { + expand: true, + src: [ + "./js-libs/**/*.js", + "./fetch/**/*.js", + "./css/**/*.js", + "./css-value/**/*.js", + ], + dest: "<%= localCfg.outModulesDir %>/", + cwd: localCfg.srcDir + }, + license: { + expand: true, + src: [ + "./LICENSE", + ], + dest: "<%= localCfg.outModulesDir %>/", + cwd: localCfg.srcDir + }, + appLicense: { + expand: true, + src: ["./LICENSE"], + cwd: localCfg.srcAppsDir, + dest: "__dummy__" + }, + definitionFiles: { + src: [ + localCfg.srcDir + "/**/*.d.ts", + pathModule.join(localCfg.srcDir, "LICENSE"), + //Exclude the d.ts files in the apps folder - these are part of the apps and are already packed there! + "!" + localCfg.srcDir + "/apps/**" + ].concat(localCfg.defaultExcludes).concat(localCfg.excludedModules), + dest: localCfg.outDefinitionsDir + "/", + expand: true, + options: { + process: filterTypeScriptFiles + } + }, + modulesPackageDef: { + expand: true, + src: localCfg.packageJsonFilePath, + dest: localCfg.outModulesDir + "/", + options: { + process: updateModulesPackageDef + } + }, + definitionsPackageDef: { + src: localCfg.packageJsonFilePath, + dest: localCfg.outDefinitionsDir + "/", + options: { + process: updateDefinitionsPackageDef + } + }, + appPackageDef: { + expand: true, + flatten: true, + src: "__app_package_json", + dest: "__dummy__", + options: { + process: updateAppPackageDef + } + }, + childPackageFiles: { + expand: true, + src: [ + localCfg.srcDir + "/**/package.json", + "!./package.json", + "!./Deploy/**/*.*", + "!./bin/**/*.*", + "!./Tests/**/*.*", + "!" + localCfg.outDir + "/**/*.*" + ].concat(localCfg.excludedModules), + dest: localCfg.outModulesDir + "/" + }, + rawAppsFiles: { + expand: true, + src: [ + "**/*.*", + "**/*", + "!**/*.map", + "!**/*.ts" + ], + dest: localCfg.outAppsDir, + cwd: localCfg.srcAppsDir, + dot: true + }, + readyAppFiles: { + expand: true, + src: ["./**/*.*"], + dest: localCfg.outAppsDir + "/", + cwd: localCfg.outModulesDir + "/apps/", + options: { + process: processAppFile + } + }, + readyTsAppFiles: { + expand: true, + src: ["./**/*.*", "!./**/*.map"], + dest: localCfg.outTsAppsDir + "/", + cwd: localCfg.srcAppsDir + }, + readyPackages: { + expand: true, + src: ["./**/*.tgz"], + dest: localCfg.outDir + "/", + cwd: localCfg.outDir, + flatten: true + } + }, + ts: { + build: { + src: localCfg.typeScriptSrc, + outDir: localCfg.outModulesDir, + options: { + fast: 'never', + module: "commonjs", + target: "es5", + sourceMap: false, + declaration: false, + removeComments: "<%= !grunt.option('leavecomments') || '' %>", + compiler: "node_modules/typescript/bin/tsc", + noEmitOnError: true, + experimentalDecorators: true, + noEmitHelpers: true + } + }, + buildNodeTests: { + src: [ + 'js-libs/easysax/**/*.ts', + 'xml/**/*.ts', + 'node-tests/**/*.ts', + ], + outDir: localCfg.outModulesDir, + options: { + fast: 'never', + module: "commonjs", + target: "es5", + sourceMap: false, + declaration: false, + removeComments: "<%= !grunt.option('leavecomments') || '' %>", + compiler: "node_modules/typescript/bin/tsc", + noEmitOnError: true + } + } + }, + tslint: { + build: { + files: { + src: localCfg.typeScriptSrcForTsLint + }, + options: { + configuration: grunt.file.readJSON("./build/tslint.json") + } + } + }, + exec: { + packModules: { + cmd: "npm pack", + cwd: localCfg.outModulesDir + "/" + }, + packDefinitions: { + cmd: "npm pack", + cwd: localCfg.outDefinitionsDir + "/" + }, + packApp: { + cmd: "npm pack", + cwd: "__dummy__" + }, + mochaNode: { + cmd: "grunt simplemocha:node" + } + }, + multidest: { + copyLicenseFiles: { + tasks: ["copy:appLicense"], + dest: function() { + var apps = getSubDirs(localCfg.srcAppsDir); + var targetDirs = []; + apps.forEach(function(item){ + targetDirs.push(pathModule.join(localCfg.outAppsDir, item.name)); + targetDirs.push(pathModule.join(localCfg.outTsAppsDir, item.name)); + }); + return targetDirs; + }() + } + }, + shell: { + getGitSHA: { + command: "git rev-parse HEAD", + options: { + callback: assignGitSHA + } + }, + }, + simplemocha: { + node: { + src: localCfg.nodeTestsDir + '/**/*.js' + } + }, + env: { + nodeTests: { + NODE_PATH: localCfg.outModulesDir, + } + } + }); - grunt.loadNpmTasks("grunt-ts"); - grunt.loadNpmTasks("grunt-contrib-clean"); - grunt.loadNpmTasks("grunt-contrib-copy"); - grunt.loadNpmTasks("grunt-exec"); - grunt.loadNpmTasks("grunt-tslint"); - grunt.loadNpmTasks("grunt-multi-dest"); - grunt.loadNpmTasks("grunt-shell"); - grunt.loadNpmTasks("grunt-env"); - grunt.loadNpmTasks("grunt-simple-mocha"); + grunt.loadNpmTasks("grunt-ts"); + grunt.loadNpmTasks("grunt-contrib-clean"); + grunt.loadNpmTasks("grunt-contrib-copy"); + grunt.loadNpmTasks("grunt-exec"); + grunt.loadNpmTasks("grunt-tslint"); + grunt.loadNpmTasks("grunt-multi-dest"); + grunt.loadNpmTasks("grunt-shell"); + grunt.loadNpmTasks("grunt-env"); + grunt.loadNpmTasks("grunt-simple-mocha"); - var cloneTasks = function(originalTasks, taskNameSuffix) - { - var clonedTasks = []; - for(var i=0; i Date: Mon, 19 Oct 2015 10:42:42 +0300 Subject: [PATCH 21/42] Ignore the .testsapprun intermediate folder. It will remain if test run fails --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 6fefaa005..385096ae7 100644 --- a/.gitignore +++ b/.gitignore @@ -30,3 +30,4 @@ obj/ tags TestRunResult.txt +.testsapprun From af16da3b4ba282d5c3d3ee0c111946cb26065fb2 Mon Sep 17 00:00:00 2001 From: Erjan Gavalji Date: Mon, 19 Oct 2015 14:10:56 +0300 Subject: [PATCH 22/42] Syntax cleanup --- gruntfile.js | 283 +++++++++++++++++++++++++-------------------------- 1 file changed, 140 insertions(+), 143 deletions(-) diff --git a/gruntfile.js b/gruntfile.js index 67b0d8a1c..42cd5e013 100644 --- a/gruntfile.js +++ b/gruntfile.js @@ -329,149 +329,146 @@ module.exports = function(grunt) { }, buildNodeTests: { src: [ - 'js-libs/easysax/**/*.ts', - 'xml/**/*.ts', - 'node-tests/**/*.ts', - ], - outDir: localCfg.outModulesDir, - options: { - fast: 'never', - module: "commonjs", - target: "es5", - sourceMap: false, - declaration: false, - removeComments: "<%= !grunt.option('leavecomments') || '' %>", - compiler: "node_modules/typescript/bin/tsc", - noEmitOnError: true - } - } - }, - tslint: { - build: { - files: { - src: localCfg.typeScriptSrcForTsLint - }, - options: { - configuration: grunt.file.readJSON("./build/tslint.json") - } - } - }, - exec: { - packModules: { - cmd: "npm pack", - cwd: localCfg.outModulesDir + "/" - }, - packDefinitions: { - cmd: "npm pack", - cwd: localCfg.outDefinitionsDir + "/" - }, - packApp: { - cmd: "npm pack", - cwd: "__dummy__" - }, - mochaNode: { - cmd: "grunt simplemocha:node" - } - }, - multidest: { - copyLicenseFiles: { - tasks: ["copy:appLicense"], - dest: function() { - var apps = getSubDirs(localCfg.srcAppsDir); - var targetDirs = []; - apps.forEach(function(item){ - targetDirs.push(pathModule.join(localCfg.outAppsDir, item.name)); - targetDirs.push(pathModule.join(localCfg.outTsAppsDir, item.name)); - }); - return targetDirs; - }() - } - }, - shell: { - getGitSHA: { - command: "git rev-parse HEAD", - options: { - callback: assignGitSHA - } - }, - }, - simplemocha: { - node: { - src: localCfg.nodeTestsDir + '/**/*.js' - } - }, - env: { - nodeTests: { - NODE_PATH: localCfg.outModulesDir, - } - } - }); - - grunt.loadNpmTasks("grunt-ts"); - grunt.loadNpmTasks("grunt-contrib-clean"); - grunt.loadNpmTasks("grunt-contrib-copy"); - grunt.loadNpmTasks("grunt-exec"); - grunt.loadNpmTasks("grunt-tslint"); - grunt.loadNpmTasks("grunt-multi-dest"); - grunt.loadNpmTasks("grunt-shell"); - grunt.loadNpmTasks("grunt-env"); - grunt.loadNpmTasks("grunt-simple-mocha"); - - var cloneTasks = function(originalTasks, taskNameSuffix) - { - var clonedTasks = []; - for(var i=0; i", + compiler: "node_modules/typescript/bin/tsc", + noEmitOnError: true + } } - }); + }, + tslint: { + build: { + files: { + src: localCfg.typeScriptSrcForTsLint + }, + options: { + configuration: grunt.file.readJSON("./build/tslint.json") + } + } + }, + exec: { + packModules: { + cmd: "npm pack", + cwd: localCfg.outModulesDir + "/" + }, + packDefinitions: { + cmd: "npm pack", + cwd: localCfg.outDefinitionsDir + "/" + }, + packApp: { + cmd: "npm pack", + cwd: "__dummy__" + }, + mochaNode: { + cmd: "grunt simplemocha:node" + } + }, + multidest: { + copyLicenseFiles: { + tasks: ["copy:appLicense"], + dest: function() { + var apps = getSubDirs(localCfg.srcAppsDir); + var targetDirs = []; + apps.forEach(function(item){ + targetDirs.push(pathModule.join(localCfg.outAppsDir, item.name)); + targetDirs.push(pathModule.join(localCfg.outTsAppsDir, item.name)); + }); + return targetDirs; + }() + } + }, + shell: { + getGitSHA: { + command: "git rev-parse HEAD", + options: { + callback: assignGitSHA + } + }, + }, + simplemocha: { + node: { + src: localCfg.nodeTestsDir + '/**/*.js' + } + }, + env: { + nodeTests: { + NODE_PATH: localCfg.outModulesDir, + } + } + }); + + grunt.loadNpmTasks("grunt-ts"); + grunt.loadNpmTasks("grunt-contrib-clean"); + grunt.loadNpmTasks("grunt-contrib-copy"); + grunt.loadNpmTasks("grunt-exec"); + grunt.loadNpmTasks("grunt-tslint"); + grunt.loadNpmTasks("grunt-multi-dest"); + grunt.loadNpmTasks("grunt-shell"); + grunt.loadNpmTasks("grunt-env"); + grunt.loadNpmTasks("grunt-simple-mocha"); + + var cloneTasks = function(originalTasks, taskNameSuffix) { + var clonedTasks = []; + for(var i=0; i Date: Mon, 19 Oct 2015 14:11:13 +0300 Subject: [PATCH 23/42] Fix the build --- build/run-testsapp.grunt.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/build/run-testsapp.grunt.js b/build/run-testsapp.grunt.js index 678727570..6d11aab72 100644 --- a/build/run-testsapp.grunt.js +++ b/build/run-testsapp.grunt.js @@ -7,7 +7,7 @@ module.exports = { androidRuntimePath:"/Users/erjan/tns-android.tgz", outfile:"./TestRunResult.txt", - workingDir=".testsapprun", + workingDir:".testsapprun", testsAppName:"TestsApp", pathToApk:"./platforms/android/build/outputs/apk/TestsApp-debug.apk", deployedAppName:"org.nativescript.$testsAppName", @@ -21,13 +21,13 @@ module.exports = { } }, mkdir: { - workindDir: { + workingDir: { options: { - create [localCfg.workingDir], + createi: [localCfg.workingDir], mode: 0700 } } - } + }, exec: { killEmulator: { cmd: "pkill '" + localCfg.emulatorProcessIdentifier + "'", @@ -35,8 +35,7 @@ module.exports = { }, runTestsApp: { cmd: "./runtestsapp.sh", - stdout: false, - cwd: "../" + stdout: false } } }); @@ -55,7 +54,7 @@ module.exports = { "clean:workingDir", "mkdir:workingDir", "exec:killEmulator", - "exec:runTestsApp", +// "exec:runTestsApp", From f416908374807d324c1c775a672210b08cddd37c Mon Sep 17 00:00:00 2001 From: Erjan Gavalji Date: Mon, 19 Oct 2015 17:42:41 +0300 Subject: [PATCH 24/42] Transfer the code up to the AndroidManifest editing to grunt --- build/run-testsapp.grunt.js | 70 +++++++++++++++++++++++++++++++++---- runtestsapp.sh | 24 ------------- 2 files changed, 64 insertions(+), 30 deletions(-) diff --git a/build/run-testsapp.grunt.js b/build/run-testsapp.grunt.js index 6d11aab72..c50099420 100644 --- a/build/run-testsapp.grunt.js +++ b/build/run-testsapp.grunt.js @@ -1,33 +1,73 @@ module.exports = { + run: function(grunt) { + var pathModule = require("path"); var localCfg = { + tnsPath: "tns", emulatorProcessIdentifier:".*emulator64-x86", emuAvdName:"Api19", androidRuntimePath:"/Users/erjan/tns-android.tgz", outfile:"./TestRunResult.txt", + androidRuntimePath: "/Users/erjan/tns-android.tgz", + androidFrameworkArgument: " --frameworkPath=/Users/erjan/tns-android.tgz", workingDir:".testsapprun", testsAppName:"TestsApp", + applicationDir: pathModule.join(".testsapprun", "TestsApp"), + appDir: pathModule.join(".testsapprun", "TestsApp", "app"), pathToApk:"./platforms/android/build/outputs/apk/TestsApp-debug.apk", deployedAppName:"org.nativescript.$testsAppName", - mainActivityName:"com.tns.NativeScriptActivity" + mainActivityName:"com.tns.NativeScriptActivity", + pathToCompiledTests: "bin/dist/apps/tests" } grunt.initConfig({ clean: { workingDir: { src: localCfg.workingDir + }, + originalAppDir: { + src: pathModule.join(localCfg.applicationDir, "app") + "/" } }, mkdir: { workingDir: { options: { - createi: [localCfg.workingDir], + create: [localCfg.workingDir], mode: 0700 } } }, + copy: { + testsAppToRunDir: { + src: "**/*.*", + dest: localCfg.appDir, + cwd: localCfg.pathToCompiledTests, + expand: true + }, + addAndroidPermissions: { + src: "AndroidManifest.xml", + dest: localCfg.applicationDir + "/platforms/android/src/main/", + cwd: localCfg.applicationDir + "/platforms/android/src/main", + expand: true, + options: { + process: function(content, srcPath) { + var newContent = content; + + var internetPermissionFinder = /(]*android\.permission\.INTERNET[^>]*>)/; + + if (!/uses-permission[^>]*android\.permission\.ACCESS_NETWORK_STATE/.test(content)) { + newContent = newContent.replace(internetPermissionFinder, "$1\n"); + } + if (!/uses-permission[^>]*android\.permission\.ACCESS_FINE_LOCATION/.test(content)) { + newContent = newContent.replace(internetPermissionFinder, "$1\n"); + } + return newContent; + } + } + } + }, exec: { killEmulator: { cmd: "pkill '" + localCfg.emulatorProcessIdentifier + "'", @@ -36,11 +76,22 @@ module.exports = { runTestsApp: { cmd: "./runtestsapp.sh", stdout: false + }, + startEmulator: { + cmd: "emulator -avd " + localCfg.emuAvdName + " -no-audio -no-window &", + stdout: true + }, + createApp: { + cmd: localCfg.tnsPath + " create " + localCfg.testsAppName, + cwd: localCfg.workingDir + }, + addAndroidPlatform: { + cmd: "tns platform add android " + localCfg.androidFrameworkArgument, + cwd: localCfg.applicationDir } } }); -// grunt.loadNpmTasks("grunt-contrib-copy"); // grunt.loadNpmTasks("grunt-tslint"); // grunt.loadNpmTasks("grunt-multi-dest"); // grunt.loadNpmTasks("grunt-shell"); @@ -49,18 +100,25 @@ module.exports = { grunt.loadNpmTasks("grunt-exec"); grunt.loadNpmTasks("grunt-mkdir"); grunt.loadNpmTasks("grunt-contrib-clean"); + grunt.loadNpmTasks("grunt-contrib-copy"); grunt.registerTask("testsapp", [ "clean:workingDir", "mkdir:workingDir", "exec:killEmulator", + "exec:startEmulator", // "exec:runTestsApp", + "exec:createApp", + "clean:originalAppDir", + "copy:testsAppToRunDir", + + "exec:addAndroidPlatform", + "copy:addAndroidPermissions", - - "exec:killEmulator", - "clean:workingDir" +// "exec:killEmulator", +// "clean:workingDir" ]); } } diff --git a/runtestsapp.sh b/runtestsapp.sh index 425f24007..f5351279a 100755 --- a/runtestsapp.sh +++ b/runtestsapp.sh @@ -14,30 +14,6 @@ mainActivityName=com.tns.NativeScriptActivity # Creating the emulator with: #android create avd -t "android-21" -n Api21 -b "default/x86" -echo "------------------------------------------------" -echo "Starting the emulator..." -time emulator -avd $emuAvdName -no-audio -no-window & - -echo "------------------------------------------------" -echo "Creating the app..." -time tns create $testsAppName -cd $testsAppName - -echo "------------------------------------------------" -echo "Removing the original template files..." -time rm app/*.* - -echo "------------------------------------------------" -echo "Copying the test app files..." -time cp -r ../../bin/dist/apps/tests/* ./app/ - -echo "------------------------------------------------" -echo "Adding the android platform..." -time tns platform add android --frameworkPath=$androidRuntimePath - -# #DO THE REPLACEMENTS IN THE Info.plist and AndroidManifest.xml -cp /Users/erjan/work/spikes/__DEL__/AndroidManifest.xml platforms/android/src/main/ - # GET THIS ONE FROM SOME PLACE... cp /Volumes/distributions/DailyBuilds/NativeScript/android-widgets/Stable/widgets.jar platforms/android/libs/ From b25e9d626f7fb7da65c8d4b6719afac246150921 Mon Sep 17 00:00:00 2001 From: Erjan Gavalji Date: Tue, 20 Oct 2015 10:50:11 +0300 Subject: [PATCH 25/42] Add whitespaces to the modified AndroidManifest.xml --- build/run-testsapp.grunt.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/build/run-testsapp.grunt.js b/build/run-testsapp.grunt.js index c50099420..ae391d901 100644 --- a/build/run-testsapp.grunt.js +++ b/build/run-testsapp.grunt.js @@ -55,13 +55,13 @@ module.exports = { process: function(content, srcPath) { var newContent = content; - var internetPermissionFinder = /(]*android\.permission\.INTERNET[^>]*>)/; + var internetPermissionFinder = /((\s*)]*android\.permission\.INTERNET[^>]*>)/; if (!/uses-permission[^>]*android\.permission\.ACCESS_NETWORK_STATE/.test(content)) { - newContent = newContent.replace(internetPermissionFinder, "$1\n"); + newContent = newContent.replace(internetPermissionFinder, "$1$2"); } if (!/uses-permission[^>]*android\.permission\.ACCESS_FINE_LOCATION/.test(content)) { - newContent = newContent.replace(internetPermissionFinder, "$1\n"); + newContent = newContent.replace(internetPermissionFinder, "$1$2"); } return newContent; } From d2f5bae59731bd84b8022e4667a70184ef030393 Mon Sep 17 00:00:00 2001 From: Erjan Gavalji Date: Tue, 20 Oct 2015 11:37:58 +0300 Subject: [PATCH 26/42] Add a build of the android app --- build/run-testsapp.grunt.js | 19 +++++++++++++------ runtestsapp.sh | 12 ------------ 2 files changed, 13 insertions(+), 18 deletions(-) diff --git a/build/run-testsapp.grunt.js b/build/run-testsapp.grunt.js index ae391d901..e03d639a2 100644 --- a/build/run-testsapp.grunt.js +++ b/build/run-testsapp.grunt.js @@ -28,7 +28,10 @@ module.exports = { src: localCfg.workingDir }, originalAppDir: { - src: pathModule.join(localCfg.applicationDir, "app") + "/" + src: [ + localCfg.appDir + "/*", + "!" + pathModule.join(localCfg.appDir, "App_Resources") + "" + ] } }, mkdir: { @@ -73,10 +76,6 @@ module.exports = { cmd: "pkill '" + localCfg.emulatorProcessIdentifier + "'", exitCode: [0, 1] }, - runTestsApp: { - cmd: "./runtestsapp.sh", - stdout: false - }, startEmulator: { cmd: "emulator -avd " + localCfg.emuAvdName + " -no-audio -no-window &", stdout: true @@ -88,6 +87,13 @@ module.exports = { addAndroidPlatform: { cmd: "tns platform add android " + localCfg.androidFrameworkArgument, cwd: localCfg.applicationDir + }, + buildAppAndroid: { + cmd: "tns build android", + cwd: localCfg.applicationDir + }, + restartAdb: { + cmd: "adb kill-server && adb start-server" } } }); @@ -107,7 +113,6 @@ module.exports = { "mkdir:workingDir", "exec:killEmulator", "exec:startEmulator", -// "exec:runTestsApp", "exec:createApp", "clean:originalAppDir", @@ -115,6 +120,8 @@ module.exports = { "exec:addAndroidPlatform", "copy:addAndroidPermissions", + "exec:buildAppAndroid", + "exec:restartAdb", // "exec:killEmulator", diff --git a/runtestsapp.sh b/runtestsapp.sh index f5351279a..a26ba15d8 100755 --- a/runtestsapp.sh +++ b/runtestsapp.sh @@ -17,18 +17,6 @@ mainActivityName=com.tns.NativeScriptActivity # GET THIS ONE FROM SOME PLACE... cp /Volumes/distributions/DailyBuilds/NativeScript/android-widgets/Stable/widgets.jar platforms/android/libs/ -echo "------------------------------------------------" -echo "Building the application..." -time tns build android - -echo "------------------------------------------------" -echo "Killing the adb server..." -time adb kill-server - -echo "------------------------------------------------" -echo "Starting the adb server..." -time adb start-server - echo "------------------------------------------------" echo "Uninstalling the app..." time adb uninstall $deployedAppName From 1543283f4a0cc3fe68a7435f425d089c6d64ebd6 Mon Sep 17 00:00:00 2001 From: Erjan Gavalji Date: Wed, 21 Oct 2015 09:55:34 +0300 Subject: [PATCH 27/42] Finish the transfer to grunt. Remove the bash script running the app --- build/run-testsapp.grunt.js | 60 +++++++++++++++++++++++++++---------- runtestsapp.sh | 38 ----------------------- 2 files changed, 45 insertions(+), 53 deletions(-) delete mode 100755 runtestsapp.sh diff --git a/build/run-testsapp.grunt.js b/build/run-testsapp.grunt.js index e03d639a2..b90f643b7 100644 --- a/build/run-testsapp.grunt.js +++ b/build/run-testsapp.grunt.js @@ -17,7 +17,7 @@ module.exports = { applicationDir: pathModule.join(".testsapprun", "TestsApp"), appDir: pathModule.join(".testsapprun", "TestsApp", "app"), pathToApk:"./platforms/android/build/outputs/apk/TestsApp-debug.apk", - deployedAppName:"org.nativescript.$testsAppName", + deployedAppName:"org.nativescript.TestsApp", mainActivityName:"com.tns.NativeScriptActivity", pathToCompiledTests: "bin/dist/apps/tests" } @@ -94,13 +94,38 @@ module.exports = { }, restartAdb: { cmd: "adb kill-server && adb start-server" + }, + uninstallExistingApp: { + cmd: "adb uninstall " + localCfg.deployedAppName + }, + installNewApp: { + cmd: "adb install " + localCfg.pathToApk, + cwd: localCfg.applicationDir + }, + startApp: { + cmd: "adb shell am start -n " + localCfg.deployedAppName + "/" + localCfg.mainActivityName + }, + collectLog: { + cmd: "./expect.exp " + localCfg.outfile, + stdout: false, + strerr: false + } + }, + shell: { + collectLog: { + command: "./expect.exp " + localCfg.outfile, + options: { + execOptions: { + maxBuffer: Infinity + } + } } } }); // grunt.loadNpmTasks("grunt-tslint"); // grunt.loadNpmTasks("grunt-multi-dest"); -// grunt.loadNpmTasks("grunt-shell"); + grunt.loadNpmTasks("grunt-shell"); // grunt.loadNpmTasks("grunt-env"); // grunt.loadNpmTasks("grunt-simple-mocha"); grunt.loadNpmTasks("grunt-exec"); @@ -109,19 +134,24 @@ module.exports = { grunt.loadNpmTasks("grunt-contrib-copy"); grunt.registerTask("testsapp", [ - "clean:workingDir", - "mkdir:workingDir", - "exec:killEmulator", - "exec:startEmulator", - - "exec:createApp", - "clean:originalAppDir", - "copy:testsAppToRunDir", - - "exec:addAndroidPlatform", - "copy:addAndroidPermissions", - "exec:buildAppAndroid", - "exec:restartAdb", +// "clean:workingDir", +// "mkdir:workingDir", +// "exec:killEmulator", +// "exec:startEmulator", +// +// "exec:createApp", +// "clean:originalAppDir", +// "copy:testsAppToRunDir", +// +// "exec:addAndroidPlatform", +// "copy:addAndroidPermissions", +// "exec:buildAppAndroid", +// "exec:restartAdb", +// + "exec:uninstallExistingApp", + "exec:installNewApp", + "exec:startApp", + "shell:collectLog", // "exec:killEmulator", diff --git a/runtestsapp.sh b/runtestsapp.sh deleted file mode 100755 index a26ba15d8..000000000 --- a/runtestsapp.sh +++ /dev/null @@ -1,38 +0,0 @@ -workingdir=./.testsapprun -startdir=$(pwd) - -emuProcId=".*emulator64-x86" -emuAvdName=Api19 -androidRuntimePath=/Users/erjan/tns-android.tgz -outfile=./TestRunResult.txt - -testsAppName=TestsApp -pathToApk=./platforms/android/build/outputs/apk/$testsAppName-debug.apk -deployedAppName=org.nativescript.$testsAppName -mainActivityName=com.tns.NativeScriptActivity - -# Creating the emulator with: -#android create avd -t "android-21" -n Api21 -b "default/x86" - -# GET THIS ONE FROM SOME PLACE... -cp /Volumes/distributions/DailyBuilds/NativeScript/android-widgets/Stable/widgets.jar platforms/android/libs/ - -echo "------------------------------------------------" -echo "Uninstalling the app..." -time adb uninstall $deployedAppName - -echo "------------------------------------------------" -echo "Installing the app..." -time adb install $pathToApk - -echo "------------------------------------------------" -echo "Starting the app..." -time adb shell am start -n $deployedAppName/$mainActivityName - -cd $startdir - -echo "------------------------------------------------" -echo "Waiting for the tests to finish executing..." -time ./expect.exp $outfile - -rm -rd $workingdir From 8eff24e56b76eb48c38f6b9dac2c05ae51678670 Mon Sep 17 00:00:00 2001 From: Erjan Gavalji Date: Wed, 21 Oct 2015 11:22:56 +0300 Subject: [PATCH 28/42] Change grunt to do a full run --- build/run-testsapp.grunt.js | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/build/run-testsapp.grunt.js b/build/run-testsapp.grunt.js index b90f643b7..777c015fc 100644 --- a/build/run-testsapp.grunt.js +++ b/build/run-testsapp.grunt.js @@ -134,28 +134,28 @@ module.exports = { grunt.loadNpmTasks("grunt-contrib-copy"); grunt.registerTask("testsapp", [ -// "clean:workingDir", -// "mkdir:workingDir", -// "exec:killEmulator", -// "exec:startEmulator", -// -// "exec:createApp", -// "clean:originalAppDir", -// "copy:testsAppToRunDir", -// -// "exec:addAndroidPlatform", -// "copy:addAndroidPermissions", -// "exec:buildAppAndroid", -// "exec:restartAdb", -// + "clean:workingDir", + "mkdir:workingDir", + "exec:killEmulator", + "exec:startEmulator", + + "exec:createApp", + "clean:originalAppDir", + "copy:testsAppToRunDir", + + "exec:addAndroidPlatform", + "copy:addAndroidPermissions", + "exec:buildAppAndroid", + "exec:restartAdb", + "exec:uninstallExistingApp", "exec:installNewApp", "exec:startApp", "shell:collectLog", -// "exec:killEmulator", -// "clean:workingDir" + "exec:killEmulator", + "clean:workingDir" ]); } } From 4b37a7ec9547edca2c7fd4ed627f437b651fd0e4 Mon Sep 17 00:00:00 2001 From: Erjan Gavalji Date: Wed, 21 Oct 2015 13:50:41 +0300 Subject: [PATCH 29/42] Introduce the platform argument. Update all the run statements to --platform=Android only --- build/run-testsapp.grunt.js | 67 +++++++++++++++++++++---------------- 1 file changed, 38 insertions(+), 29 deletions(-) diff --git a/build/run-testsapp.grunt.js b/build/run-testsapp.grunt.js index 777c015fc..74a463ad6 100644 --- a/build/run-testsapp.grunt.js +++ b/build/run-testsapp.grunt.js @@ -3,6 +3,15 @@ module.exports = { run: function(grunt) { var pathModule = require("path"); + //Construct and validate the arguments + var args = { + platform: grunt.option("platform") + }; + + (function validateInput(){ + if (!(/^(Android|iOS)$/).test(args.platform)) { throw new Error("Invalid target platform specified! Use --platform=Android|iOS"); } + }()); + var localCfg = { tnsPath: "tns", emulatorProcessIdentifier:".*emulator64-x86", @@ -19,7 +28,9 @@ module.exports = { pathToApk:"./platforms/android/build/outputs/apk/TestsApp-debug.apk", deployedAppName:"org.nativescript.TestsApp", mainActivityName:"com.tns.NativeScriptActivity", - pathToCompiledTests: "bin/dist/apps/tests" + pathToCompiledTests: "bin/dist/apps/tests", + + platform: args.platform } grunt.initConfig({ @@ -72,11 +83,11 @@ module.exports = { } }, exec: { - killEmulator: { + killAndroidEmulator: { cmd: "pkill '" + localCfg.emulatorProcessIdentifier + "'", exitCode: [0, 1] }, - startEmulator: { + startAndroidEmulator: { cmd: "emulator -avd " + localCfg.emuAvdName + " -no-audio -no-window &", stdout: true }, @@ -88,31 +99,26 @@ module.exports = { cmd: "tns platform add android " + localCfg.androidFrameworkArgument, cwd: localCfg.applicationDir }, - buildAppAndroid: { + buildAndroidApp: { cmd: "tns build android", cwd: localCfg.applicationDir }, restartAdb: { cmd: "adb kill-server && adb start-server" }, - uninstallExistingApp: { + uninstallExistingAndroidApp: { cmd: "adb uninstall " + localCfg.deployedAppName }, - installNewApp: { + installNewAndroidApp: { cmd: "adb install " + localCfg.pathToApk, cwd: localCfg.applicationDir }, - startApp: { + startAndroidApp: { cmd: "adb shell am start -n " + localCfg.deployedAppName + "/" + localCfg.mainActivityName - }, - collectLog: { - cmd: "./expect.exp " + localCfg.outfile, - stdout: false, - strerr: false } }, shell: { - collectLog: { + collectAndroidLog: { command: "./expect.exp " + localCfg.outfile, options: { execOptions: { @@ -123,38 +129,41 @@ module.exports = { } }); -// grunt.loadNpmTasks("grunt-tslint"); -// grunt.loadNpmTasks("grunt-multi-dest"); grunt.loadNpmTasks("grunt-shell"); -// grunt.loadNpmTasks("grunt-env"); -// grunt.loadNpmTasks("grunt-simple-mocha"); grunt.loadNpmTasks("grunt-exec"); grunt.loadNpmTasks("grunt-mkdir"); grunt.loadNpmTasks("grunt-contrib-clean"); grunt.loadNpmTasks("grunt-contrib-copy"); + var getPlatformSpecificTask = function(templatedTaskName) { + return templatedTaskName.replace(/\{platform\}/, localCfg.platform); + } + + grunt.registerTask("doPostPlatformAdd", [ + "exec:restartAdb" + ]); + grunt.registerTask("testsapp", [ "clean:workingDir", "mkdir:workingDir", - "exec:killEmulator", - "exec:startEmulator", + getPlatformSpecificTask("exec:kill{platform}Emulator"), + getPlatformSpecificTask("exec:start{platform}Emulator"), "exec:createApp", "clean:originalAppDir", "copy:testsAppToRunDir", - "exec:addAndroidPlatform", - "copy:addAndroidPermissions", - "exec:buildAppAndroid", - "exec:restartAdb", + getPlatformSpecificTask("exec:add{platform}Platform"), + getPlatformSpecificTask("copy:add{platform}Permissions"), + getPlatformSpecificTask("exec:build{platform}App"), + "doPostPlatformAdd", - "exec:uninstallExistingApp", - "exec:installNewApp", - "exec:startApp", - "shell:collectLog", + getPlatformSpecificTask("exec:uninstallExisting{platform}App"), + getPlatformSpecificTask("exec:installNew{platform}App"), + getPlatformSpecificTask("exec:start{platform}App"), + getPlatformSpecificTask("shell:collect{platform}Log"), - - "exec:killEmulator", + getPlatformSpecificTask("exec:kill{platform}Emulator"), "clean:workingDir" ]); } From 58d05747cda47ffb34a2b0a682447858a2e5de96 Mon Sep 17 00:00:00 2001 From: Erjan Gavalji Date: Wed, 21 Oct 2015 15:15:50 +0300 Subject: [PATCH 30/42] Add more parameters. Add a basic readme for running the tests --- build/run-testsapp.grunt.js | 7 +++++-- running-tests.md | 29 +++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 running-tests.md diff --git a/build/run-testsapp.grunt.js b/build/run-testsapp.grunt.js index 74a463ad6..2e3630c5d 100644 --- a/build/run-testsapp.grunt.js +++ b/build/run-testsapp.grunt.js @@ -6,6 +6,11 @@ module.exports = { //Construct and validate the arguments var args = { platform: grunt.option("platform") + tnsPath: grunt.option("tnsPath") + emulatorProcessIdentifier: grunt.option("emuPId") + emuAvdName: grunt.option("avdNameToStart") + outFile: grunt.option("logFilePath") + androidRuntimePath: grunt.option("androidRuntimePath") }; (function validateInput(){ @@ -16,9 +21,7 @@ module.exports = { tnsPath: "tns", emulatorProcessIdentifier:".*emulator64-x86", emuAvdName:"Api19", - androidRuntimePath:"/Users/erjan/tns-android.tgz", outfile:"./TestRunResult.txt", - androidRuntimePath: "/Users/erjan/tns-android.tgz", androidFrameworkArgument: " --frameworkPath=/Users/erjan/tns-android.tgz", workingDir:".testsapprun", diff --git a/running-tests.md b/running-tests.md new file mode 100644 index 000000000..5a44b18a6 --- /dev/null +++ b/running-tests.md @@ -0,0 +1,29 @@ +Running NativeScript Tests +========================= + + +# Details +NativeScript is a framework for building applications on mobile devices. Many +of its components are UI elements which get tested most efficiently on the +respective device or simulator/emulator. Thus, running the tests involves +the following steps: +- Create a NativeScript project +- Build it to a native image +- Start a simulator/emulator +- Deploy the application image +- Start the application +- Monitor its output +- Gather test output + +# Prerequisites +- Node JS +- grunt +- NativeScript CLI +- Android/iOS setup +- expect + +# Sample run: +``` +grunt testsapp --platform=Android [--tnsPath="tns"] --emuPId=".*emulator64-x86" +--emuAvdName="Api19" [--logFilePath="./TestRunResult.txt"] [--androidRuntimePath="./tns-android.tgz"] +``` From 24d2bb40c91b8286cb1b17207b689f97acd0b64a Mon Sep 17 00:00:00 2001 From: Erjan Gavalji Date: Thu, 22 Oct 2015 11:41:11 +0300 Subject: [PATCH 31/42] Validate and assign the rest of the parameters. Check for android ones only. Add just small notes to the article --- build/run-testsapp.grunt.js | 39 ++++++++++++++++++++++++------------- running-tests.md | 4 +++- 2 files changed, 29 insertions(+), 14 deletions(-) diff --git a/build/run-testsapp.grunt.js b/build/run-testsapp.grunt.js index 2e3630c5d..58333acb4 100644 --- a/build/run-testsapp.grunt.js +++ b/build/run-testsapp.grunt.js @@ -5,24 +5,37 @@ module.exports = { //Construct and validate the arguments var args = { - platform: grunt.option("platform") - tnsPath: grunt.option("tnsPath") - emulatorProcessIdentifier: grunt.option("emuPId") - emuAvdName: grunt.option("avdNameToStart") - outFile: grunt.option("logFilePath") - androidRuntimePath: grunt.option("androidRuntimePath") + platform: grunt.option("platform"), + tnsPath: grunt.option("tnsPath"), + emulatorProcessIdentifier: grunt.option("emuPId"), + emuAvdName: grunt.option("avd"), + outFile: grunt.option("logFilePath"), + androidRuntimePath: grunt.option("androidRuntimePath"), + showEmu: grunt.option("showEmu") }; (function validateInput(){ - if (!(/^(Android|iOS)$/).test(args.platform)) { throw new Error("Invalid target platform specified! Use --platform=Android|iOS"); } + if (!(/^(Android|iOS)$/).test(args.platform)) { + throw new Error("Invalid target platform specified! Use --platform=Android|iOS"); + } + + if (args.platform === "Android") { + if (!args.emulatorProcessIdentifier) { + throw new Error("Please, specify an identifier of the emulator process so that it can be stopped (--emuPId=...). Too many emulators started might cause machine overload"); + } + if (!args.emuAvdName) { + throw new Error("Please, specify the name of the AVD to start (--avd=...)."); + } + } }()); var localCfg = { - tnsPath: "tns", - emulatorProcessIdentifier:".*emulator64-x86", - emuAvdName:"Api19", - outfile:"./TestRunResult.txt", - androidFrameworkArgument: " --frameworkPath=/Users/erjan/tns-android.tgz", + tnsPath: args.tnsPath || "tns", + emulatorProcessIdentifier: args.emulatorProcessIdentifier, + emuAvdName: args.emuAvdName, + outfile: args.outFile || "./TestRunResult.txt", + androidFrameworkArgument: args.androidRuntimePath ? " --frameworkPath=" + args.androidRuntimePath : "", + showEmu: args.showEmu || false, workingDir:".testsapprun", testsAppName:"TestsApp", @@ -91,7 +104,7 @@ module.exports = { exitCode: [0, 1] }, startAndroidEmulator: { - cmd: "emulator -avd " + localCfg.emuAvdName + " -no-audio -no-window &", + cmd: "emulator -avd " + localCfg.emuAvdName + " -no-audio " + (args.showEmu ? "" : "-no-window") + "&", stdout: true }, createApp: { diff --git a/running-tests.md b/running-tests.md index 5a44b18a6..10d872e8e 100644 --- a/running-tests.md +++ b/running-tests.md @@ -22,8 +22,10 @@ the following steps: - Android/iOS setup - expect +# Arguments: + # Sample run: ``` grunt testsapp --platform=Android [--tnsPath="tns"] --emuPId=".*emulator64-x86" ---emuAvdName="Api19" [--logFilePath="./TestRunResult.txt"] [--androidRuntimePath="./tns-android.tgz"] +--avd="Api19" [--logFilePath="./TestRunResult.txt"] [--androidRuntimePath="./tns-android.tgz"] --showEmu=true ``` From a60cedcde390d2a7f37bcfb2ebfd77ede900e193 Mon Sep 17 00:00:00 2001 From: Erjan Gavalji Date: Thu, 22 Oct 2015 15:00:10 +0300 Subject: [PATCH 32/42] Describe the parameters --- running-tests.md | 36 +++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/running-tests.md b/running-tests.md index 10d872e8e..e42f16560 100644 --- a/running-tests.md +++ b/running-tests.md @@ -7,13 +7,17 @@ NativeScript is a framework for building applications on mobile devices. Many of its components are UI elements which get tested most efficiently on the respective device or simulator/emulator. Thus, running the tests involves the following steps: -- Create a NativeScript project -- Build it to a native image -- Start a simulator/emulator -- Deploy the application image -- Start the application -- Monitor its output -- Gather test output + - Create a NativeScript project + - Build it to a native image + - Start a simulator/emulator + - Deploy the application image + - Start the application + - Monitor its output + - Gather test output + +These steps are automated via the `run-testsapp.grunt.js` grunt script, located +under the `build` directory. It gets called by the main `gruntfile.js`, but is +split to a separate file for simplicity. # Prerequisites - Node JS @@ -24,6 +28,24 @@ the following steps: # Arguments: + > As this is a [grunt](http://gruntjs.com/) script, the arguments are passed + the grunt way (--argName=argValue) + + - `platform`: The platform to run the tests application on: iOS or Android + - `tnsPath`: [Optional] The path to the NativeScript executable. If not + found, the globally installed `tns` gets called. + - `emuPId`: The ID of the emulator process. This one is used to refresh the + emulator process, as the emulator sometimes hangs. + - `avd`: The name of the Android Virtual Device to be started to run the + tests. + - `logFilePath`: [Optional] The path to the file, which the test app run + log will get saved to. Defaults to "./TestRunResult.txt". + - `androidRuntimePath`: [Optional] The path to a custom Android Runtime + package to have the tests run onto. If not specified, the newest available + build on [npmjs.com](http://npmjs.com). + - `showEmu`: [Optional] Specifies whether the emulator should get launched + in a window or headless mode. Defaults to `false`. + # Sample run: ``` grunt testsapp --platform=Android [--tnsPath="tns"] --emuPId=".*emulator64-x86" From 8e6b4b562884eadda833b58f2ca3601715399c27 Mon Sep 17 00:00:00 2001 From: Erjan Gavalji Date: Thu, 22 Oct 2015 15:04:23 +0300 Subject: [PATCH 33/42] Improve the readability of the instructions --- running-tests.md | 47 ++++++++++++++++++++++++----------------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/running-tests.md b/running-tests.md index e42f16560..2102c1c87 100644 --- a/running-tests.md +++ b/running-tests.md @@ -7,13 +7,14 @@ NativeScript is a framework for building applications on mobile devices. Many of its components are UI elements which get tested most efficiently on the respective device or simulator/emulator. Thus, running the tests involves the following steps: - - Create a NativeScript project - - Build it to a native image - - Start a simulator/emulator - - Deploy the application image - - Start the application - - Monitor its output - - Gather test output + +- Create a NativeScript project +- Build it to a native image +- Start a simulator/emulator +- Deploy the application image +- Start the application +- Monitor its output +- Gather test output These steps are automated via the `run-testsapp.grunt.js` grunt script, located under the `build` directory. It gets called by the main `gruntfile.js`, but is @@ -28,23 +29,23 @@ split to a separate file for simplicity. # Arguments: - > As this is a [grunt](http://gruntjs.com/) script, the arguments are passed - the grunt way (--argName=argValue) +>As this is a [grunt](http://gruntjs.com/) script, the arguments are passed + the grunt way (`--argName=argValue`) - - `platform`: The platform to run the tests application on: iOS or Android - - `tnsPath`: [Optional] The path to the NativeScript executable. If not - found, the globally installed `tns` gets called. - - `emuPId`: The ID of the emulator process. This one is used to refresh the - emulator process, as the emulator sometimes hangs. - - `avd`: The name of the Android Virtual Device to be started to run the - tests. - - `logFilePath`: [Optional] The path to the file, which the test app run - log will get saved to. Defaults to "./TestRunResult.txt". - - `androidRuntimePath`: [Optional] The path to a custom Android Runtime - package to have the tests run onto. If not specified, the newest available - build on [npmjs.com](http://npmjs.com). - - `showEmu`: [Optional] Specifies whether the emulator should get launched - in a window or headless mode. Defaults to `false`. +- `platform`: The platform to run the tests application on: iOS or Android +- `showEmu`: [Optional] Specifies whether the emulator should get launched +in a window or headless mode. Defaults to `false`. +- `tnsPath`: [Optional] The path to the NativeScript executable. If not +found, the globally installed `tns` gets called. +- `emuPId`: The ID of the emulator process. This one is used to refresh the +emulator process, as the emulator sometimes hangs. +- `avd`: The name of the Android Virtual Device to be started to run the +tests. +- `logFilePath`: [Optional] The path to the file, which the test app run +log will get saved to. Defaults to "./TestRunResult.txt". +- `androidRuntimePath`: [Optional] The path to a custom Android Runtime +package to have the tests run onto. If not specified, the newest available +build on [npmjs.com](http://npmjs.com). # Sample run: ``` From 6ad3474803bb1a56226e1e7c3d08c7aa6b31bf73 Mon Sep 17 00:00:00 2001 From: Erjan Gavalji Date: Fri, 23 Oct 2015 15:18:10 +0300 Subject: [PATCH 34/42] Add empty tasks to update the modules. Broken. --- build/run-testsapp.grunt.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/build/run-testsapp.grunt.js b/build/run-testsapp.grunt.js index 58333acb4..6b1092a22 100644 --- a/build/run-testsapp.grunt.js +++ b/build/run-testsapp.grunt.js @@ -3,9 +3,12 @@ module.exports = { run: function(grunt) { var pathModule = require("path"); + var modulesPackageConfig = grunt.file.readJSON('package.json'); + //Construct and validate the arguments var args = { platform: grunt.option("platform"), + modulesPath: grunt.option("modulespath"), tnsPath: grunt.option("tnsPath"), emulatorProcessIdentifier: grunt.option("emuPId"), emuAvdName: grunt.option("avd"), @@ -32,6 +35,7 @@ module.exports = { var localCfg = { tnsPath: args.tnsPath || "tns", emulatorProcessIdentifier: args.emulatorProcessIdentifier, + modulesPath: args.modulesPath || "./bin/dist/tns-core-modules-" + modulesPackageConfig.version + ".tgz", emuAvdName: args.emuAvdName, outfile: args.outFile || "./TestRunResult.txt", androidFrameworkArgument: args.androidRuntimePath ? " --frameworkPath=" + args.androidRuntimePath : "", @@ -168,6 +172,8 @@ module.exports = { "exec:createApp", "clean:originalAppDir", "copy:testsAppToRunDir", + "untar:modules", + "copy:updateModules", getPlatformSpecificTask("exec:add{platform}Platform"), getPlatformSpecificTask("copy:add{platform}Permissions"), From 0445173757cd01c25333b3fd20f25e5fcecd39f9 Mon Sep 17 00:00:00 2001 From: Erjan Gavalji Date: Mon, 26 Oct 2015 11:45:57 +0200 Subject: [PATCH 35/42] Now update the modules --- build/run-testsapp.grunt.js | 23 ++++++++++++++++++++++- package.json | 1 + 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/build/run-testsapp.grunt.js b/build/run-testsapp.grunt.js index 6b1092a22..7e7c1c91a 100644 --- a/build/run-testsapp.grunt.js +++ b/build/run-testsapp.grunt.js @@ -63,6 +63,12 @@ module.exports = { localCfg.appDir + "/*", "!" + pathModule.join(localCfg.appDir, "App_Resources") + "" ] + }, + modules: { + src: pathModule.join(localCfg.applicationDir, "node_modules", "tns-core-modules") + }, + tempExtractedModules: { + src: pathModule.join(localCfg.applicationDir, "node_modules", "package") } }, mkdir: { @@ -80,6 +86,12 @@ module.exports = { cwd: localCfg.pathToCompiledTests, expand: true }, + modulesToDir: { + expand: true, + src: "**/*.*", + cwd: pathModule.join(localCfg.applicationDir, "node_modules", "package"), + dest: pathModule.join(localCfg.applicationDir, "node_modules", "tns-core-modules") + }, addAndroidPermissions: { src: "AndroidManifest.xml", dest: localCfg.applicationDir + "/platforms/android/src/main/", @@ -137,6 +149,12 @@ module.exports = { cmd: "adb shell am start -n " + localCfg.deployedAppName + "/" + localCfg.mainActivityName } }, + untar: { + modules: { + src: localCfg.modulesPath, + dest: pathModule.join(localCfg.applicationDir, "node_modules") + } + }, shell: { collectAndroidLog: { command: "./expect.exp " + localCfg.outfile, @@ -154,6 +172,7 @@ module.exports = { grunt.loadNpmTasks("grunt-mkdir"); grunt.loadNpmTasks("grunt-contrib-clean"); grunt.loadNpmTasks("grunt-contrib-copy"); + grunt.loadNpmTasks("grunt-untar"); var getPlatformSpecificTask = function(templatedTaskName) { return templatedTaskName.replace(/\{platform\}/, localCfg.platform); @@ -172,8 +191,10 @@ module.exports = { "exec:createApp", "clean:originalAppDir", "copy:testsAppToRunDir", + "clean:modules", "untar:modules", - "copy:updateModules", + "copy:modulesToDir", + "clean:tempExtractedModules", getPlatformSpecificTask("exec:add{platform}Platform"), getPlatformSpecificTask("copy:add{platform}Permissions"), diff --git a/package.json b/package.json index 487c4a0a3..bdfc82587 100644 --- a/package.json +++ b/package.json @@ -25,6 +25,7 @@ "grunt-simple-mocha": "0.4.0", "grunt-ts": "5.0.0-beta.5", "grunt-tslint": "2.5.0", + "grunt-untar": "0.0.1", "mocha": "2.2.5", "typescript": "1.6.2" } From cfb6c415424c1b1529ccc3368fc052ea96096d83 Mon Sep 17 00:00:00 2001 From: Erjan Gavalji Date: Mon, 26 Oct 2015 15:02:47 +0200 Subject: [PATCH 36/42] Fix the casing of the modulesPath argument; update the readme --- build/run-testsapp.grunt.js | 2 +- running-tests.md | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/build/run-testsapp.grunt.js b/build/run-testsapp.grunt.js index 7e7c1c91a..3c9204ffd 100644 --- a/build/run-testsapp.grunt.js +++ b/build/run-testsapp.grunt.js @@ -8,7 +8,7 @@ module.exports = { //Construct and validate the arguments var args = { platform: grunt.option("platform"), - modulesPath: grunt.option("modulespath"), + modulesPath: grunt.option("modulesPath"), tnsPath: grunt.option("tnsPath"), emulatorProcessIdentifier: grunt.option("emuPId"), emuAvdName: grunt.option("avd"), diff --git a/running-tests.md b/running-tests.md index 2102c1c87..63a56ead4 100644 --- a/running-tests.md +++ b/running-tests.md @@ -35,6 +35,9 @@ split to a separate file for simplicity. - `platform`: The platform to run the tests application on: iOS or Android - `showEmu`: [Optional] Specifies whether the emulator should get launched in a window or headless mode. Defaults to `false`. +- `modulesPath`: [Optional] The path to the tns-core-modules npm package +to be tested. Defaults to the npm package, located in the current +`bin/dist/` folder. The modules must have been built before that. - `tnsPath`: [Optional] The path to the NativeScript executable. If not found, the globally installed `tns` gets called. - `emuPId`: The ID of the emulator process. This one is used to refresh the From 8355634274fe511afb394dc55eeaf1bbb9ea4503 Mon Sep 17 00:00:00 2001 From: Erjan Gavalji Date: Mon, 26 Oct 2015 18:01:28 +0200 Subject: [PATCH 37/42] Reconfigure android-specific tasks and arguments to be cross-platform. Update documentation --- build/run-testsapp.grunt.js | 58 +++++++++++++++++++++++++++---------- running-tests.md | 6 ++-- 2 files changed, 47 insertions(+), 17 deletions(-) diff --git a/build/run-testsapp.grunt.js b/build/run-testsapp.grunt.js index 3c9204ffd..238ab99a2 100644 --- a/build/run-testsapp.grunt.js +++ b/build/run-testsapp.grunt.js @@ -13,7 +13,7 @@ module.exports = { emulatorProcessIdentifier: grunt.option("emuPId"), emuAvdName: grunt.option("avd"), outFile: grunt.option("logFilePath"), - androidRuntimePath: grunt.option("androidRuntimePath"), + runtimePath: grunt.option("runtimePath"), showEmu: grunt.option("showEmu") }; @@ -38,7 +38,7 @@ module.exports = { modulesPath: args.modulesPath || "./bin/dist/tns-core-modules-" + modulesPackageConfig.version + ".tgz", emuAvdName: args.emuAvdName, outfile: args.outFile || "./TestRunResult.txt", - androidFrameworkArgument: args.androidRuntimePath ? " --frameworkPath=" + args.androidRuntimePath : "", + frameworkArgument: args.runtimePath ? " --frameworkPath=" + args.runtimePath : "", showEmu: args.showEmu || false, workingDir:".testsapprun", @@ -112,6 +112,27 @@ module.exports = { return newContent; } } + }, + addiOSPermissions: { + src: localCfg.testsAppName + "-Info.plist", + dest: pathModule.join(localCfg.applicationDir,"/platforms/ios/", localCfg.testsAppName) + "/", + cwd: pathModule.join(localCfg.applicationDir,"/platforms/ios/", localCfg.testsAppName), + expand: true, + options: { + process: function(content, srcPath) { + var newContent = content; + + var lastDictLocator = /(<\/dict>\s*<\/plist>)$/gm; + + if (!/NSAppTransportSecurity/.test(content)) { + newContent = newContent.replace(lastDictLocator, "NSAppTransportSecurity\n$1"); + } + if (!/NSAllowsArbitraryLoads/.test(content)) { + newContent = newContent.replace(lastDictLocator, "\nNSAllowsArbitraryLoads\n\n\n$1"); + } + return newContent; + } + } } }, exec: { @@ -127,12 +148,8 @@ module.exports = { cmd: localCfg.tnsPath + " create " + localCfg.testsAppName, cwd: localCfg.workingDir }, - addAndroidPlatform: { - cmd: "tns platform add android " + localCfg.androidFrameworkArgument, - cwd: localCfg.applicationDir - }, - buildAndroidApp: { - cmd: "tns build android", + addPlatform: { + cmd: "tns platform add " + localCfg.platform.toLowerCase() + " " + localCfg.frameworkArgument, cwd: localCfg.applicationDir }, restartAdb: { @@ -163,7 +180,16 @@ module.exports = { maxBuffer: Infinity } } - } + }, + buildApp: { + command: "tns build " + localCfg.platform.toLowerCase(), + options: { + execOptions: { + maxBuffer: Infinity, + cwd: localCfg.applicationDir + } + } + }, } }); @@ -178,15 +204,17 @@ module.exports = { return templatedTaskName.replace(/\{platform\}/, localCfg.platform); } - grunt.registerTask("doPostPlatformAdd", [ + grunt.registerTask("doPostPlatformAddAndroid", [ "exec:restartAdb" ]); + grunt.registerTask("doPostPlatformAddiOS", [ + ]); grunt.registerTask("testsapp", [ "clean:workingDir", "mkdir:workingDir", - getPlatformSpecificTask("exec:kill{platform}Emulator"), - getPlatformSpecificTask("exec:start{platform}Emulator"), +// getPlatformSpecificTask("exec:kill{platform}Emulator"), +// getPlatformSpecificTask("exec:start{platform}Emulator"), "exec:createApp", "clean:originalAppDir", @@ -196,10 +224,10 @@ module.exports = { "copy:modulesToDir", "clean:tempExtractedModules", - getPlatformSpecificTask("exec:add{platform}Platform"), + "exec:addPlatform", getPlatformSpecificTask("copy:add{platform}Permissions"), - getPlatformSpecificTask("exec:build{platform}App"), - "doPostPlatformAdd", + "shell:buildApp", + getPlatformSpecificTask("doPostPlatformAdd{platform}"), getPlatformSpecificTask("exec:uninstallExisting{platform}App"), getPlatformSpecificTask("exec:installNew{platform}App"), diff --git a/running-tests.md b/running-tests.md index 63a56ead4..4cce032b6 100644 --- a/running-tests.md +++ b/running-tests.md @@ -46,9 +46,11 @@ emulator process, as the emulator sometimes hangs. tests. - `logFilePath`: [Optional] The path to the file, which the test app run log will get saved to. Defaults to "./TestRunResult.txt". -- `androidRuntimePath`: [Optional] The path to a custom Android Runtime +- `runtimePath`: [Optional] The path to a custom iOS or Android Runtime package to have the tests run onto. If not specified, the newest available -build on [npmjs.com](http://npmjs.com). +build on [npmjs.com](http://npmjs.com) - +[tns-ios](https://www.npmjs.com/package/tns-ios) or +[tns-android](https://www.npmjs.com/package/tns-android). # Sample run: ``` From 94a7499aadd39110c67fd5786b9d69831d350563 Mon Sep 17 00:00:00 2001 From: Erjan Gavalji Date: Tue, 27 Oct 2015 17:14:08 +0200 Subject: [PATCH 38/42] Add a breaking command --- build/run-testsapp.grunt.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/build/run-testsapp.grunt.js b/build/run-testsapp.grunt.js index 238ab99a2..7bc5c4684 100644 --- a/build/run-testsapp.grunt.js +++ b/build/run-testsapp.grunt.js @@ -164,6 +164,9 @@ module.exports = { }, startAndroidApp: { cmd: "adb shell am start -n " + localCfg.deployedAppName + "/" + localCfg.mainActivityName + }, + uninstallExistingiOSApp: { + cmd: "bash -c 'exit 1'" } }, untar: { From 094f9f487003af66d298c25069cabe741dfa404a Mon Sep 17 00:00:00 2001 From: Erjan Gavalji Date: Tue, 27 Oct 2015 17:49:19 +0200 Subject: [PATCH 39/42] Add the run script used to ease the development... --- run.sh | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100755 run.sh diff --git a/run.sh b/run.sh new file mode 100755 index 000000000..f7c75bddb --- /dev/null +++ b/run.sh @@ -0,0 +1,7 @@ +#! /bin/bash + +#grunt testsapp --verbose --platform=Android --emuPId=".*emulator64-x86" --avd="Api19" --logFilePath="./TestRunResult.txt" --runtimePath="/Users/erjan/tns-android.tgz" --showEmu=true --modulesPath=/Volumes/distributions/DailyBuilds/NativeScript/tns-modules/Stable/tns-core-modules.tgz + +grunt testsapp --verbose --platform=iOS --logFilePath="./TestRunResult.txt" --runtimePath="/Users/erjan/tns-ios.tgz" --showEmu=true --modulesPath=/Volumes/distributions/DailyBuilds/NativeScript/tns-modules/Stable/tns-core-modules.tgz + + From c1b30428d06fa741a8eaf2843668e7836ba6b560 Mon Sep 17 00:00:00 2001 From: Erjan Gavalji Date: Wed, 28 Oct 2015 15:53:40 +0200 Subject: [PATCH 40/42] Uninstall, install and start the app --- build/run-testsapp.grunt.js | 72 +++++++++++++++++++++++-------------- run.sh | 2 +- 2 files changed, 47 insertions(+), 27 deletions(-) diff --git a/build/run-testsapp.grunt.js b/build/run-testsapp.grunt.js index 7bc5c4684..73c3f5111 100644 --- a/build/run-testsapp.grunt.js +++ b/build/run-testsapp.grunt.js @@ -45,7 +45,8 @@ module.exports = { testsAppName:"TestsApp", applicationDir: pathModule.join(".testsapprun", "TestsApp"), appDir: pathModule.join(".testsapprun", "TestsApp", "app"), - pathToApk:"./platforms/android/build/outputs/apk/TestsApp-debug.apk", + pathToApk: "./platforms/android/build/outputs/apk/TestsApp-debug.apk", + pathToApp: "./platforms/ios/build/emulator/TestsApp.app", deployedAppName:"org.nativescript.TestsApp", mainActivityName:"com.tns.NativeScriptActivity", pathToCompiledTests: "bin/dist/apps/tests", @@ -140,9 +141,9 @@ module.exports = { cmd: "pkill '" + localCfg.emulatorProcessIdentifier + "'", exitCode: [0, 1] }, - startAndroidEmulator: { - cmd: "emulator -avd " + localCfg.emuAvdName + " -no-audio " + (args.showEmu ? "" : "-no-window") + "&", - stdout: true + killiOSEmulator: { + cmd: "pkill Simulator", + exitCode: [0, 1] }, createApp: { cmd: localCfg.tnsPath + " create " + localCfg.testsAppName, @@ -166,8 +167,16 @@ module.exports = { cmd: "adb shell am start -n " + localCfg.deployedAppName + "/" + localCfg.mainActivityName }, uninstallExistingiOSApp: { - cmd: "bash -c 'exit 1'" - } + cmd: "xcrun simctl uninstall " + localCfg.emuAvdName + " org.nativescript." + localCfg.testsAppName, + cwd: localCfg.applicationDir + }, + installNewiOSApp: { + cmd: "xcrun simctl install " + localCfg.emuAvdName + " " + localCfg.pathToApp, + cwd: localCfg.applicationDir + }, + startiOSApp: { + cmd: "xcrun simctl launch " + localCfg.emuAvdName + " org.nativescript." + localCfg.testsAppName + }, }, untar: { modules: { @@ -184,6 +193,15 @@ module.exports = { } } }, + startAndroidEmulator: { + command: "emulator -avd " + localCfg.emuAvdName + " -no-audio " + (args.showEmu ? "" : "-no-window") + "&" + }, + startiOSEmulator: { + command: "xcrun instruments -w " + localCfg.emuAvdName, + options: { + failOnError: false + }, + }, buildApp: { command: "tns build " + localCfg.platform.toLowerCase(), options: { @@ -213,32 +231,34 @@ module.exports = { grunt.registerTask("doPostPlatformAddiOS", [ ]); + +//xcrun instruments -s grunt.registerTask("testsapp", [ - "clean:workingDir", - "mkdir:workingDir", +// "clean:workingDir", +// "mkdir:workingDir", // getPlatformSpecificTask("exec:kill{platform}Emulator"), -// getPlatformSpecificTask("exec:start{platform}Emulator"), - - "exec:createApp", - "clean:originalAppDir", - "copy:testsAppToRunDir", - "clean:modules", - "untar:modules", - "copy:modulesToDir", - "clean:tempExtractedModules", - - "exec:addPlatform", - getPlatformSpecificTask("copy:add{platform}Permissions"), - "shell:buildApp", - getPlatformSpecificTask("doPostPlatformAdd{platform}"), +// getPlatformSpecificTask("shell:start{platform}Emulator"), +// +// "exec:createApp", +// "clean:originalAppDir", +// "copy:testsAppToRunDir", +// "clean:modules", +// "untar:modules", +// "copy:modulesToDir", +// "clean:tempExtractedModules", +// +// "exec:addPlatform", +// getPlatformSpecificTask("copy:add{platform}Permissions"), +// "shell:buildApp", +// getPlatformSpecificTask("doPostPlatformAdd{platform}"), getPlatformSpecificTask("exec:uninstallExisting{platform}App"), getPlatformSpecificTask("exec:installNew{platform}App"), getPlatformSpecificTask("exec:start{platform}App"), - getPlatformSpecificTask("shell:collect{platform}Log"), - - getPlatformSpecificTask("exec:kill{platform}Emulator"), - "clean:workingDir" +// getPlatformSpecificTask("shell:collect{platform}Log"), +// +// getPlatformSpecificTask("exec:kill{platform}Emulator"), +// "clean:workingDir" ]); } } diff --git a/run.sh b/run.sh index f7c75bddb..88e8b99e5 100755 --- a/run.sh +++ b/run.sh @@ -2,6 +2,6 @@ #grunt testsapp --verbose --platform=Android --emuPId=".*emulator64-x86" --avd="Api19" --logFilePath="./TestRunResult.txt" --runtimePath="/Users/erjan/tns-android.tgz" --showEmu=true --modulesPath=/Volumes/distributions/DailyBuilds/NativeScript/tns-modules/Stable/tns-core-modules.tgz -grunt testsapp --verbose --platform=iOS --logFilePath="./TestRunResult.txt" --runtimePath="/Users/erjan/tns-ios.tgz" --showEmu=true --modulesPath=/Volumes/distributions/DailyBuilds/NativeScript/tns-modules/Stable/tns-core-modules.tgz +grunt testsapp --verbose --platform=iOS --logFilePath="./TestRunResult.txt" --runtimePath="/Users/erjan/tns-ios.tgz" --showEmu=true --modulesPath=/Volumes/distributions/DailyBuilds/NativeScript/tns-modules/Stable/tns-core-modules.tgz --avd="2ADF1A49-F09E-4D5F-A099-AD557ABFA91C" From d5eb8046de574032ca85476eca87fbcd3d237019 Mon Sep 17 00:00:00 2001 From: Erjan Gavalji Date: Thu, 29 Oct 2015 10:26:16 +0200 Subject: [PATCH 41/42] Collecting the iOS log --- build/run-testsapp.grunt.js | 93 ++++++++++++++++++++++++++----------- expect.exp | 7 ++- 2 files changed, 70 insertions(+), 30 deletions(-) diff --git a/build/run-testsapp.grunt.js b/build/run-testsapp.grunt.js index 73c3f5111..86d85a311 100644 --- a/build/run-testsapp.grunt.js +++ b/build/run-testsapp.grunt.js @@ -37,7 +37,7 @@ module.exports = { emulatorProcessIdentifier: args.emulatorProcessIdentifier, modulesPath: args.modulesPath || "./bin/dist/tns-core-modules-" + modulesPackageConfig.version + ".tgz", emuAvdName: args.emuAvdName, - outfile: args.outFile || "./TestRunResult.txt", + outFile: args.outFile || "./TestRunResult.txt", frameworkArgument: args.runtimePath ? " --frameworkPath=" + args.runtimePath : "", showEmu: args.showEmu || false, @@ -50,7 +50,7 @@ module.exports = { deployedAppName:"org.nativescript.TestsApp", mainActivityName:"com.tns.NativeScriptActivity", pathToCompiledTests: "bin/dist/apps/tests", - + simulatorSysLog: pathModule.join(process.env.HOME, "Library/Logs/CoreSimulator", args.emuAvdName, "/system.log"), platform: args.platform } @@ -70,6 +70,12 @@ module.exports = { }, tempExtractedModules: { src: pathModule.join(localCfg.applicationDir, "node_modules", "package") + }, + simulatorLog: { + src: localCfg.simulatorSysLog, + options: { + force: true + } } }, mkdir: { @@ -134,6 +140,10 @@ module.exports = { return newContent; } } + }, + simulatorLog: { + src: localCfg.simulatorSysLog, + dest: localCfg.outFile } }, exec: { @@ -163,6 +173,9 @@ module.exports = { cmd: "adb install " + localCfg.pathToApk, cwd: localCfg.applicationDir }, + startAndroidEmulator: { + cmd: "emulator -avd " + localCfg.emuAvdName + " -no-audio " + (args.showEmu ? "" : "-no-window") + "&" + }, startAndroidApp: { cmd: "adb shell am start -n " + localCfg.deployedAppName + "/" + localCfg.mainActivityName }, @@ -186,17 +199,22 @@ module.exports = { }, shell: { collectAndroidLog: { - command: "./expect.exp " + localCfg.outfile, + command: "./expect.exp " + "'adb logcat' " + localCfg.outFile, options: { execOptions: { maxBuffer: Infinity } } }, - startAndroidEmulator: { - command: "emulator -avd " + localCfg.emuAvdName + " -no-audio " + (args.showEmu ? "" : "-no-window") + "&" + waitiOSLogCompletion: { + command: "./expect.exp " + "'tail -f " + localCfg.simulatorSysLog + "' " + localCfg.outFile, + options: { + execOptions: { + maxBuffer: Infinity + } + } }, - startiOSEmulator: { + startiOSSimulator: { command: "xcrun instruments -w " + localCfg.emuAvdName, options: { failOnError: false @@ -225,38 +243,57 @@ module.exports = { return templatedTaskName.replace(/\{platform\}/, localCfg.platform); } + grunt.registerTask("startEmulatorAndroid", [ + getPlatformSpecificTask("exec:startAndroidEmulator"), + ]); + + grunt.registerTask("startEmulatoriOS", [ + getPlatformSpecificTask("shell:startiOSSimulator"), + ]); + + grunt.registerTask("collectLogAndroid", [ + "shell:collectAndroidLog" + ]); + + grunt.registerTask("collectLogiOS", [ + "shell:waitiOSLogCompletion", + "copy:simulatorLog" + ]); + grunt.registerTask("doPostPlatformAddAndroid", [ - "exec:restartAdb" - ]); + "exec:restartAdb" + ]); + grunt.registerTask("doPostPlatformAddiOS", [ - ]); + "clean:simulatorLog" + ]); //xcrun instruments -s grunt.registerTask("testsapp", [ -// "clean:workingDir", -// "mkdir:workingDir", -// getPlatformSpecificTask("exec:kill{platform}Emulator"), -// getPlatformSpecificTask("shell:start{platform}Emulator"), -// -// "exec:createApp", -// "clean:originalAppDir", -// "copy:testsAppToRunDir", -// "clean:modules", -// "untar:modules", -// "copy:modulesToDir", -// "clean:tempExtractedModules", -// -// "exec:addPlatform", -// getPlatformSpecificTask("copy:add{platform}Permissions"), -// "shell:buildApp", -// getPlatformSpecificTask("doPostPlatformAdd{platform}"), + "clean:workingDir", + "mkdir:workingDir", + getPlatformSpecificTask("exec:kill{platform}Emulator"), + getPlatformSpecificTask("startEmulator{platform}"), + + "exec:createApp", + "clean:originalAppDir", + "copy:testsAppToRunDir", + "clean:modules", + "untar:modules", + "copy:modulesToDir", + "clean:tempExtractedModules", + + "exec:addPlatform", + getPlatformSpecificTask("copy:add{platform}Permissions"), + "shell:buildApp", + getPlatformSpecificTask("doPostPlatformAdd{platform}"), getPlatformSpecificTask("exec:uninstallExisting{platform}App"), getPlatformSpecificTask("exec:installNew{platform}App"), getPlatformSpecificTask("exec:start{platform}App"), -// getPlatformSpecificTask("shell:collect{platform}Log"), -// + getPlatformSpecificTask("collectLog{platform}"), + // getPlatformSpecificTask("exec:kill{platform}Emulator"), // "clean:workingDir" ]); diff --git a/expect.exp b/expect.exp index 5a084c782..4cbba512e 100755 --- a/expect.exp +++ b/expect.exp @@ -8,10 +8,13 @@ #expect "TypeScript compilation complete" #send \003 -set outfile [lindex $argv 0]; + +set cmd [lindex $argv 0]; +set outfile [lindex $argv 1]; + set timeout 600 #spawn (adb logcat | tee ./__TESTRESULT__.txt) log_file -noappend $outfile -spawn adb logcat +eval spawn $cmd expect "=== ALL TESTS COMPLETE ===" send \003 From 55dfe7e39a75a126a3577f70d79f023fa29cbcb1 Mon Sep 17 00:00:00 2001 From: Erjan Gavalji Date: Thu, 29 Oct 2015 10:35:14 +0200 Subject: [PATCH 42/42] Remove redundant files. Update the doc with iOS instructions --- linux-runtestapp.sh | 70 -------------------------------------------- run.sh | 7 ----- running-tests.md | 4 +-- win-runtestsapp.sh | 71 --------------------------------------------- 4 files changed, 2 insertions(+), 150 deletions(-) delete mode 100755 linux-runtestapp.sh delete mode 100755 run.sh delete mode 100644 win-runtestsapp.sh diff --git a/linux-runtestapp.sh b/linux-runtestapp.sh deleted file mode 100755 index 52cfc274f..000000000 --- a/linux-runtestapp.sh +++ /dev/null @@ -1,70 +0,0 @@ -workingdir=__TESTSAPP__ -startdir=$(pwd) -rm -rd $workingdir -mkdir $workingdir -cd $workingdir - -#android create avd -t "android-21" -n Api21 -b "default/x86" - -#if [ 1 == 2 ] ; then - echo "------------------------------------------------" - echo "Killing the emulator..." - time pkill ".*emulator64-x86" && true - - echo "------------------------------------------------" - echo "Starting the emulator..." - #time emulator -avd Api19 -no-skin -no-audio & # -gpu on - time emulator -avd Api21 -qemu -m 2048 -enable-kvm & - #emulator -avd Api19 -no-skin -no-audio -no-window & - - echo "------------------------------------------------" - echo "Creating the app..." - time tns create TestsApp - cd TestsApp - - echo "------------------------------------------------" - echo "Removing the original template files..." - time rm app/*.* - - echo "------------------------------------------------" - echo "Copying the test app files..." - time cp -r ../../bin/dist/apps/tests/* ./app/ - - echo "------------------------------------------------" - echo "Adding the android platform..." - time tns platform add android #--frameworkPath=/Users/erjan/tns-android.tgz - - # #DO THE REPLACEMENTS IN THE Info.plist and AndroidManifest.xml -# cp /Users/erjan/work/spikes/__DEL__/AndroidManifest.xml platforms/android/src/main/ - - echo "------------------------------------------------" - echo "Building the application..." - time tns build android - - echo "------------------------------------------------" - echo "Killing the adb server..." - time adb kill-server - - echo "------------------------------------------------" - echo "Starting the adb server..." - time adb start-server - -#fi - -echo "------------------------------------------------" -echo "Uninstalling the app..." -time adb uninstall org.nativescript.TestsApp - -echo "------------------------------------------------" -echo "Installing the app..." -time adb install ./platforms/android/build/outputs/apk/TestsApp-debug.apk - -echo "------------------------------------------------" -echo "Starting the app..." -time adb shell am start -n org.nativescript.TestsApp/com.tns.NativeScriptActivity - -cd $startdir - -echo "------------------------------------------------" -echo "Waiting for the tests to finish executing..." -time ./expect.exp diff --git a/run.sh b/run.sh deleted file mode 100755 index 88e8b99e5..000000000 --- a/run.sh +++ /dev/null @@ -1,7 +0,0 @@ -#! /bin/bash - -#grunt testsapp --verbose --platform=Android --emuPId=".*emulator64-x86" --avd="Api19" --logFilePath="./TestRunResult.txt" --runtimePath="/Users/erjan/tns-android.tgz" --showEmu=true --modulesPath=/Volumes/distributions/DailyBuilds/NativeScript/tns-modules/Stable/tns-core-modules.tgz - -grunt testsapp --verbose --platform=iOS --logFilePath="./TestRunResult.txt" --runtimePath="/Users/erjan/tns-ios.tgz" --showEmu=true --modulesPath=/Volumes/distributions/DailyBuilds/NativeScript/tns-modules/Stable/tns-core-modules.tgz --avd="2ADF1A49-F09E-4D5F-A099-AD557ABFA91C" - - diff --git a/running-tests.md b/running-tests.md index 4cce032b6..1d3d4b8e4 100644 --- a/running-tests.md +++ b/running-tests.md @@ -42,8 +42,8 @@ to be tested. Defaults to the npm package, located in the current found, the globally installed `tns` gets called. - `emuPId`: The ID of the emulator process. This one is used to refresh the emulator process, as the emulator sometimes hangs. -- `avd`: The name of the Android Virtual Device to be started to run the -tests. +- `avd`: The name of the Android Virtual Device or the iOS simulator GUID +to be started to run the tests. - `logFilePath`: [Optional] The path to the file, which the test app run log will get saved to. Defaults to "./TestRunResult.txt". - `runtimePath`: [Optional] The path to a custom iOS or Android Runtime diff --git a/win-runtestsapp.sh b/win-runtestsapp.sh deleted file mode 100644 index 1e7a24ea8..000000000 --- a/win-runtestsapp.sh +++ /dev/null @@ -1,71 +0,0 @@ -workingdir=__TESTSAPP__ -startdir=$(pwd) -rm -rd $workingdir -mkdir $workingdir -cd $workingdir - -#android create avd -t "android-21" -n Api21 -b "default/x86" - -#if [ 1 == 2 ] ; then - echo "------------------------------------------------" - echo "Killing the emulator..." -# time pkill ".*emulator64-x86" && true - - echo "------------------------------------------------" - echo "Starting the emulator..." - #time emulator -avd Api19 -no-skin -no-audio & # -gpu on - time emulator -avd Api19 -no-audio & # -gpu on - #emulator -avd Api19 -no-skin -no-audio -no-window & - - echo "------------------------------------------------" - echo "Creating the app..." - time tns create TestsApp - cd TestsApp - - echo "------------------------------------------------" - echo "Removing the original template files..." - time rm app/*.* - - echo "------------------------------------------------" - echo "Copying the test app files..." - time cp -r ../../bin/dist/apps/tests/* ./app/ - - echo "------------------------------------------------" - echo "Adding the android platform..." - time tns platform add android #--frameworkPath=/Users/erjan/tns-android.tgz - - # #DO THE REPLACEMENTS IN THE Info.plist and AndroidManifest.xml - cp /Users/erjan/work/spikes/__DEL__/AndroidManifest.xml platforms/android/src/main/ - - echo "------------------------------------------------" - echo "Building the application..." - time tns build android - - echo "------------------------------------------------" - echo "Killing the adb server..." - time adb kill-server - - echo "------------------------------------------------" - echo "Starting the adb server..." - time adb start-server - -#fi - -echo "------------------------------------------------" -echo "Uninstalling the app..." -time adb uninstall org.nativescript.TestsApp - -echo "------------------------------------------------" -echo "Installing the app..." -time adb install ./platforms/android/build/outputs/apk/TestsApp-debug.apk - -echo "------------------------------------------------" -echo "Starting the app..." -time adb shell am start -n org.nativescript.TestsApp/com.tns.NativeScriptActivity - -cd $startdir - -echo "------------------------------------------------" -echo "Waiting for the tests to finish executing..." -adb logcat -