Skip to content

Commit 6068e54

Browse files
committed
hotfix: do not shutdown device on --cleanup if it is not prepared
1 parent f13b338 commit 6068e54

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

detox/src/devices/Device.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ class Device {
271271
async _cleanup() {
272272
await this.deviceDriver.cleanup(this._deviceId, this._bundleId);
273273

274-
if (argparse.getArgValue('cleanup')) {
274+
if (argparse.getArgValue('cleanup') && this._deviceId) {
275275
await this.deviceDriver.shutdown(this._deviceId);
276276
}
277277

detox/src/devices/Device.test.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -713,20 +713,33 @@ describe('Device', () => {
713713
expect(driverMock.driver.cleanup).toHaveBeenCalledTimes(1);
714714
});
715715

716-
it(`_cleanup() should not shutdown the device by default`, async () => {
716+
it(`_cleanup() should shutdown a prepared device if --cleanup is passed from CLI`, async () => {
717+
argparse.getArgValue.mockReturnValue(true);
718+
719+
const device = validDevice();
720+
await device.prepare();
721+
await device._cleanup();
722+
723+
expect(driverMock.driver.shutdown).toHaveBeenCalled();
724+
});
725+
726+
it(`_cleanup() should not shutdown a prepared device if --cleanup is not passed from CLI`, async () => {
727+
argparse.getArgValue.mockReturnValue(false);
728+
717729
const device = validDevice();
730+
await device.prepare();
718731
await device._cleanup();
719732

720733
expect(driverMock.driver.shutdown).not.toHaveBeenCalled();
721734
});
722735

723-
it(`_cleanup() should shutdown the device if --cleanup is passed form CLI`, async () => {
736+
it(`_cleanup() should not shutdown an unprepared device even if --cleanup is passed from CLI`, async () => {
724737
argparse.getArgValue.mockReturnValue(true);
725738

726739
const device = validDevice();
727740
await device._cleanup();
728741

729-
expect(driverMock.driver.shutdown).toHaveBeenCalledTimes(1);
742+
expect(driverMock.driver.shutdown).not.toHaveBeenCalled();
730743
});
731744

732745
it(`new Device() with invalid device config (no binary) should throw`, () => {

0 commit comments

Comments
 (0)