Skip to content

Commit 336f9ac

Browse files
authored
fix: conduct cleanup even if app has been already terminated (#1465)
1 parent 3ffaaae commit 336f9ac

4 files changed

Lines changed: 32 additions & 5 deletions

File tree

detox/src/client/Client.test.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,16 @@ describe('Client', () => {
110110
expect(client.ws.send).toHaveBeenCalledTimes(3);
111111
});
112112

113+
it(`cleanup() - if connected should accept testeeDisconnected action too`, async () => {
114+
await connect();
115+
client.ws.send.mockReturnValueOnce(response("ready", {}, 1));
116+
await client.waitUntilReady();
117+
client.ws.send.mockReturnValueOnce(response("testeeDisconnected", {}, 2));
118+
await client.cleanup();
119+
120+
expect(client.ws.send).toHaveBeenCalledTimes(3);
121+
});
122+
113123
it(`cleanup() - if not connected should do nothing`, async () => {
114124
client = new Client(config);
115125
client.ws.send.mockReturnValueOnce(response("cleanupDone", {}, 1));

detox/src/client/actions/actions.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,14 @@ class ReloadReactNative extends Action {
8383

8484
class Cleanup extends Action {
8585
constructor(stopRunner) {
86-
const params = {
87-
stopRunner: stopRunner
88-
};
89-
super('cleanup', params);
86+
super('cleanup', { stopRunner });
87+
this.messageId = -0xc1ea;
9088
}
9189

9290
async handle(response) {
93-
this.expectResponseOfType(response, 'cleanupDone');
91+
if (response.type !== 'testeeDisconnected') {
92+
this.expectResponseOfType('cleanupDone');
93+
}
9494
}
9595
}
9696

detox/src/server/DetoxServer.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ class DetoxServer {
4949
if (sessionId && role) {
5050
this.log.debug({ event: 'DISCONNECT' }, `role=${role}, sessionId=${sessionId}`);
5151

52+
if (role === ROLE_TESTEE) {
53+
this.sendToOtherRole(sessionId, role, { type: 'testeeDisconnected', messageId: -0xc1ea });
54+
}
55+
5256
if (this.standalone && role === ROLE_TESTER) {
5357
this.sendToOtherRole(sessionId, role, { type: 'testerDisconnected', messageId: -1 });
5458
}
@@ -70,6 +74,13 @@ class DetoxServer {
7074
this.sendAction(ws, action);
7175
} else {
7276
this.log.debug({ event: 'CANNOT_FORWARD' }, `role=${otherRole} not connected, cannot fw action (sessionId=${sessionId})`);
77+
78+
if (role === ROLE_TESTER && action.type === 'cleanup') {
79+
this.sendToOtherRole(sessionId, otherRole, {
80+
type: 'testeeDisconnected',
81+
messageId: action.messageId,
82+
});
83+
}
7384
}
7485
}
7586

detox/test/e2e/23.flows.test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
describe('Flows', () => {
2+
it('should exit without timeouts if app was terminated inside test', async () => {
3+
await device.launchApp();
4+
await device.terminateApp();
5+
});
6+
});

0 commit comments

Comments
 (0)