summaryrefslogtreecommitdiff
path: root/platform/android/scripts
diff options
context:
space:
mode:
authorTobrun <tobrun.van.nuland@gmail.com>2016-08-17 08:53:33 +0200
committerGitHub <noreply@github.com>2016-08-17 08:53:33 +0200
commitfff0ebaa1754aabd9584c994624b7b948bec95af (patch)
tree745006b1a761856e6651738cd7d26e0e08c6cbbf /platform/android/scripts
parent0062cf2f949fe1b0080e2de45aaf0b3d5e028bf3 (diff)
downloadqtlocation-mapboxgl-fff0ebaa1754aabd9584c994624b7b948bec95af.tar.gz
5859 generate sanity tests (#5870)
* [android] #5859 - generate espresso tests [android] #5859 - cleanup xml files, use all the same resource id for map view [android] #5859 - update scripts [android] #5859 - update Activity to match mapboxMap naming [android] #5859 - make SurfaceViewMediaControlActivity compatible [android] #5859 - make MarkerViewScaleActivity test generation compatible [android] #5859 - make PolygonActivity test generation compatible [android] #5859 - integration within make file [android] #5859 - made CameraPostion generation safe [android] #5859 - generate sanity test [android] #5859 - add generated test cases [android] #5859 - add documentation * [android] #5859 - remove generated files, introduce gen package, added gitignore to package * [android] #5859 - regenerated test code * [android] #5859 - added AWS gradle plugin + bitrise configuration * [android] #5859 - fixes running locally without having the properties configured * [android] #6010 - remove python from android sdk * [android] #5859 - update docs about aws gradle plugin
Diffstat (limited to 'platform/android/scripts')
-rw-r--r--platform/android/scripts/generate-test-code.js60
1 files changed, 60 insertions, 0 deletions
diff --git a/platform/android/scripts/generate-test-code.js b/platform/android/scripts/generate-test-code.js
new file mode 100644
index 0000000000..1580949fda
--- /dev/null
+++ b/platform/android/scripts/generate-test-code.js
@@ -0,0 +1,60 @@
+'use strict';
+
+const fs = require('fs');
+const ejs = require('ejs');
+
+global.iff = function (condition, val) {
+ return condition() ? val : "";
+}
+
+global.camelize = function (str) {
+ return str.replace(/(?:^|-)(.)/g, function (_, x) {
+ return x.toUpperCase();
+ });
+}
+
+
+const excludeActivities = ["GeoJsonClusteringActivity","RuntimeStyleTestActivity", "AnimatedMarkerActivity", "ViewPagerActivity","MapFragmentActivity","SupportMapFragmentActivity","SnapshotActivity","NavigationDrawerActivity"];
+const appBasePath = 'platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity';
+const testBasePath = 'platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/activity/gen';
+const subPackages = fs.readdirSync(appBasePath);
+const ejsConversionTask = ejs.compile(fs.readFileSync('platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/activity/activity.junit.ejs', 'utf8'), {strict: true});
+
+if (!fs.existsSync(testBasePath)){
+ fs.mkdirSync(testBasePath);
+}
+
+for(const subPackage of subPackages) {
+ if(!(subPackage.slice(-5) == '.java')) {
+ const activities = fs.readdirSync(appBasePath+'/'+subPackage);
+
+ // create directories for package
+ if (!fs.existsSync(testBasePath+"/"+subPackage)){
+ fs.mkdirSync(testBasePath+"/"+subPackage);
+ }
+
+ for (const activity of activities) {
+ // strip .java from input file
+ const activityName = activity.slice(0, -5);
+
+ // create path for test file
+ const filePath = testBasePath+"/"+subPackage+"/"+activityName+'Test.java';
+
+ // try removing previous generated files
+ try {
+ fs.accessSync(filePath, fs.F_OK);
+ fs.unlinkSync(filePath);
+ console.log("Removed file: "+filePath);
+ } catch (e) {
+ console.log("No file found: "+filePath);
+ }
+
+ // only generate test file if not part of exclude list
+ if (!(excludeActivities.indexOf(activityName) > -1)) {
+ console.log("Created file: "+filePath);
+ fs.writeFileSync(filePath, ejsConversionTask([activityName, subPackage]));
+ }
+ }
+ }
+}
+