Skip to content
Open
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
9 changes: 5 additions & 4 deletions lib/services/livesync/ios-device-livesync-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ export class IOSDeviceLiveSyncService
}

private async setupSocketIfNeeded(
projectData: IProjectData
projectData: IProjectData,
ensureAppStarted: boolean = true
): Promise<boolean> {
// TODO: persist the sockets per app in order to support LiveSync on multiple apps on the same device
if (this.socket) {
Expand All @@ -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,
Expand Down Expand Up @@ -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);
}
}

Expand Down
63 changes: 63 additions & 0 deletions test/services/livesync/ios-device-livesync-service.ts
Original file line number Diff line number Diff line change
@@ -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 (<any>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]);
});
});
Loading