Skip to content

Commit 873efbb

Browse files
Fix getting information about adb
When path to ANDROID_HOME contains spaces, we do not get the path to adb correctly and we return error that adb is not installed. Fix this by using child_process.spawn which handles spaces. Fix incorrect tests which did not consider the `ignoreError` option of spawnFromEvent method.
1 parent 1ee7a42 commit 873efbb

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

lib/sys-info.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,8 @@ export class SysInfo implements NativeScriptDoctor.ISysInfo {
160160

161161
public getAdbVersion(): Promise<string> {
162162
return this.getValueForProperty(() => this.adbVerCache, async (): Promise<string> => {
163-
const output = await this.execCommand(`${await this.androidToolsInfo.getPathToAdbFromAndroidHome()} version`);
164-
return output ? this.getVersionFromString(output) : null;
163+
const output = await this.childProcess.spawnFromEvent(await this.androidToolsInfo.getPathToAdbFromAndroidHome(), ["version"], "close", { ignoreError: true });
164+
return output && output.stdout ? this.getVersionFromString(output.stdout) : null;
165165
});
166166
}
167167

test/sys-info.ts

+9-4
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ function createChildProcessResults(childProcessResult: IChildProcessResults): ID
7171
"xcodebuild -version": childProcessResult.xCodeVersion,
7272
"pod --version": childProcessResult.podVersion,
7373
"pod": childProcessResult.pod,
74+
'adb': childProcessResult.adbVersion,
7475
'adb version': childProcessResult.adbVersion,
7576
"'adb' version": childProcessResult.adbVersion, // for Mac and Linux
7677
'android': childProcessResult.androidInstalled,
@@ -83,9 +84,13 @@ function createChildProcessResults(childProcessResult: IChildProcessResults): ID
8384
};
8485
}
8586

86-
function getResultFromChildProcess(childProcessResultDescription: IChildProcessResultDescription, command: string): any {
87+
function getResultFromChildProcess(childProcessResultDescription: IChildProcessResultDescription, command: string, options?: ISpawnFromEventOptions): any {
8788
if (childProcessResultDescription.shouldThrowError) {
88-
throw new Error(`This one throws error. (${command})`);
89+
if (options && options.ignoreError) {
90+
return null;
91+
} else {
92+
throw new Error(`This one throws error. (${command})`);
93+
}
8994
}
9095

9196
return childProcessResultDescription.result;
@@ -111,8 +116,8 @@ function mockSysInfo(childProcessResult: IChildProcessResults, hostInfoOptions?:
111116
exec: async (command: string) => {
112117
return getResultFromChildProcess(childProcessResultDictionary[command], command);
113118
},
114-
spawnFromEvent: async (command: string, args: string[], event: string) => {
115-
return getResultFromChildProcess(childProcessResultDictionary[command], command);
119+
spawnFromEvent: async (command: string, args: string[], event: string, options: ISpawnFromEventOptions) => {
120+
return getResultFromChildProcess(childProcessResultDictionary[command], command, options);
116121
},
117122
execFile: async () => {
118123
return undefined;

0 commit comments

Comments
 (0)