Skip to content

Commit

Permalink
fix(ios): preserve logs after device.resetContentAndSettings() (#4215)
Browse files Browse the repository at this point in the history
  • Loading branch information
noomorph authored Oct 11, 2023
1 parent 585bca0 commit ba39bbb
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 110 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,10 @@ class SimulatorAllocDriver {
* @param {import('../../DeviceRegistry')} options.deviceRegistry
* @param {DetoxInternals.RuntimeConfig} options.detoxConfig
* @param {import('../../../common/drivers/ios/tools/AppleSimUtils')} options.applesimutils
* @param {import('./SimulatorLauncher')} options.simulatorLauncher
*/
constructor({ detoxConfig, deviceRegistry, applesimutils, simulatorLauncher }) {
constructor({ detoxConfig, deviceRegistry, applesimutils }) {
this._deviceRegistry = deviceRegistry;
this._applesimutils = applesimutils;
this._simulatorLauncher = simulatorLauncher;
this._launchInfo = {};
this._shouldShutdown = detoxConfig.behavior.cleanup.shutdownDevice;
}
Expand Down Expand Up @@ -61,7 +59,7 @@ class SimulatorAllocDriver {
async postAllocate(deviceCookie) {
const { udid } = deviceCookie;
const { deviceConfig } = this._launchInfo[udid];
await this._simulatorLauncher.launch(udid, deviceConfig.type, deviceConfig.bootArgs, deviceConfig.headless);
await this._applesimutils.boot(udid, deviceConfig.bootArgs, deviceConfig.headless);

return {
id: udid,
Expand Down Expand Up @@ -105,7 +103,7 @@ class SimulatorAllocDriver {
*/
async _doShutdown(udid) {
try {
await this._simulatorLauncher.shutdown(udid);
await this._applesimutils.shutdown(udid);
} catch (err) {
log.warn({ err }, `Failed to shutdown simulator ${udid}`);
}
Expand Down
25 changes: 0 additions & 25 deletions detox/src/devices/allocation/drivers/ios/SimulatorLauncher.js

This file was deleted.

63 changes: 0 additions & 63 deletions detox/src/devices/allocation/drivers/ios/SimulatorLauncher.test.js

This file was deleted.

5 changes: 1 addition & 4 deletions detox/src/devices/allocation/factories/ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,8 @@ class IosSimulator extends DeviceAllocatorFactory {
const DeviceRegistry = require('../../../devices/allocation/DeviceRegistry');
const deviceRegistry = new DeviceRegistry({ sessionId: detoxSession.id });

const SimulatorLauncher = require('../drivers/ios/SimulatorLauncher');
const simulatorLauncher = new SimulatorLauncher({ applesimutils, eventEmitter });

const SimulatorAllocDriver = require('../drivers/ios/SimulatorAllocDriver');
return new SimulatorAllocDriver({ detoxConfig, deviceRegistry, applesimutils, simulatorLauncher });
return new SimulatorAllocDriver({ detoxConfig, deviceRegistry, applesimutils });
}
}

Expand Down
9 changes: 5 additions & 4 deletions detox/src/devices/runtime/drivers/ios/SimulatorDriver.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ const IosDriver = require('./IosDriver');

/**
* @typedef SimulatorDriverDeps { DeviceDriverDeps }
* @property simulatorLauncher { SimulatorLauncher }
* @property applesimutils { AppleSimUtils }
*/

Expand All @@ -38,7 +37,6 @@ class SimulatorDriver extends IosDriver {
this._bootArgs = bootArgs;
this._headless = headless;
this._deviceName = `${udid} (${this._type})`;
this._simulatorLauncher = deps.simulatorLauncher;
this._applesimutils = deps.applesimutils;
}

Expand Down Expand Up @@ -150,9 +148,12 @@ class SimulatorDriver extends IosDriver {
}

async resetContentAndSettings() {
await this._simulatorLauncher.shutdown(this.udid);
await this.emitter.emit('beforeShutdownDevice', { deviceId: this.udid });
await this._applesimutils.shutdown(this.udid);
await this.emitter.emit('shutdownDevice', { deviceId: this.udid });
await this._applesimutils.resetContentAndSettings(this.udid);
await this._simulatorLauncher.launch(this.udid, this._type, this._bootArgs, this._headless);
await this._applesimutils.boot(this.udid, this._bootArgs, this._headless);
await this.emitter.emit('bootDevice', { deviceId: this.udid });
}

getLogsPaths() {
Expand Down
10 changes: 3 additions & 7 deletions detox/src/devices/runtime/drivers/ios/SimulatorDriver.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ describe('IOS simulator driver', () => {
let client;
let eventEmitter;
let applesimutils;
let simulatorLauncher;
let uut;
beforeEach(() => {
const AsyncEmitter = require('../../../../utils/AsyncEmitter');
Expand All @@ -24,12 +23,9 @@ describe('IOS simulator driver', () => {
const AppleSimUtils = jest.genMockFromModule('../../../common/drivers/ios/tools/AppleSimUtils');
applesimutils = new AppleSimUtils();

const SimulatorLauncher = jest.genMockFromModule('../../../allocation/drivers/ios/SimulatorLauncher');
simulatorLauncher = new SimulatorLauncher();

const SimulatorDriver = require('./SimulatorDriver');
uut = new SimulatorDriver(
{ simulatorLauncher, applesimutils, client, eventEmitter },
{ applesimutils, client, eventEmitter },
{ udid, type, bootArgs, headless }
);
});
Expand Down Expand Up @@ -74,7 +70,7 @@ describe('IOS simulator driver', () => {
describe('.resetContentAndSettings', () => {
it('should shut the device down', async () => {
await uut.resetContentAndSettings();
expect(simulatorLauncher.shutdown).toHaveBeenCalledWith(udid);
expect(applesimutils.shutdown).toHaveBeenCalledWith(udid);
});

it('should reset via apple-sim-utils', async () => {
Expand All @@ -84,7 +80,7 @@ describe('IOS simulator driver', () => {

it('should relaunch the simulator', async () => {
await uut.resetContentAndSettings();
expect(simulatorLauncher.launch).toHaveBeenCalledWith(udid, type, bootArgs, true);
expect(applesimutils.boot).toHaveBeenCalledWith(udid, bootArgs, true);
});
});

Expand Down
2 changes: 0 additions & 2 deletions detox/src/devices/runtime/factories/ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@ class RuntimeDriverFactoryIos extends RuntimeDeviceFactory {
const AppleSimUtils = require('../../../devices/common/drivers/ios/tools/AppleSimUtils');
const applesimutils = new AppleSimUtils();

const SimulatorLauncher = require('../../allocation/drivers/ios/SimulatorLauncher');
return {
...commonDeps,
applesimutils,
simulatorLauncher: new SimulatorLauncher({ applesimutils, eventEmitter }),
};
}
}
Expand Down

0 comments on commit ba39bbb

Please sign in to comment.