You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by er...@apache.org on 2021/08/31 16:16:54 UTC

[cordova-electron] branch master updated: test: cleanup and remove unneeded code (#204)

This is an automated email from the ASF dual-hosted git repository.

erisu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cordova-electron.git


The following commit(s) were added to refs/heads/master by this push:
     new 4d6874e  test: cleanup and remove unneeded code (#204)
4d6874e is described below

commit 4d6874e530b6cfaa7968553daaff75b383a5edd2
Author: エリス <er...@users.noreply.github.com>
AuthorDate: Wed Sep 1 01:13:56 2021 +0900

    test: cleanup and remove unneeded code (#204)
---
 .../plugins/cordova-plugin-device/package.json     | 46 --------------------
 .../plugins/cordova-plugin-sample/package.json     | 27 ++++++++++++
 .../plugin.xml                                     | 14 +++----
 .../src/electron/index.js                          | 13 +++---
 .../src/electron/package.json                      |  8 ++--
 .../www/sample.js}                                 | 49 ++++++----------------
 tests/spec/fixtures/test-browser-plugin/plugin.xml |  1 -
 tests/spec/fixtures/test-config-1.xml              |  1 -
 tests/spec/fixtures/test-config-2.xml              |  8 ----
 .../test-config-no-author-custom-email.xml         |  8 ----
 .../fixtures/test-non-electron-plugin/plugin.xml   |  1 -
 tests/spec/fixtures/testapp/config.xml             |  8 ----
 .../fixtures/testplugin-empty-jsmodule/plugin.xml  |  1 -
 tests/spec/fixtures/testplugin/plugin.xml          |  1 -
 tests/spec/unit/lib/handler.spec.js                | 26 ++++++------
 15 files changed, 69 insertions(+), 143 deletions(-)

diff --git a/tests/spec/fixtures/test-app-with-electron-plugin/plugins/cordova-plugin-device/package.json b/tests/spec/fixtures/test-app-with-electron-plugin/plugins/cordova-plugin-device/package.json
deleted file mode 100644
index 0b59744..0000000
--- a/tests/spec/fixtures/test-app-with-electron-plugin/plugins/cordova-plugin-device/package.json
+++ /dev/null
@@ -1,46 +0,0 @@
-{
-  "name": "cordova-plugin-device",
-  "version": "2.0.4-dev",
-  "description": "Cordova Device Plugin",
-  "types": "./types/index.d.ts",
-  "cordova": {
-    "id": "cordova-plugin-device",
-    "platforms": [
-      "android",
-      "ios",
-      "windows",
-      "browser",
-      "osx"
-    ]
-  },
-  "repository": "github:apache/cordova-plugin-device",
-  "bugs": "https://github.com/apache/cordova-plugin-device/issues",
-  "keywords": [
-    "cordova",
-    "device",
-    "ecosystem:cordova",
-    "cordova-android",
-    "cordova-electron",
-    "cordova-ios",
-    "cordova-windows",
-    "cordova-browser",
-    "cordova-osx"
-  ],
-  "scripts": {
-    "test": "npm run lint",
-    "lint": "eslint ."
-  },
-  "author": "Apache Software Foundation",
-  "license": "Apache-2.0",
-  "engines": {
-    "cordovaDependencies": {
-      "3.0.0": {
-        "cordova": ">100",
-        "cordova-electron": ">=3.0.0"
-      }
-    }
-  },
-  "devDependencies": {
-    "@cordova/eslint-config": "^3.0.0"
-  }
-}
diff --git a/tests/spec/fixtures/test-app-with-electron-plugin/plugins/cordova-plugin-sample/package.json b/tests/spec/fixtures/test-app-with-electron-plugin/plugins/cordova-plugin-sample/package.json
new file mode 100644
index 0000000..aed86ac
--- /dev/null
+++ b/tests/spec/fixtures/test-app-with-electron-plugin/plugins/cordova-plugin-sample/package.json
@@ -0,0 +1,27 @@
+{
+  "name": "cordova-plugin-sample",
+  "version": "1.0.0",
+  "description": "Cordova Sample Plugin",
+  "cordova": {
+    "id": "cordova-plugin-sample",
+    "platforms": [
+      "electron"
+    ]
+  },
+  "keywords": [
+    "cordova",
+    "sample",
+    "ecosystem:cordova",
+    "cordova-electron"
+  ],
+  "author": "Apache Software Foundation",
+  "license": "Apache-2.0",
+  "engines": {
+    "cordovaDependencies": {
+      "1.0.0": {
+        "cordova": ">100",
+        "cordova-electron": ">=3.0.0"
+      }
+    }
+  }
+}
diff --git a/tests/spec/fixtures/test-app-with-electron-plugin/plugins/cordova-plugin-device/plugin.xml b/tests/spec/fixtures/test-app-with-electron-plugin/plugins/cordova-plugin-sample/plugin.xml
similarity index 79%
rename from tests/spec/fixtures/test-app-with-electron-plugin/plugins/cordova-plugin-device/plugin.xml
rename to tests/spec/fixtures/test-app-with-electron-plugin/plugins/cordova-plugin-sample/plugin.xml
index 2dcfb6f..835911f 100644
--- a/tests/spec/fixtures/test-app-with-electron-plugin/plugins/cordova-plugin-device/plugin.xml
+++ b/tests/spec/fixtures/test-app-with-electron-plugin/plugins/cordova-plugin-sample/plugin.xml
@@ -19,19 +19,19 @@
 -->
 
 <plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
-    id="cordova-plugin-device"
-    version="2.0.4-dev">
-    <name>Device</name>
-    <description>Cordova Mock Device Plugin for Electron Testing</description>
+    id="cordova-plugin-sample"
+    version="1.0.0">
+    <name>Sanple</name>
+    <description>Cordova Sample Plugin</description>
     <license>Apache 2.0</license>
-    <keywords>cordova,device</keywords>
+    <keywords>cordova,sample</keywords>
 
     <engines>
         <engine name="cordova-electron" version=">=3.0.0" />
     </engines>
 
-    <js-module src="www/device.js" name="device">
-        <clobbers target="device" />
+    <js-module src="www/sample.js" name="sample">
+        <clobbers target="sample" />
     </js-module>
 
     <platform name="electron">
diff --git a/tests/spec/fixtures/test-app-with-electron-plugin/plugins/cordova-plugin-device/src/electron/index.js b/tests/spec/fixtures/test-app-with-electron-plugin/plugins/cordova-plugin-sample/src/electron/index.js
similarity index 77%
rename from tests/spec/fixtures/test-app-with-electron-plugin/plugins/cordova-plugin-device/src/electron/index.js
rename to tests/spec/fixtures/test-app-with-electron-plugin/plugins/cordova-plugin-sample/src/electron/index.js
index ee3941c..774baa5 100644
--- a/tests/spec/fixtures/test-app-with-electron-plugin/plugins/cordova-plugin-device/src/electron/index.js
+++ b/tests/spec/fixtures/test-app-with-electron-plugin/plugins/cordova-plugin-sample/src/electron/index.js
@@ -18,21 +18,18 @@
 */
 
 const { system, osInfo } = require('systeminformation');
+const electron = require
 
 module.exports = {
-    getDeviceInfo: async () => {
+    getSampleInfo: async () => {
         try {
-            const { manufacturer, model, uuid } = await system();
-            const { platform, distro, codename, build } = await osInfo();
+            const { model } = await system();
+            const { platform } = await osInfo();
 
             return {
-                manufacturer,
                 model,
                 platform: platform === 'darwin' ? codename : distro,
-                version: build,
-                uuid,
-                // cordova: ''
-                isVirtual: false
+                electronVersion: process.versions.electron
             };
         } catch (e) {
             console.log(e);
diff --git a/tests/spec/fixtures/test-app-with-electron-plugin/plugins/cordova-plugin-device/src/electron/package.json b/tests/spec/fixtures/test-app-with-electron-plugin/plugins/cordova-plugin-sample/src/electron/package.json
similarity index 62%
rename from tests/spec/fixtures/test-app-with-electron-plugin/plugins/cordova-plugin-device/src/electron/package.json
rename to tests/spec/fixtures/test-app-with-electron-plugin/plugins/cordova-plugin-sample/src/electron/package.json
index d3b235f..1fdb535 100644
--- a/tests/spec/fixtures/test-app-with-electron-plugin/plugins/cordova-plugin-device/src/electron/package.json
+++ b/tests/spec/fixtures/test-app-with-electron-plugin/plugins/cordova-plugin-sample/src/electron/package.json
@@ -1,12 +1,12 @@
 {
-  "name": "cordova-plugin-device-electron",
+  "name": "cordova-plugin-sample-electron",
   "version": "1.0.0",
-  "description": "Electron Native Supprot for Cordova Device Plugin",
+  "description": "Cordova Sample Electron Plugin (Native Support)",
   "main": "index.js",
   "keywords": [
     "cordova",
     "electron",
-    "device",
+    "sample",
     "native"
   ],
   "author": "Apache Software Foundation",
@@ -15,6 +15,6 @@
     "systeminformation": "^4.27.9"
   },
   "cordova": {
-    "serviceName": "Device"
+    "serviceName": "Sample"
   }
 }
diff --git a/tests/spec/fixtures/test-app-with-electron-plugin/plugins/cordova-plugin-device/www/device.js b/tests/spec/fixtures/test-app-with-electron-plugin/plugins/cordova-plugin-sample/www/sample.js
similarity index 50%
rename from tests/spec/fixtures/test-app-with-electron-plugin/plugins/cordova-plugin-device/www/device.js
rename to tests/spec/fixtures/test-app-with-electron-plugin/plugins/cordova-plugin-sample/www/sample.js
index 8bb2aa6..1dee15e 100644
--- a/tests/spec/fixtures/test-app-with-electron-plugin/plugins/cordova-plugin-device/www/device.js
+++ b/tests/spec/fixtures/test-app-with-electron-plugin/plugins/cordova-plugin-sample/www/sample.js
@@ -29,57 +29,34 @@ channel.createSticky('onCordovaInfoReady');
 channel.waitForInitialization('onCordovaInfoReady');
 
 /**
- * This represents the mobile device, and provides properties for inspecting the model, version, UUID of the
- * phone, etc.
  * @constructor
  */
-function Device () {
-    this.available = false;
-    this.platform = null;
-    this.version = null;
-    this.uuid = null;
-    this.cordova = null;
+function Sample () {
     this.model = null;
-    this.manufacturer = null;
-    this.isVirtual = null;
-    this.serial = null;
-
-    var me = this;
+    this.platform = null;
 
-    channel.onCordovaReady.subscribe(function () {
+    channel.onCordovaReady.subscribe(() => {
         me.getInfo(
-            function (info) {
-                // ignoring info.cordova returning from native, we should use value from cordova.version defined in cordova.js
-                // TODO: CB-5105 native implementations should not return info.cordova
-                var buildLabel = cordova.version;
-                me.available = true;
-                me.platform = info.platform;
-                me.version = info.version;
-                me.uuid = info.uuid;
-                me.cordova = buildLabel;
-                me.model = info.model;
-                me.isVirtual = info.isVirtual;
-                me.manufacturer = info.manufacturer || 'unknown';
-                me.serial = info.serial || 'unknown';
+            info => {
+                this.model = info.model;
+                this.platform = info.platform;
+
                 channel.onCordovaInfoReady.fire();
             },
-            function (e) {
-                me.available = false;
-                console.error('[ERROR] Error initializing cordova-plugin-device: ' + e);
-            }
+            error => { console.error('[ERROR] Error initializing cordova-plugin-sample: ', error); }
         );
     });
 }
 
 /**
- * Get device info
+ * Get sample info
  *
  * @param {Function} successCallback The function to call when the heading data is available
  * @param {Function} errorCallback The function to call when there is an error getting the heading data. (OPTIONAL)
  */
-Device.prototype.getInfo = function (successCallback, errorCallback) {
-    argscheck.checkArgs('fF', 'Device.getInfo', arguments);
-    exec(successCallback, errorCallback, 'Device', 'getDeviceInfo', []);
+Sample.prototype.getInfo = function (successCallback, errorCallback) {
+    argscheck.checkArgs('fF', 'Sample.getInfo', arguments);
+    exec(successCallback, errorCallback, 'Sample', 'getSampleInfo', []);
 };
 
-module.exports = new Device();
+module.exports = new Sample();
diff --git a/tests/spec/fixtures/test-browser-plugin/plugin.xml b/tests/spec/fixtures/test-browser-plugin/plugin.xml
index 2760357..a7dd7e3 100644
--- a/tests/spec/fixtures/test-browser-plugin/plugin.xml
+++ b/tests/spec/fixtures/test-browser-plugin/plugin.xml
@@ -19,7 +19,6 @@
 -->
 
 <plugin xmlns="http://cordova.apache.org/ns/plugins/1.0"
-    xmlns:android="http://schemas.android.com/apk/res/android"
     id="org.apache.testbrowserplugin"
     version="1.0.0">
 
diff --git a/tests/spec/fixtures/test-config-1.xml b/tests/spec/fixtures/test-config-1.xml
index 56c2b52..80282d9 100644
--- a/tests/spec/fixtures/test-config-1.xml
+++ b/tests/spec/fixtures/test-config-1.xml
@@ -55,5 +55,4 @@
         <icon src="res/electron/cordova@16.png" />
         <icon src="res/electron/cordova_512.png" target="installer" />
     </platform>
-    <engine name="electron" spec="github:Apache/cordova-electron" />
 </widget>
diff --git a/tests/spec/fixtures/test-config-2.xml b/tests/spec/fixtures/test-config-2.xml
index 7ec17b6..88046bd 100644
--- a/tests/spec/fixtures/test-config-2.xml
+++ b/tests/spec/fixtures/test-config-2.xml
@@ -37,13 +37,6 @@
     <allow-intent href="sms:*" />
     <allow-intent href="mailto:*" />
     <allow-intent href="geo:*" />
-    <platform name="android">
-        <allow-intent href="market:*" />
-    </platform>
-    <platform name="ios">
-        <allow-intent href="itms:*" />
-        <allow-intent href="itms-apps:*" />
-    </platform>
     <platform name="electron">
         <icon src="res/electron/cordova.png" />
         <icon src="res/electron/cordova@1.5.png" />
@@ -54,5 +47,4 @@
         <icon src="res/electron/cordova@16.png" />
         <icon src="res/electron/cordova_512.png" target="installer" />
     </platform>
-    <engine name="electron" spec="github:Apache/cordova-electron" />
 </widget>
diff --git a/tests/spec/fixtures/test-config-no-author-custom-email.xml b/tests/spec/fixtures/test-config-no-author-custom-email.xml
index b1d3f0a..0e5745c 100644
--- a/tests/spec/fixtures/test-config-no-author-custom-email.xml
+++ b/tests/spec/fixtures/test-config-no-author-custom-email.xml
@@ -35,13 +35,6 @@
     <allow-intent href="sms:*" />
     <allow-intent href="mailto:*" />
     <allow-intent href="geo:*" />
-    <platform name="android">
-        <allow-intent href="market:*" />
-    </platform>
-    <platform name="ios">
-        <allow-intent href="itms:*" />
-        <allow-intent href="itms-apps:*" />
-    </platform>
     <icon src="res/electron/cordova.png"  width="16" height="16"/>
     <platform name="electron">
         <icon src="res/electron/cordova.png"/>
@@ -53,5 +46,4 @@
         <icon src="res/electron/cordova@16.png" />
         <icon src="res/electron/cordova_512.png" target="installer" />
     </platform>
-    <engine name="electron" spec="github:Apache/cordova-electron" />
 </widget>
diff --git a/tests/spec/fixtures/test-non-electron-plugin/plugin.xml b/tests/spec/fixtures/test-non-electron-plugin/plugin.xml
index 4f123cc..1ceb243 100644
--- a/tests/spec/fixtures/test-non-electron-plugin/plugin.xml
+++ b/tests/spec/fixtures/test-non-electron-plugin/plugin.xml
@@ -19,7 +19,6 @@
 -->
 
 <plugin xmlns="http://cordova.apache.org/ns/plugins/1.0"
-    xmlns:android="http://schemas.android.com/apk/res/android"
     id="org.apache.testnonelectronplugin"
     version="1.0.0">
 
diff --git a/tests/spec/fixtures/testapp/config.xml b/tests/spec/fixtures/testapp/config.xml
index 5068845..233f093 100644
--- a/tests/spec/fixtures/testapp/config.xml
+++ b/tests/spec/fixtures/testapp/config.xml
@@ -37,13 +37,6 @@
     <allow-intent href="sms:*" />
     <allow-intent href="mailto:*" />
     <allow-intent href="geo:*" />
-    <platform name="android">
-        <allow-intent href="market:*" />
-    </platform>
-    <platform name="ios">
-        <allow-intent href="itms:*" />
-        <allow-intent href="itms-apps:*" />
-    </platform>
     <icon src="res/electron/cordova.png"  width="16" height="16"/>
     <platform name="electron">
         <icon src="res/electron/cordova.png"/>
@@ -55,5 +48,4 @@
         <icon src="res/electron/cordova@16.png" />
         <icon src="res/electron/cordova_512.png" target="installer" />
     </platform>
-    <engine name="electron" spec="github:apache/cordova-electron" />
 </widget>
diff --git a/tests/spec/fixtures/testplugin-empty-jsmodule/plugin.xml b/tests/spec/fixtures/testplugin-empty-jsmodule/plugin.xml
index 4d5f697..575505f 100644
--- a/tests/spec/fixtures/testplugin-empty-jsmodule/plugin.xml
+++ b/tests/spec/fixtures/testplugin-empty-jsmodule/plugin.xml
@@ -19,7 +19,6 @@
 -->
 
 <plugin xmlns="http://cordova.apache.org/ns/plugins/1.0"
-    xmlns:android="http://schemas.android.com/apk/res/android"
     id="org.apache.testplugin2"
     version="1.0.0">
 
diff --git a/tests/spec/fixtures/testplugin/plugin.xml b/tests/spec/fixtures/testplugin/plugin.xml
index f6878aa..82eb88e 100644
--- a/tests/spec/fixtures/testplugin/plugin.xml
+++ b/tests/spec/fixtures/testplugin/plugin.xml
@@ -19,7 +19,6 @@
 -->
 
 <plugin xmlns="http://cordova.apache.org/ns/plugins/1.0"
-    xmlns:android="http://schemas.android.com/apk/res/android"
     id="org.apache.testplugin"
     version="1.0.0">
 
diff --git a/tests/spec/unit/lib/handler.spec.js b/tests/spec/unit/lib/handler.spec.js
index 3ab405e..28fa984 100644
--- a/tests/spec/unit/lib/handler.spec.js
+++ b/tests/spec/unit/lib/handler.spec.js
@@ -190,7 +190,7 @@ describe('Handler export', () => {
             implementation: undefined
         };
 
-        const frameworkInstallPluginId = 'cordova-plugin-device';
+        const frameworkInstallPluginId = 'cordova-plugin-sample';
         const frameworkInstallElectronPluginId = `${frameworkInstallPluginId}-electron`;
         const frameworkInstallPluginDir = path.join(testProjectDir, `plugins/${frameworkInstallPluginId}`);
         const frameworkInstallProjectDir = path.join(testProjectDir, 'platforms/electron');
@@ -256,9 +256,9 @@ describe('Handler export', () => {
                     frameworkInstallPluginId
                 );
 
-                // Validate that device plugin's service is registered.
+                // Validate that sample plugin's service is registered.
                 const validateAppPackage = JSON.parse(fs.readFileSync(frameworkInstallProjectAppPackageFile, 'utf8'));
-                const test = validateAppPackage && validateAppPackage.cordova && validateAppPackage.cordova.services && validateAppPackage.cordova.services.Device;
+                const test = validateAppPackage && validateAppPackage.cordova && validateAppPackage.cordova.services && validateAppPackage.cordova.services.Sample;
                 expect(test).toBe(frameworkInstallElectronPluginId);
             });
 
@@ -300,9 +300,9 @@ describe('Handler export', () => {
                     frameworkInstallPluginId
                 );
 
-                // Validate that device plugin's service is registered.
+                // Validate that sample plugin's service is registered.
                 const validateAppPackage = JSON.parse(fs.readFileSync(frameworkInstallProjectAppPackageFile, 'utf8'));
-                const test = validateAppPackage && validateAppPackage.cordova && validateAppPackage.cordova.services && validateAppPackage.cordova.services.Device;
+                const test = validateAppPackage && validateAppPackage.cordova && validateAppPackage.cordova.services && validateAppPackage.cordova.services.Sample;
                 expect(test).not.toBe(frameworkInstallElectronPluginId);
             });
 
@@ -322,10 +322,10 @@ describe('Handler export', () => {
                     path.join(frameworkInstallPluginDir, 'src/electron')
                 );
 
-                // fake some other device service already registered
+                // fake some other sample service already registered
                 appPackage.cordova = appPackage.cordova || {};
                 appPackage.cordova.services = appPackage.cordova.services || {
-                    Device: 'cordova-plugin-device-electron'
+                    Sample: 'cordova-plugin-sample-electron'
                 };
 
                 fs.writeFileSync(
@@ -343,7 +343,7 @@ describe('Handler export', () => {
 
                 expect(events.emit).toHaveBeenCalledWith(
                     'warn',
-                    '[Cordova Electron] The service name "Device" is already taken by "cordova-plugin-device-electron" and can not be redeclared.'
+                    '[Cordova Electron] The service name "Sample" is already taken by "cordova-plugin-sample-electron" and can not be redeclared.'
                 );
                 events.emit.calls.reset();
             });
@@ -364,10 +364,10 @@ describe('Handler export', () => {
                     path.join(frameworkInstallPluginDir, 'src/electron')
                 );
 
-                // fake some other device service already registered
+                // fake some other sample service already registered
                 appPackage.cordova = appPackage.cordova || {};
                 appPackage.cordova.services = appPackage.cordova.services || {
-                    Device: 'cordova-plugin-device-electron'
+                    Sample: 'cordova-plugin-sample-electron'
                 };
 
                 fs.writeFileSync(
@@ -384,7 +384,7 @@ describe('Handler export', () => {
 
                 expect(events.emit).toHaveBeenCalledWith(
                     'verbose',
-                    '[Cordova Electron] The service name "Device" was delinked.'
+                    '[Cordova Electron] The service name "Sample" was delinked.'
                 );
                 events.emit.calls.reset();
             });
@@ -403,10 +403,10 @@ describe('Handler export', () => {
                     path.join(frameworkInstallPluginDir, 'src/electron')
                 );
 
-                // fake some other device service already registered
+                // fake some other sample service already registered
                 appPackage.cordova = appPackage.cordova || {};
                 appPackage.cordova.services = appPackage.cordova.services || {
-                    Device: 'some-other-package'
+                    Sample: 'some-other-package'
                 };
 
                 fs.writeFileSync(

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org