Skip to content

Commit ff69ddd

Browse files
authored
fix(emulators): Fix listing emulator targets (#1495)
1 parent ecac294 commit ff69ddd

File tree

3 files changed

+11
-13
lines changed

3 files changed

+11
-13
lines changed

lib/listEmulatorBuildTargets.js

-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
*/
1919

2020
const execa = require('execa');
21-
const { events } = require('cordova-common');
2221

2322
/**
2423
* Returns a list of available simulator build targets of the form
@@ -32,7 +31,6 @@ const { events } = require('cordova-common');
3231
*
3332
*/
3433
function listEmulatorBuildTargets () {
35-
events.emit('log', 'List simulator targets');
3634
return execa('xcrun', ['simctl', 'list', '--json'])
3735
.then(({ stdout }) => JSON.parse(stdout))
3836
.then(function (simInfo) {

lib/run.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ module.exports.startSim = startSim;
138138
module.exports.listDevices = listDevices;
139139
module.exports.listEmulators = listEmulators;
140140
module.exports.execListDevices = execListDevices;
141-
module.exports.execListEmulatorTargets = execListEmulatorTargets;
141+
module.exports.execListEmulatorImages = execListEmulatorImages;
142142

143143
/**
144144
* Filters the args array and removes supported args for the 'run' command.
@@ -207,7 +207,7 @@ async function deployToSim (appPath, target) {
207207

208208
if (!target) {
209209
// Select target device for emulator (preferring iPhone Emulators)
210-
const emulators = await module.exports.execListEmulatorTargets();
210+
const emulators = await module.exports.execListEmulatorImages();
211211
const iPhoneEmus = emulators.filter(emulator => emulator.startsWith('iPhone'));
212212
target = iPhoneEmus.concat(emulators)[0];
213213
events.emit('log', `No target specified for emulator. Deploying to "${target}" simulator.`);
@@ -248,8 +248,8 @@ function execListDevices () {
248248
}
249249

250250
/* istanbul ignore next */
251-
function execListEmulatorTargets () {
252-
return require('./listEmulatorTargets').run();
251+
function execListEmulatorImages () {
252+
return require('./listEmulatorImages').run();
253253
}
254254

255255
function listDevices () {
@@ -263,7 +263,7 @@ function listDevices () {
263263
}
264264

265265
function listEmulators () {
266-
return module.exports.execListEmulatorTargets()
266+
return module.exports.execListEmulatorImages()
267267
.then(emulators => {
268268
events.emit('log', 'Available iOS Simulators:');
269269
emulators.forEach(emulator => {

tests/spec/unit/run.spec.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -35,22 +35,22 @@ describe('cordova/lib/run', () => {
3535
beforeEach(() => {
3636
spyOn(events, 'emit');
3737
spyOn(run, 'execListDevices').and.returnValue(Promise.resolve(['iPhone Xs']));
38-
spyOn(run, 'execListEmulatorTargets').and.returnValue(Promise.resolve(['iPhone 15 Simulator']));
38+
spyOn(run, 'execListEmulatorImages').and.returnValue(Promise.resolve(['iPhone 15 Simulator']));
3939
});
4040

4141
it('should delegate to "listDevices" when the "runListDevices" method options param contains "options.device".', () => {
4242
return run.runListDevices({ options: { device: true } }).then(() => {
4343
expect(run.execListDevices).toHaveBeenCalled();
44-
expect(run.execListEmulatorTargets).not.toHaveBeenCalled();
44+
expect(run.execListEmulatorImages).not.toHaveBeenCalled();
4545

4646
expect(events.emit).toHaveBeenCalledWith('log', '\tiPhone Xs');
4747
});
4848
});
4949

50-
it('should delegate to "listDevices" when the "runListDevices" method options param contains "options.emulator".', () => {
50+
it('should delegate to "listEmulators" when the "runListDevices" method options param contains "options.emulator".', () => {
5151
return run.runListDevices({ options: { emulator: true } }).then(() => {
5252
expect(run.execListDevices).not.toHaveBeenCalled();
53-
expect(run.execListEmulatorTargets).toHaveBeenCalled();
53+
expect(run.execListEmulatorImages).toHaveBeenCalled();
5454

5555
expect(events.emit).toHaveBeenCalledWith('log', '\tiPhone 15 Simulator');
5656
});
@@ -59,7 +59,7 @@ describe('cordova/lib/run', () => {
5959
it('should delegate to both "listEmulators" and "listDevices" when the "runListDevices" method does not contain "options.device" or "options.emulator".', () => {
6060
return run.runListDevices().then(() => {
6161
expect(run.execListDevices).toHaveBeenCalled();
62-
expect(run.execListEmulatorTargets).toHaveBeenCalled();
62+
expect(run.execListEmulatorImages).toHaveBeenCalled();
6363

6464
expect(events.emit).toHaveBeenCalledWith('log', '\tiPhone Xs');
6565
expect(events.emit).toHaveBeenCalledWith('log', '\tiPhone 15 Simulator');
@@ -80,7 +80,7 @@ describe('cordova/lib/run', () => {
8080
spyOn(build, 'run').and.returnValue(Promise.resolve());
8181
spyOn(projectFile, 'parse').and.returnValue(fakeXcodeProject);
8282
spyOn(run, 'execListDevices').and.resolveTo([]);
83-
spyOn(run, 'execListEmulatorTargets').and.resolveTo([]);
83+
spyOn(run, 'execListEmulatorImages').and.resolveTo([]);
8484
spyOn(run, 'listDevices').and.resolveTo();
8585
spyOn(run, 'deployToMac').and.resolveTo();
8686
spyOn(run, 'deployToSim').and.resolveTo();

0 commit comments

Comments
 (0)