Skip to content

Commit 90bbf08

Browse files
committed
Resort to soft-failing errors in emulator version detection for skin-cfg patching
1 parent 30f6dfa commit 90bbf08

File tree

3 files changed

+38
-8
lines changed

3 files changed

+38
-8
lines changed

detox/src/devices/drivers/android/EmulatorDriver.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,16 @@ class EmulatorDriver extends AndroidDriver {
105105
}
106106

107107
async _fixEmulatorConfigIniSkinNameIfNeeded(avdName) {
108-
const binaryVersion = _.get(await this.binaryVersion(), 'major', EMU_BIN_STABLE_SKIN_VER - 1);
108+
const binaryVersion = _.get(await this.binaryVersion(), 'major');
109+
if (!binaryVersion) {
110+
log.warn({ event: 'EMU_SKIN_CFG_PATCH' }, [
111+
'Failed to detect emulator version! (see previous logs)',
112+
'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.',
113+
'If you feel this is not needed, you can either ignore this message, or otherwise apply the patch manually.',
114+
].join('\n'));
115+
return;
116+
}
117+
109118
if (binaryVersion >= EMU_BIN_STABLE_SKIN_VER) {
110119
return;
111120
}

detox/src/devices/drivers/android/emulator/EmulatorVersionResolver.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,14 @@ class EmulatorVersionResolver {
1717
}
1818

1919
async _resolve() {
20-
const rawOutput = await this._emulatorExec.exec(new QueryVersionCommand()) || '';
20+
let rawOutput;
21+
try {
22+
rawOutput = await this._emulatorExec.exec(new QueryVersionCommand()) || '';
23+
} catch (error) {
24+
log.error({ event: EMU_BIN_VERSION_DETECT_EV, success: false, error }, 'Could not detect emulator binary version', error);
25+
return null;
26+
}
27+
2128
const matches = rawOutput.match(/Android emulator version ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]*)/);
2229
if (!matches) {
2330
log.warn({ event: EMU_BIN_VERSION_DETECT_EV, success: false }, 'Could not detect emulator binary version, got:', rawOutput);

detox/src/devices/drivers/android/emulator/EmulatorVersionResolver.test.js

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ describe('Emulator binary version', () => {
3535
child: jest.fn().mockReturnValue({
3636
debug: jest.fn(),
3737
warn: jest.fn(),
38+
error: jest.fn(),
3839
}),
3940
}));
4041
log = require('../../../../utils/logger').child();
@@ -65,6 +66,25 @@ describe('Emulator binary version', () => {
6566
expect(version).toEqual(null);
6667
});
6768

69+
it('should log in case of a parsing error', async () => {
70+
emulatorExec.exec.mockResolvedValue('non-parsable result');
71+
await uut.resolve();
72+
expect(log.warn).toHaveBeenCalledWith({event: 'EMU_BIN_VERSION_DETECT', success: false}, expect.any(String), 'non-parsable result');
73+
});
74+
75+
it('should return null in case of a version-query failure', async () => {
76+
emulatorExec.exec.mockRejectedValue(new Error('some error'));
77+
const version = await uut.resolve();
78+
expect(version).toEqual(null);
79+
});
80+
81+
it('should log in case of a version-query failure', async () => {
82+
const error = new Error('some error');
83+
emulatorExec.exec.mockRejectedValue(error);
84+
await uut.resolve();
85+
expect(log.error).toHaveBeenCalledWith({event: 'EMU_BIN_VERSION_DETECT', success: false, error}, expect.any(String), error);
86+
});
87+
6888
it('should cache the version', async () => {
6989
await uut.resolve();
7090
const version = await uut.resolve();
@@ -77,10 +97,4 @@ describe('Emulator binary version', () => {
7797
await uut.resolve();
7898
expect(log.debug).toHaveBeenCalledWith({event: 'EMU_BIN_VERSION_DETECT', success: true}, expect.any(String), expectedVersion);
7999
});
80-
81-
it('should log in case of an error', async () => {
82-
emulatorExec.exec.mockResolvedValue('mock result');
83-
await uut.resolve();
84-
expect(log.warn).toHaveBeenCalledWith({event: 'EMU_BIN_VERSION_DETECT', success: false}, expect.any(String), 'mock result');
85-
});
86100
});

0 commit comments

Comments
 (0)