From 84a5a0c05a466c25221e45a5745d146f6e481207 Mon Sep 17 00:00:00 2001 From: fatme Date: Tue, 2 Jul 2019 13:03:59 +0300 Subject: [PATCH] fix: fix stop livesync when the method is called with empty array Currently when stop method is called with empty array, the livesync process is stopped for all devices but the runOnDeviceStopped event is not emitted. This PR fixes this behavior as ensures the runOnDeviceStopped event will be emitted for all connected devices. --- lib/controllers/run-controller.ts | 2 +- test/controllers/run-controller.ts | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/controllers/run-controller.ts b/lib/controllers/run-controller.ts index 290b9505d6..1237555a06 100644 --- a/lib/controllers/run-controller.ts +++ b/lib/controllers/run-controller.ts @@ -62,7 +62,7 @@ export class RunController extends EventEmitter implements IRunController { // so we cannot await it as this will cause infinite loop. const shouldAwaitPendingOperation = !stopOptions || stopOptions.shouldAwaitAllActions; - const deviceIdentifiersToRemove = deviceIdentifiers || _.map(liveSyncProcessInfo.deviceDescriptors, d => d.identifier); + const deviceIdentifiersToRemove = (deviceIdentifiers && deviceIdentifiers.length) ? deviceIdentifiers : _.map(liveSyncProcessInfo.deviceDescriptors, d => d.identifier); const removedDeviceIdentifiers = _.remove(liveSyncProcessInfo.deviceDescriptors, descriptor => _.includes(deviceIdentifiersToRemove, descriptor.identifier)) .map(descriptor => descriptor.identifier); diff --git a/test/controllers/run-controller.ts b/test/controllers/run-controller.ts index 9dc2e674da..e33fbc4688 100644 --- a/test/controllers/run-controller.ts +++ b/test/controllers/run-controller.ts @@ -240,6 +240,12 @@ describe("RunController", () => { currentDeviceIdentifiers: ["device1", "device2", "device3"], expectedDeviceIdentifiers: ["device1"], deviceIdentifiersToBeStopped: ["device1", "device4"] + }, + { + name: "stops LiveSync operation for all devices when stop method is called with empty array", + currentDeviceIdentifiers: ["device1", "device2", "device3"], + expectedDeviceIdentifiers: ["device1", "device2", "device3"], + deviceIdentifiersToBeStopped: [] } ];