Skip to content

Commit

Permalink
Merge pull request #2005 from wix/softfail-emu-skin-patch
Browse files Browse the repository at this point in the history
Resort to soft-failing errors in emulator version detection for skin-cfg patching
  • Loading branch information
d4vidi committed Apr 14, 2020
2 parents b64a96d + 90bbf08 commit 73c13ee
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 8 deletions.
11 changes: 10 additions & 1 deletion detox/src/devices/drivers/android/EmulatorDriver.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,16 @@ class EmulatorDriver extends AndroidDriver {
}

async _fixEmulatorConfigIniSkinNameIfNeeded(avdName) {
const binaryVersion = _.get(await this.binaryVersion(), 'major', EMU_BIN_STABLE_SKIN_VER - 1);
const binaryVersion = _.get(await this.binaryVersion(), 'major');
if (!binaryVersion) {
log.warn({ event: 'EMU_SKIN_CFG_PATCH' }, [
'Failed to detect emulator version! (see previous logs)',
'This leaves Detox unable to tell if it should automatically apply this patch-fix: https://stackoverflow.com/a/47265664/453052, which seems to be needed in emulator versions < 28.',
'If you feel this is not needed, you can either ignore this message, or otherwise apply the patch manually.',
].join('\n'));
return;
}

if (binaryVersion >= EMU_BIN_STABLE_SKIN_VER) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,14 @@ class EmulatorVersionResolver {
}

async _resolve() {
const rawOutput = await this._emulatorExec.exec(new QueryVersionCommand()) || '';
let rawOutput;
try {
rawOutput = await this._emulatorExec.exec(new QueryVersionCommand()) || '';
} catch (error) {
log.error({ event: EMU_BIN_VERSION_DETECT_EV, success: false, error }, 'Could not detect emulator binary version', error);
return null;
}

const matches = rawOutput.match(/Android emulator version ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]*)/);
if (!matches) {
log.warn({ event: EMU_BIN_VERSION_DETECT_EV, success: false }, 'Could not detect emulator binary version, got:', rawOutput);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ describe('Emulator binary version', () => {
child: jest.fn().mockReturnValue({
debug: jest.fn(),
warn: jest.fn(),
error: jest.fn(),
}),
}));
log = require('../../../../utils/logger').child();
Expand Down Expand Up @@ -65,6 +66,25 @@ describe('Emulator binary version', () => {
expect(version).toEqual(null);
});

it('should log in case of a parsing error', async () => {
emulatorExec.exec.mockResolvedValue('non-parsable result');
await uut.resolve();
expect(log.warn).toHaveBeenCalledWith({event: 'EMU_BIN_VERSION_DETECT', success: false}, expect.any(String), 'non-parsable result');
});

it('should return null in case of a version-query failure', async () => {
emulatorExec.exec.mockRejectedValue(new Error('some error'));
const version = await uut.resolve();
expect(version).toEqual(null);
});

it('should log in case of a version-query failure', async () => {
const error = new Error('some error');
emulatorExec.exec.mockRejectedValue(error);
await uut.resolve();
expect(log.error).toHaveBeenCalledWith({event: 'EMU_BIN_VERSION_DETECT', success: false, error}, expect.any(String), error);
});

it('should cache the version', async () => {
await uut.resolve();
const version = await uut.resolve();
Expand All @@ -77,10 +97,4 @@ describe('Emulator binary version', () => {
await uut.resolve();
expect(log.debug).toHaveBeenCalledWith({event: 'EMU_BIN_VERSION_DETECT', success: true}, expect.any(String), expectedVersion);
});

it('should log in case of an error', async () => {
emulatorExec.exec.mockResolvedValue('mock result');
await uut.resolve();
expect(log.warn).toHaveBeenCalledWith({event: 'EMU_BIN_VERSION_DETECT', success: false}, expect.any(String), 'mock result');
});
});

0 comments on commit 73c13ee

Please sign in to comment.