From b34d8663ce4f58b6a9030fa60d3fd940cd322d18 Mon Sep 17 00:00:00 2001 From: Darryl Pogue Date: Mon, 7 Oct 2024 22:31:44 -0700 Subject: [PATCH] fix(emulators): Fix listing emulator targets --- lib/listEmulatorBuildTargets.js | 2 -- lib/run.js | 10 +++++----- tests/spec/unit/run.spec.js | 12 ++++++------ 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/lib/listEmulatorBuildTargets.js b/lib/listEmulatorBuildTargets.js index c3d7b8b48..0377c9e71 100644 --- a/lib/listEmulatorBuildTargets.js +++ b/lib/listEmulatorBuildTargets.js @@ -18,7 +18,6 @@ */ const execa = require('execa'); -const { events } = require('cordova-common'); /** * Returns a list of available simulator build targets of the form @@ -32,7 +31,6 @@ const { events } = require('cordova-common'); * */ function listEmulatorBuildTargets () { - events.emit('log', 'List simulator targets'); return execa('xcrun', ['simctl', 'list', '--json']) .then(({ stdout }) => JSON.parse(stdout)) .then(function (simInfo) { diff --git a/lib/run.js b/lib/run.js index eb35c6b09..869bd72fb 100644 --- a/lib/run.js +++ b/lib/run.js @@ -138,7 +138,7 @@ module.exports.startSim = startSim; module.exports.listDevices = listDevices; module.exports.listEmulators = listEmulators; module.exports.execListDevices = execListDevices; -module.exports.execListEmulatorTargets = execListEmulatorTargets; +module.exports.execListEmulatorImages = execListEmulatorImages; /** * Filters the args array and removes supported args for the 'run' command. @@ -207,7 +207,7 @@ async function deployToSim (appPath, target) { if (!target) { // Select target device for emulator (preferring iPhone Emulators) - const emulators = await module.exports.execListEmulatorTargets(); + const emulators = await module.exports.execListEmulatorImages(); const iPhoneEmus = emulators.filter(emulator => emulator.startsWith('iPhone')); target = iPhoneEmus.concat(emulators)[0]; events.emit('log', `No target specified for emulator. Deploying to "${target}" simulator.`); @@ -248,8 +248,8 @@ function execListDevices () { } /* istanbul ignore next */ -function execListEmulatorTargets () { - return require('./listEmulatorTargets').run(); +function execListEmulatorImages () { + return require('./listEmulatorImages').run(); } function listDevices () { @@ -263,7 +263,7 @@ function listDevices () { } function listEmulators () { - return module.exports.execListEmulatorTargets() + return module.exports.execListEmulatorImages() .then(emulators => { events.emit('log', 'Available iOS Simulators:'); emulators.forEach(emulator => { diff --git a/tests/spec/unit/run.spec.js b/tests/spec/unit/run.spec.js index 8b693103a..cc965abb2 100644 --- a/tests/spec/unit/run.spec.js +++ b/tests/spec/unit/run.spec.js @@ -35,22 +35,22 @@ describe('cordova/lib/run', () => { beforeEach(() => { spyOn(events, 'emit'); spyOn(run, 'execListDevices').and.returnValue(Promise.resolve(['iPhone Xs'])); - spyOn(run, 'execListEmulatorTargets').and.returnValue(Promise.resolve(['iPhone 15 Simulator'])); + spyOn(run, 'execListEmulatorImages').and.returnValue(Promise.resolve(['iPhone 15 Simulator'])); }); it('should delegate to "listDevices" when the "runListDevices" method options param contains "options.device".', () => { return run.runListDevices({ options: { device: true } }).then(() => { expect(run.execListDevices).toHaveBeenCalled(); - expect(run.execListEmulatorTargets).not.toHaveBeenCalled(); + expect(run.execListEmulatorImages).not.toHaveBeenCalled(); expect(events.emit).toHaveBeenCalledWith('log', '\tiPhone Xs'); }); }); - it('should delegate to "listDevices" when the "runListDevices" method options param contains "options.emulator".', () => { + it('should delegate to "listEmulators" when the "runListDevices" method options param contains "options.emulator".', () => { return run.runListDevices({ options: { emulator: true } }).then(() => { expect(run.execListDevices).not.toHaveBeenCalled(); - expect(run.execListEmulatorTargets).toHaveBeenCalled(); + expect(run.execListEmulatorImages).toHaveBeenCalled(); expect(events.emit).toHaveBeenCalledWith('log', '\tiPhone 15 Simulator'); }); @@ -59,7 +59,7 @@ describe('cordova/lib/run', () => { it('should delegate to both "listEmulators" and "listDevices" when the "runListDevices" method does not contain "options.device" or "options.emulator".', () => { return run.runListDevices().then(() => { expect(run.execListDevices).toHaveBeenCalled(); - expect(run.execListEmulatorTargets).toHaveBeenCalled(); + expect(run.execListEmulatorImages).toHaveBeenCalled(); expect(events.emit).toHaveBeenCalledWith('log', '\tiPhone Xs'); expect(events.emit).toHaveBeenCalledWith('log', '\tiPhone 15 Simulator'); @@ -80,7 +80,7 @@ describe('cordova/lib/run', () => { spyOn(build, 'run').and.returnValue(Promise.resolve()); spyOn(projectFile, 'parse').and.returnValue(fakeXcodeProject); spyOn(run, 'execListDevices').and.resolveTo([]); - spyOn(run, 'execListEmulatorTargets').and.resolveTo([]); + spyOn(run, 'execListEmulatorImages').and.resolveTo([]); spyOn(run, 'listDevices').and.resolveTo(); spyOn(run, 'deployToMac').and.resolveTo(); spyOn(run, 'deployToSim').and.resolveTo();