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

dpogue 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 4f8992a4 fix: Error when no simulators are available (#1470)
4f8992a4 is described below

commit 4f8992a4ad9b3f4c0e9ea99d0edd1b8d736cdadc
Author: Darryl Pogue <dar...@dpogue.ca>
AuthorDate: Mon Aug 19 19:07:43 2024 -0700

    fix: Error when no simulators are available (#1470)
    
    This should at least return a useful and actionable error message to the
    end user, rather than "Cannot read property name of undefined".
    
    Closes GH-526.
    Closes GH-1366.
    Closes GH-1377.
    Closes GH-1469.
---
 lib/build.js                  |  7 ++++---
 tests/spec/unit/build.spec.js | 15 +++++++++++++++
 2 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/lib/build.js b/lib/build.js
index cfb6a894..73d57fa7 100644
--- a/lib/build.js
+++ b/lib/build.js
@@ -85,10 +85,11 @@ function getDefaultSimulatorTarget () {
     events.emit('log', 'Select last emulator from list as default.');
     return require('./listEmulatorBuildTargets').run()
         .then(emulators => {
-            let targetEmulator;
-            if (emulators.length > 0) {
-                targetEmulator = emulators[0];
+            if (emulators.length === 0) {
+                return Promise.reject(new CordovaError('Could not find any iOS 
simulators. Use Xcode to install simulator devices for testing.'));
             }
+
+            let targetEmulator = emulators[0];
             emulators.forEach(emulator => {
                 if (emulator.name.indexOf('iPhone') === 0) {
                     targetEmulator = emulator;
diff --git a/tests/spec/unit/build.spec.js b/tests/spec/unit/build.spec.js
index 6e0b1da4..ad7282fa 100644
--- a/tests/spec/unit/build.spec.js
+++ b/tests/spec/unit/build.spec.js
@@ -418,6 +418,21 @@ describe('build', () => {
                 });
             });
         });
+
+        it('should handle the case of no simulators being available', () => {
+            // This method will require a module that supports the run method.
+            build.__set__('require', () => ({
+                run: () => Promise.resolve([])
+            }));
+
+            const getDefaultSimulatorTarget = 
build.__get__('getDefaultSimulatorTarget');
+
+            return getDefaultSimulatorTarget().then(sim => {
+                return Promise.reject(new Error('Should not resolve if no 
simulators are present'));
+            }, (err) => {
+                expect(err).toBeInstanceOf(CordovaError);
+            });
+        });
     });
 
     describe('findXCodeProjectIn method', () => {


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

Reply via email to