Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resort to soft-failing errors in emulator version detection for skin-cfg patching #2005

Merged
merged 1 commit into from
Apr 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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');
});
});