Skip to content

Commit dafd54a

Browse files
committed
fix(open): preserve platformless device resolution
1 parent 4da836f commit dafd54a

2 files changed

Lines changed: 19 additions & 25 deletions

File tree

‎src/core/__tests__/dispatch-resolve.test.ts‎

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -185,33 +185,28 @@ test('resolveTargetDevice selects the unique booted simulator with the requested
185185
);
186186
});
187187

188-
test('resolveTargetDevice uses app-aware iOS selection when platform is omitted', async () => {
189-
mockListAppleDevices.mockResolvedValue([bootedSimulator, secondBootedSimulator]);
190-
mockFindIosSimulatorInstalledApp.mockImplementation(async (device) =>
191-
device.id === secondBootedSimulator.id ? 'com.example.demo' : undefined,
188+
test('resolveTargetDevice leaves platform-less static app selection to normal cross-platform resolution', async () => {
189+
const result = await withDeviceInventoryProvider(
190+
async (request) => {
191+
assert.equal(request.platform, undefined);
192+
return [androidEmulator, bootedSimulator, secondBootedSimulator];
193+
},
194+
async () => await resolveTargetDevice({}, { appleSimulatorAppTarget: 'com.example.demo' }),
192195
);
193196

194-
const result = await resolveTargetDevice({}, { appleSimulatorAppTarget: 'com.example.demo' });
195-
196-
assert.equal(result.id, secondBootedSimulator.id);
197-
assert.deepEqual(
198-
mockFindIosSimulatorInstalledApp.mock.calls.map(([device, app]) => [device.id, app]),
199-
[
200-
[bootedSimulator.id, 'com.example.demo'],
201-
[secondBootedSimulator.id, 'com.example.demo'],
202-
],
203-
);
197+
assert.equal(result.id, androidEmulator.id);
198+
assert.equal(mockFindIosSimulatorInstalledApp.mock.calls.length, 0);
204199
});
205200

206-
test('resolveTargetDevice reuses an app-aware selection for later platform-inferred resolution', async () => {
201+
test('resolveTargetDevice reuses an app-aware iOS selection for later iOS resolution', async () => {
207202
mockListAppleDevices.mockResolvedValue([bootedSimulator, secondBootedSimulator]);
208203
mockFindIosSimulatorInstalledApp.mockImplementation(async (device) =>
209204
device.id === secondBootedSimulator.id ? 'com.example.demo' : undefined,
210205
);
211206

212207
const [appAware, laterResolution] = await withResolveTargetDeviceCacheScope(async () => [
213-
await resolveTargetDevice({}, { appleSimulatorAppTarget: 'com.example.demo' }),
214-
await resolveTargetDevice({}),
208+
await resolveTargetDevice({ platform: 'ios' }, { appleSimulatorAppTarget: 'com.example.demo' }),
209+
await resolveTargetDevice({ platform: 'ios' }),
215210
]);
216211

217212
assert.equal(appAware.id, secondBootedSimulator.id);

‎src/core/dispatch-resolve.ts‎

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ export async function resolveTargetDevice(
214214
}
215215
const injectedDevices = await readInjectedDeviceInventory(inventoryRequest);
216216
if (injectedDevices) {
217-
if (shouldUseAppleResolution(selector, options)) {
217+
if (shouldUseAppleResolution(selector)) {
218218
return cacheResolvedTargetDevice(
219219
cacheKey,
220220
await resolveAppleDevice(injectedDevices, selector as AppleDeviceSelector, {
@@ -232,7 +232,7 @@ export async function resolveTargetDevice(
232232

233233
const devices = await listLocalDeviceInventory(inventoryRequest);
234234

235-
if (shouldUseAppleResolution(selector, options)) {
235+
if (shouldUseAppleResolution(selector)) {
236236
return cacheResolvedTargetDevice(
237237
cacheKey,
238238
await resolveAppleDevice(devices, selector as AppleDeviceSelector, {
@@ -328,12 +328,11 @@ function isAppleResolutionSelector(selector: {
328328
return isApplePlatform(selector.platform);
329329
}
330330

331-
function shouldUseAppleResolution(
332-
selector: { platform?: PlatformSelector; target?: DeviceTarget },
333-
options: ResolveTargetDeviceOptions,
334-
): boolean {
335-
if (isAppleResolutionSelector(selector)) return true;
336-
return selector.platform === undefined && options.appleSimulatorAppTarget !== undefined;
331+
function shouldUseAppleResolution(selector: {
332+
platform?: PlatformSelector;
333+
target?: DeviceTarget;
334+
}): boolean {
335+
return isAppleResolutionSelector(selector);
337336
}
338337

339338
function readResolveTargetDeviceCache(cacheKey: string): DeviceInfo | undefined {

0 commit comments

Comments
 (0)