Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(emulators): Fix listing emulator targets #1495

Merged
merged 1 commit into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions lib/listEmulatorBuildTargets.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
*/

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

/**
* Returns a list of available simulator build targets of the form
Expand All @@ -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) {
Expand Down
10 changes: 5 additions & 5 deletions lib/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.`);
Expand Down Expand Up @@ -248,8 +248,8 @@ function execListDevices () {
}

/* istanbul ignore next */
function execListEmulatorTargets () {
return require('./listEmulatorTargets').run();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is the key change here. Almost everything else is just renaming this function to match what it's actually doing.

function execListEmulatorImages () {
return require('./listEmulatorImages').run();
}

function listDevices () {
Expand All @@ -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 => {
Expand Down
12 changes: 6 additions & 6 deletions tests/spec/unit/run.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
Expand All @@ -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');
Expand All @@ -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();
Expand Down