Skip to content

Commit 100d250

Browse files
committed
fix(ios): count only the --device selection when deciding on the USB tunnel
Session descriptors include every discovered device, so a booted simulator or a second iOS device on the network turned the tunnel off even when --device picked a single USB iPhone.
1 parent 1113346 commit 100d250

3 files changed

Lines changed: 28 additions & 0 deletions

File tree

‎lib/controllers/run-controller.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -873,7 +873,16 @@ export class RunController extends EventEmitter implements IRunController {
873873
return;
874874
}
875875

876+
// Descriptors cover every discovered device; `--device` narrows the
877+
// session to one of them.
878+
const selected = this.$devicesService.getDeviceByDeviceOption();
876879
const platformTargets = sessionDeviceDescriptors.filter((descriptor) => {
880+
if (
881+
selected &&
882+
descriptor.identifier !== selected.deviceInfo.identifier
883+
) {
884+
return false;
885+
}
877886
const target = this.$devicesService.getDeviceByIdentifier(
878887
descriptor.identifier,
879888
);

‎test/controllers/run-controller.ts‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,24 @@ describe("RunController", () => {
363363
assert.deepStrictEqual(openedFor, []);
364364
});
365365

366+
it("opens the tunnel of the --device selection when another iOS device is attached", async () => {
367+
const devicesService = injector.resolve("devicesService");
368+
devicesService.getDeviceByDeviceOption = () => iOSDevice;
369+
mockDevicesService(injector, [iOSDevice]);
370+
371+
try {
372+
await runController.run({
373+
liveSyncInfo: hmrLiveSyncInfo,
374+
deviceDescriptors: [iOSDeviceDescriptor, secondIOSDeviceDescriptor],
375+
});
376+
} finally {
377+
devicesService.getDeviceByDeviceOption = (): Mobile.IDevice =>
378+
undefined;
379+
}
380+
381+
assert.deepStrictEqual(openedFor, ["myiOSDevice"]);
382+
});
383+
366384
it("does not open a tunnel when the user set NS_HMR_HOST", async () => {
367385
process.env.NS_HMR_HOST = "192.168.1.10";
368386
mockDevicesService(injector, [iOSDevice]);

‎test/stubs.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1557,6 +1557,7 @@ export class InjectorStub extends Yok implements IInjector {
15571557
this.register("devicesService", {
15581558
getDevice: (): Mobile.IDevice => undefined,
15591559
getDeviceByIdentifier: (): Mobile.IDevice => undefined,
1560+
getDeviceByDeviceOption: (): Mobile.IDevice => undefined,
15601561
});
15611562
this.register("terminalSpinnerService", TerminalSpinnerServiceStub);
15621563
}

0 commit comments

Comments
 (0)