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-ios.git


The following commit(s) were added to refs/heads/master by this push:
     new c000a1b5 feat: add listTarget api & revert original bin file location 
(#1320)
c000a1b5 is described below

commit c000a1b5d9ec587f64d78219167abde4bb21a1c2
Author: エリス <[email protected]>
AuthorDate: Mon May 8 14:47:08 2023 +0900

    feat: add listTarget api & revert original bin file location (#1320)
    
    * feat: add listTarget api & revert original bin file location
    * test: write Platform API target list specs
---
 lib/Api.js                                          |  5 +++++
 lib/run.js                                          | 15 +++++++++++++++
 package.json                                        |  2 +-
 {lib => templates/cordova/lib}/list-devices         |  2 +-
 {lib => templates/cordova/lib}/list-emulator-images |  2 +-
 tests/spec/unit/Api.spec.js                         | 12 ++++++++++++
 tests/spec/unit/lib/run.spec.js                     | 21 +++++++++++++++++++++
 7 files changed, 56 insertions(+), 3 deletions(-)

diff --git a/lib/Api.js b/lib/Api.js
index e282e8ec..d37adf80 100644
--- a/lib/Api.js
+++ b/lib/Api.js
@@ -665,6 +665,11 @@ class Api {
             .then(() => require('./run').run.call(this, runOptions));
     }
 
+    listTargets (options) {
+        return check_reqs.run()
+            .then(() => require('./run').runListDevices.call(this, options));
+    }
+
     /**
      * Cleans out the build artifacts from platform's directory.
      *
diff --git a/lib/run.js b/lib/run.js
index 678bd130..11ddb8e4 100644
--- a/lib/run.js
+++ b/lib/run.js
@@ -228,3 +228,18 @@ function listEmulators () {
             });
         });
 }
+
+module.exports.runListDevices = async function (options = {}) {
+    const { options: cliArgs = {} } = options;
+
+    if (cliArgs?.device) {
+        await module.exports.listDevices.call(this);
+    } else if (cliArgs?.emulator) {
+        await module.exports.listEmulators.call(this);
+    } else {
+        await module.exports.listDevices.call(this);
+        await module.exports.listEmulators.call(this);
+    }
+
+    return true;
+};
diff --git a/package.json b/package.json
index e9efc07a..54bfc443 100644
--- a/package.json
+++ b/package.json
@@ -25,7 +25,7 @@
     "xcodebuild": "xcodebuild -quiet test -workspace 
tests/cordova-ios.xcworkspace -destination \"platform=iOS Simulator,name=iPhone 
8\" CONFIGURATION_BUILD_DIR=\"`mktemp -d 2>/dev/null || mktemp -d -t 
'cordova-ios'`\"",
     "preobjc-tests": "killall Simulator || true",
     "unit-tests": "jasmine --config=tests/spec/unit.json",
-    "lint": "eslint . \"lib/**/!(*.*)\""
+    "lint": "eslint . \"templates/cordova/lib/!(*.*)\""
   },
   "author": "Apache Software Foundation",
   "license": "Apache-2.0",
diff --git a/lib/list-devices b/templates/cordova/lib/list-devices
similarity index 94%
rename from lib/list-devices
rename to templates/cordova/lib/list-devices
index 5f89e21b..81c3e3d7 100755
--- a/lib/list-devices
+++ b/templates/cordova/lib/list-devices
@@ -19,7 +19,7 @@
        under the License.
 */
 
-const { run } = require('./listDevices');
+const { run } = require('cordova-ios/lib/listDevices');
 
 run().then(devices => {
     devices.forEach(device => {
diff --git a/lib/list-emulator-images 
b/templates/cordova/lib/list-emulator-images
similarity index 93%
rename from lib/list-emulator-images
rename to templates/cordova/lib/list-emulator-images
index db9b72af..b422269c 100755
--- a/lib/list-emulator-images
+++ b/templates/cordova/lib/list-emulator-images
@@ -19,7 +19,7 @@
        under the License.
 */
 
-const { run } = require('./listEmulatorImages');
+const { run } = require('cordova-ios/lib/listEmulatorImages');
 
 run().then(names => {
     names.forEach(name => {
diff --git a/tests/spec/unit/Api.spec.js b/tests/spec/unit/Api.spec.js
index 269e9053..f7c48b91 100644
--- a/tests/spec/unit/Api.spec.js
+++ b/tests/spec/unit/Api.spec.js
@@ -92,6 +92,18 @@ describe('Platform Api', () => {
                     });
                 });
             });
+
+            describe('listTargets', () => {
+                beforeEach(() => {
+                    spyOn(check_reqs, 
'run').and.returnValue(Promise.resolve());
+                });
+                it('should call into lib/run module', () => {
+                    spyOn(run_mod, 'runListDevices');
+                    return api.listTargets().then(() => {
+                        expect(run_mod.runListDevices).toHaveBeenCalled();
+                    });
+                });
+            });
         }
 
         describe('addPlugin', () => {
diff --git a/tests/spec/unit/lib/run.spec.js b/tests/spec/unit/lib/run.spec.js
index a08ce31b..160c965f 100644
--- a/tests/spec/unit/lib/run.spec.js
+++ b/tests/spec/unit/lib/run.spec.js
@@ -48,6 +48,27 @@ if (process.platform === 'darwin') {
                     expect(run.listEmulators).toHaveBeenCalled();
                 });
             });
+
+            it('should delegate to "listDevices" when the "runListDevices" 
method options param contains "options.device".', () => {
+                return run.runListDevices({ options: { device: true } 
}).then(() => {
+                    expect(run.listDevices).toHaveBeenCalled();
+                    expect(run.listEmulators).not.toHaveBeenCalled();
+                });
+            });
+
+            it('should delegate to "listDevices" when the "runListDevices" 
method options param contains "options.emulator".', () => {
+                return run.runListDevices({ options: { emulator: true } 
}).then(() => {
+                    expect(run.listDevices).not.toHaveBeenCalled();
+                    expect(run.listEmulators).toHaveBeenCalled();
+                });
+            });
+
+            it('should delegate to both "listEmulators" and "listDevices" when 
the "runListDevices" method does not contain "options.device" or 
"options.emulator".', () => {
+                return run.runListDevices({ options: {} }).then(() => {
+                    expect(run.listDevices).toHaveBeenCalled();
+                    expect(run.listEmulators).toHaveBeenCalled();
+                });
+            });
         });
     });
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to