diff --git a/detox/src/devices/drivers/android/EmulatorDriver.js b/detox/src/devices/drivers/android/EmulatorDriver.js index 647cb0bb2e..24c022969f 100644 --- a/detox/src/devices/drivers/android/EmulatorDriver.js +++ b/detox/src/devices/drivers/android/EmulatorDriver.js @@ -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; } diff --git a/detox/src/devices/drivers/android/emulator/EmulatorVersionResolver.js b/detox/src/devices/drivers/android/emulator/EmulatorVersionResolver.js index e9d2666d67..8d1c87eb6d 100644 --- a/detox/src/devices/drivers/android/emulator/EmulatorVersionResolver.js +++ b/detox/src/devices/drivers/android/emulator/EmulatorVersionResolver.js @@ -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); diff --git a/detox/src/devices/drivers/android/emulator/EmulatorVersionResolver.test.js b/detox/src/devices/drivers/android/emulator/EmulatorVersionResolver.test.js index 53409ed526..d95eb0d87c 100644 --- a/detox/src/devices/drivers/android/emulator/EmulatorVersionResolver.test.js +++ b/detox/src/devices/drivers/android/emulator/EmulatorVersionResolver.test.js @@ -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(); @@ -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(); @@ -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'); - }); });