Skip to content
This repository was archived by the owner on Feb 2, 2021. It is now read-only.

Commit 0e88a4c

Browse files
Fix cocoapods check and add unit tests for doctor service
When cocoapods are not installed on Mac machine, doctor is failing. Fix this by skipping match check in case pods are not installed. Add basic unit tests for doctor service. Add unit test for the failing cocoapods check. Wrap winreg module in our own class.
1 parent 2811f51 commit 0e88a4c

File tree

6 files changed

+438
-33
lines changed

6 files changed

+438
-33
lines changed

bootstrap.ts

+1
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,4 @@ $injector.requireCommand("doctor", "./commands/doctor");
100100

101101
$injector.require("utils", "./utils");
102102
$injector.require("bplistParser", "./bplist-parser");
103+
$injector.require("winreg", "./winreg");

declarations.d.ts

+103-1
Original file line numberDiff line numberDiff line change
@@ -366,10 +366,11 @@ interface ISysInfoData {
366366
interface ISysInfo {
367367
/**
368368
* Returns information for the current system.
369+
* @param {string} pathToPackageJson Path to package.json of the CLI.
369370
* @param {any} androidToolsInfo Defines paths to adb and android executables.
370371
* @return {IFuture<ISysInfoData>} Object containing information for current system.
371372
*/
372-
getSysInfo(androidToolsInfo?: {pathToAdb: string, pathToAndroid: string}): IFuture<ISysInfoData>;
373+
getSysInfo(pathToPackageJson: string, androidToolsInfo?: {pathToAdb: string, pathToAndroid: string}): IFuture<ISysInfoData>;
373374
}
374375

375376
interface IHostInfo {
@@ -559,3 +560,104 @@ interface IPluginVariablesHelper {
559560
getPluginVariableFromVarOption(variableName: string, configuration?: string): any;
560561
simplifyYargsObject(obj: any, configuration?: string): any;
561562
}
563+
564+
/**
565+
* Describes Registry values returned from winreg
566+
*/
567+
interface IWinRegResult {
568+
/**
569+
* The hostname, if it has been set in the options.
570+
*/
571+
host: string;
572+
573+
/**
574+
* The hive id, as specified in the options
575+
*/
576+
hive: string;
577+
/**
578+
* The key, as specified in the options
579+
*/
580+
key: string;
581+
582+
/**
583+
* The name of the registry value
584+
*/
585+
name: string;
586+
587+
/**
588+
* One of the types:
589+
* REG_SZ a string value
590+
* REG_MULTI_SZ a multiline string value
591+
* REG_EXPAND_SZ an expandable string value
592+
* REG_DWORD a double word value (32 bit integer)
593+
* REG_QWORD a quad word value (64 bit integer)
594+
* REG_BINARY a binary value
595+
* REG_NONE a value of unknown type
596+
*/
597+
type: string;
598+
599+
/**
600+
* A string containing the value
601+
*/
602+
value: string;
603+
}
604+
605+
/**
606+
* Describes single registry available for search.
607+
*/
608+
interface IHiveId {
609+
/**
610+
* Name of the registry that will be checked.
611+
*/
612+
registry: string;
613+
}
614+
615+
/**
616+
* Describes available for search registry ids.
617+
*/
618+
interface IHiveIds {
619+
/**
620+
* HKEY_LOCAL_MACHINE
621+
*/
622+
HKLM: IHiveId;
623+
624+
/**
625+
* HKEY_CURRENT_USER
626+
*/
627+
HKCU: IHiveId;
628+
629+
/**
630+
* HKEY_CLASSES_ROOT
631+
*/
632+
HKCR: IHiveId;
633+
634+
/**
635+
* HKEY_CURRENT_CONFIG
636+
*/
637+
HKCC: IHiveId;
638+
639+
/**
640+
* HKEY_USERS
641+
*/
642+
HKU: IHiveId;
643+
}
644+
645+
/**
646+
* Defines reading values from registry. Wrapper for node-winreg module.s
647+
*/
648+
interface IWinReg {
649+
/**
650+
* Gets specified value from the registry.
651+
* The following options are processed by the Winreg constructor:
652+
* @param {string} valueName Value that has to be checked in the registry.
653+
* @param {IHiveId} hive The optional hive id, the default is HKLM.
654+
* @param {string} key The optional key, the default is the root key
655+
* @param {string} host The optional hostname, must start with the '\\' sequence
656+
*/
657+
getRegistryValue(valueName: string, hive?: IHiveId, key?: string, host?: string): IFuture<IWinRegResult>;
658+
659+
/**
660+
* Gets object containing available registries for search.
661+
*/
662+
registryKeys: IHiveIds;
663+
}

dispatchers.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"use strict";
33

44
import * as queue from "./queue";
5+
import * as path from "path";
56

67
export class CommandDispatcher implements ICommandDispatcher {
78
constructor(private $logger: ILogger,
@@ -19,7 +20,8 @@ export class CommandDispatcher implements ICommandDispatcher {
1920
}
2021

2122
if (this.$logger.getLevel() === "TRACE") {
22-
let sysInfo = this.$sysInfo.getSysInfo().wait();
23+
// CommandDispatcher is called from external CLI's only, so pass the path to their package.json
24+
let sysInfo = this.$sysInfo.getSysInfo(path.join(__dirname, "..", "..", "package.json")).wait();
2325
this.$logger.trace("System information:");
2426
this.$logger.trace(sysInfo);
2527
}

sys-info-base.ts

+28-31
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,26 @@
33

44
import * as os from "os";
55
import * as osenv from "osenv";
6-
import Future = require("fibers/future");
76
import * as path from "path";
87
import {quoteString} from "./helpers";
98

109
export class SysInfoBase implements ISysInfo {
1110
constructor(protected $childProcess: IChildProcess,
1211
protected $hostInfo: IHostInfo,
1312
protected $iTunesValidator: Mobile.IiTunesValidator,
14-
protected $logger: ILogger) { }
13+
protected $logger: ILogger,
14+
protected $winreg: IWinReg) { }
1515

16-
private static monoVerRegExp = /version (\d+[.]\d+[.]\d+) /gm;
16+
private monoVerRegExp = /version (\d+[.]\d+[.]\d+) /gm;
1717
private sysInfoCache: ISysInfoData = undefined;
1818

19-
public getSysInfo(androidToolsInfo?: {pathToAdb: string, pathToAndroid: string}): IFuture<ISysInfoData> {
19+
public getSysInfo(pathToPackageJson: string, androidToolsInfo?: {pathToAdb: string, pathToAndroid: string}): IFuture<ISysInfoData> {
2020
return((): ISysInfoData => {
2121
if (!this.sysInfoCache) {
2222
let res: ISysInfoData = Object.create(null);
2323
let procOutput: string;
2424

25-
let packageJson = require("../../package.json");
25+
let packageJson = require(pathToPackageJson);
2626
res.procInfo = packageJson.name + "/" + packageJson.version;
2727

2828
// os stuff
@@ -39,7 +39,7 @@ export class SysInfoBase implements ISysInfo {
3939
res.procArch = process.arch;
4040
res.nodeVer = process.version;
4141

42-
procOutput = this.$childProcess.exec("npm -v").wait();
42+
procOutput = this.exec("npm -v");
4343
res.npmVer = procOutput ? procOutput.split("\n")[0] : null;
4444

4545
// dependencies
@@ -70,7 +70,7 @@ export class SysInfoBase implements ISysInfo {
7070

7171
procOutput = this.exec("mono --version");
7272
if (!!procOutput) {
73-
let match = SysInfoBase.monoVerRegExp.exec(procOutput);
73+
let match = this.monoVerRegExp.exec(procOutput);
7474
res.monoVer = match ? match[1] : null;
7575
} else {
7676
res.monoVer = null;
@@ -115,30 +115,25 @@ export class SysInfoBase implements ISysInfo {
115115
}
116116

117117
private winVer(): string {
118-
return this.readRegistryValue("ProductName").wait() + " " +
119-
this.readRegistryValue("CurrentVersion").wait() + "." +
120-
this.readRegistryValue("CurrentBuild").wait();
118+
try {
119+
return this.readRegistryValue("ProductName").wait() + " " +
120+
this.readRegistryValue("CurrentVersion").wait() + "." +
121+
this.readRegistryValue("CurrentBuild").wait();
122+
} catch (err) {
123+
this.$logger.trace(err);
124+
}
125+
126+
return null;
121127
}
122128

123129
private readRegistryValue(valueName: string): IFuture<string> {
124-
let future = new Future<string>();
125-
let Winreg = require("winreg");
126-
let regKey = new Winreg({
127-
hive: Winreg.HKLM,
128-
key: '\\Software\\Microsoft\\Windows NT\\CurrentVersion'
129-
});
130-
regKey.get(valueName, (err: Error, value: any) => {
131-
if (err) {
132-
future.throw(err);
133-
} else {
134-
future.return(value.value);
135-
}
136-
});
137-
return future;
130+
return ((): string => {
131+
return this.$winreg.getRegistryValue(valueName, this.$winreg.registryKeys.HKLM, '\\Software\\Microsoft\\Windows NT\\CurrentVersion').wait().value;
132+
}).future<string>()();
138133
}
139134

140135
private unixVer(): string {
141-
return this.$childProcess.exec("uname -a").wait();
136+
return this.exec("uname -a");
142137
}
143138

144139
private getJavaCompilerVersion(): IFuture<string> {
@@ -156,13 +151,15 @@ export class SysInfoBase implements ISysInfo {
156151
private getCocoapodVersion(): string {
157152
if(this.$hostInfo.isDarwin) {
158153
let cocoapodVersion = this.exec("pod --version");
159-
// Output of pod --version could contain some warnings. Find the version in it.
160-
let cocoapodVersionMatch = cocoapodVersion.match(/^((?:\d+\.){2}\d+.*?)$/gm);
161-
if(cocoapodVersionMatch && cocoapodVersionMatch[0]) {
162-
cocoapodVersion = cocoapodVersionMatch[0].trim();
163-
}
154+
if(cocoapodVersion) {
155+
// Output of pod --version could contain some warnings. Find the version in it.
156+
let cocoapodVersionMatch = cocoapodVersion.match(/^((?:\d+\.){2}\d+.*?)$/gm);
157+
if(cocoapodVersionMatch && cocoapodVersionMatch[0]) {
158+
cocoapodVersion = cocoapodVersionMatch[0].trim();
159+
}
164160

165-
return cocoapodVersion;
161+
return cocoapodVersion;
162+
}
166163
}
167164

168165
return null;

0 commit comments

Comments
 (0)