Skip to content

Commit

Permalink
Closes #424: Detox hangs if binary is not found
Browse files Browse the repository at this point in the history
  • Loading branch information
rotemmiz committed Nov 21, 2017
1 parent af41517 commit a36a7d6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
9 changes: 8 additions & 1 deletion detox/src/client/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
}
}
Expand Down
6 changes: 4 additions & 2 deletions detox/src/client/Client.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down

0 comments on commit a36a7d6

Please sign in to comment.