Skip to content

Commit 86e54d9

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 0088994 commit 86e54d9

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
@@ -871,7 +871,16 @@ export class RunController extends EventEmitter implements IRunController {
871871
return;
872872
}
873873

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

‎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
@@ -1540,6 +1540,7 @@ export class InjectorStub extends Yok implements IInjector {
15401540
this.register("devicesService", {
15411541
getDevice: (): Mobile.IDevice => undefined,
15421542
getDeviceByIdentifier: (): Mobile.IDevice => undefined,
1543+
getDeviceByDeviceOption: (): Mobile.IDevice => undefined,
15431544
});
15441545
this.register("terminalSpinnerService", TerminalSpinnerServiceStub);
15451546
}

0 commit comments

Comments
 (0)