diff --git a/lib/services/livesync/ios-device-livesync-service.ts b/lib/services/livesync/ios-device-livesync-service.ts index 78c3150ff9..8668c0fca0 100644 --- a/lib/services/livesync/ios-device-livesync-service.ts +++ b/lib/services/livesync/ios-device-livesync-service.ts @@ -58,7 +58,8 @@ export class IOSDeviceLiveSyncService } private async setupSocketIfNeeded( - projectData: IProjectData + projectData: IProjectData, + ensureAppStarted: boolean = true ): Promise { // TODO: persist the sockets per app in order to support LiveSync on multiple apps on the same device if (this.socket) { @@ -67,8 +68,6 @@ export class IOSDeviceLiveSyncService const appId = projectData.projectIdentifiers.ios; try { - // TODO: temp workaround till we setup the sockets along with the app start - const ensureAppStarted = true; this.socket = await this.device.getDebugSocket( appId, projectData.projectName, @@ -217,7 +216,9 @@ export class IOSDeviceLiveSyncService if (liveSyncInfo.useHotModuleReload) { // enable HOT updates - await this.setupSocketIfNeeded(projectData); + // Starting the app again here would terminate the instance launched + // above. + await this.setupSocketIfNeeded(projectData, false); } } diff --git a/test/services/livesync/ios-device-livesync-service.ts b/test/services/livesync/ios-device-livesync-service.ts new file mode 100644 index 0000000000..97e03af8f3 --- /dev/null +++ b/test/services/livesync/ios-device-livesync-service.ts @@ -0,0 +1,63 @@ +import * as assert from "assert"; +import { IOSDeviceLiveSyncService } from "../../../lib/services/livesync/ios-device-livesync-service"; + +describe("IOSDeviceLiveSyncService", () => { + const projectData: any = { + projectName: "app", + projectDir: "/app", + projectIdentifiers: { ios: "org.app" }, + }; + + const restart = async (waitForDebugger: boolean) => { + const calls: string[] = []; + const ensureAppStartedValues: boolean[] = []; + const device: any = { + applicationManager: { + restartApplication: async () => { + calls.push("restart"); + }, + }, + getDebugSocket: async ( + _appId: string, + _projectName: string, + _projectDir: string, + ensureAppStarted: boolean + ) => { + calls.push("socket"); + ensureAppStartedValues.push(ensureAppStarted); + return { on: () => {}, removeAllListeners: () => {} }; + }, + }; + const service = new (IOSDeviceLiveSyncService)( + { trace: () => {} }, + {}, + {}, + {}, + {}, + {}, + device + ); + + await service.restartApplication(projectData, { + deviceAppData: { appIdentifier: "org.app" }, + useHotModuleReload: true, + waitForDebugger, + }); + + return { calls, ensureAppStartedValues }; + }; + + it("connects to the app it restarted without starting it again", async () => { + const { calls, ensureAppStartedValues } = await restart(false); + + assert.deepStrictEqual(calls, ["restart", "socket"]); + assert.deepStrictEqual(ensureAppStartedValues, [false]); + }); + + it("keeps an instance that waits for a debugger", async () => { + const { calls, ensureAppStartedValues } = await restart(true); + + assert.deepStrictEqual(calls, ["restart", "socket"]); + assert.deepStrictEqual(ensureAppStartedValues, [false]); + }); +});