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: Error when no simulators are available #1470

Merged
merged 1 commit into from
Aug 20, 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
7 changes: 4 additions & 3 deletions lib/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
15 changes: 15 additions & 0 deletions tests/spec/unit/build.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down