From a36a7d6599d2c87f99b7396ae5259af7cff9c0f9 Mon Sep 17 00:00:00 2001 From: Rotem M Date: Tue, 21 Nov 2017 22:16:32 +0200 Subject: [PATCH] Closes #424: Detox hangs if binary is not found --- detox/src/client/Client.js | 9 ++++++++- detox/src/client/Client.test.js | 6 ++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/detox/src/client/Client.js b/detox/src/client/Client.js index b1b2229f76..c9036a369a 100644 --- a/detox/src/client/Client.js +++ b/detox/src/client/Client.js @@ -4,6 +4,7 @@ const argparse = require('../utils/argparse'); class Client { constructor(config) { + this.isConnected = false; this.configuration = config; this.ws = new AsyncWebSocket(config.server); this.slowInvocationStatusHandler = null; @@ -26,11 +27,17 @@ class Client { async waitUntilReady() { await this.sendAction(new actions.Ready(), -1000); + this.isConnected = true; } async cleanup() { - if (this.ws.isOpen()) { + console.log(this.isConnected); + if (this.isConnected) { await this.sendAction(new actions.Cleanup(this.successfulTestRun)); + this.isConnected = false; + } + + if (this.ws.isOpen()) { await this.ws.close(); } } diff --git a/detox/src/client/Client.test.js b/detox/src/client/Client.test.js index 1d37ec0023..74635fd32e 100644 --- a/detox/src/client/Client.test.js +++ b/detox/src/client/Client.test.js @@ -59,10 +59,12 @@ describe('Client', () => { it(`cleanup() - if connected should send cleanup action and close websocket`, async () => { await connect(); - client.ws.send.mockReturnValueOnce(response("cleanupDone", {}, 1)); + client.ws.send.mockReturnValueOnce(response("ready", {}, 1)); + await client.waitUntilReady(); + client.ws.send.mockReturnValueOnce(response("cleanupDone", {}, 2)); await client.cleanup(); - expect(client.ws.send).toHaveBeenCalledTimes(2); + expect(client.ws.send).toHaveBeenCalledTimes(3); }); it(`cleanup() - if not connected should do nothing`, async () => {