-
-
Notifications
You must be signed in to change notification settings - Fork 197
/
Copy pathstubs.ts
191 lines (157 loc) · 5.67 KB
/
stubs.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
/* tslint:disable:no-empty */
import * as util from "util";
import { EventEmitter } from "events";
import { LoggerConfigData } from "../../../constants";
export class LockServiceStub implements ILockService {
public async lock(lockFilePath?: string, lockOpts?: ILockOptions): Promise<() => void> {
return () => { };
}
public async unlock(lockFilePath?: string): Promise<void> {
}
public async executeActionWithLock<T>(action: () => Promise<T>, lockFilePath?: string, lockOpts?: ILockOptions): Promise<T> {
const result = await action();
return result;
}
}
export class CommonLoggerStub implements ILogger {
loggerLevel: string = "";
initialize(opts?: ILoggerOptions): void { }
initializeCliLogger(): void { }
getLevel(): string { return this.loggerLevel; }
fatal(...args: any[]): void { }
error(...args: any[]): void {
this.errorOutput += util.format.apply(null, args) + "\n";
}
warn(...args: any[]): void {
this.output += util.format.apply(null, args) + "\n";
}
info(...args: any[]): void {
this.output += util.format.apply(null, args) + "\n";
}
debug(...args: any[]): void { }
trace(...args: any[]): void {
this.traceOutput += util.format.apply(null, args) + "\n";
}
public output = "";
public traceOutput = "";
public errorOutput = "";
prepare(item: any): string {
return "";
}
printMarkdown(message: string): void {
this.output += message;
}
write(...args: any[]): void { }
printInfoMessageOnSameLine(message: string): void { }
async printMsgWithTimeout(message: string, timeout: number): Promise<void> { }
printOnStderr(formatStr?: any, ...args: any[]): void { }
isVerbose(): boolean { return false; }
}
export class ErrorsStub implements IErrors {
printCallStack: boolean = false;
fail(formatStr: string, ...args: any[]): never;
fail(opts: { formatStr?: string; errorCode?: number; suppressCommandHelp?: boolean }, ...args: any[]): never;
fail(...args: any[]): never {
if (_.isObject(args) && (<any>args).formatStr) {
throw new Error((<any>args).formatStr);
}
throw new Error(util.format.apply(null, args));
}
failWithoutHelp(message: string, ...args: any[]): never {
throw new Error(message);
}
async beginCommand(action: () => Promise<boolean>, printHelpCommand: () => Promise<void>): Promise<boolean> {
return action();
}
executeAction(action: Function): any {
return action();
}
verifyHeap(message: string): void { }
}
export class HooksServiceStub implements IHooksService {
async executeBeforeHooks(commandName: string): Promise<void> {
return;
}
async executeAfterHooks(commandName: string): Promise<void> {
return;
}
hookArgsName = "hookArgs";
}
export class SettingsService implements ISettingsService {
public setSettings(settings: IConfigurationSettings) {
// Intentionally left blank
}
public getProfileDir() {
return "profileDir";
}
}
export class AndroidProcessServiceStub implements Mobile.IAndroidProcessService {
public MapAbstractToTcpPortResult = "stub";
public GetDebuggableAppsResult: Mobile.IDeviceApplicationInformation[] = [];
public GetMappedAbstractToTcpPortsResult: IDictionary<number> = {};
public GetAppProcessIdResult = "stub";
public GetAppProcessIdFailAttempts = 0;
public ForwardFreeTcpToAbstractPortResult = 0;
async mapAbstractToTcpPort(deviceIdentifier: string, appIdentifier: string, framework: string): Promise<string> {
return this.MapAbstractToTcpPortResult;
}
async getDebuggableApps(deviceIdentifier: string): Promise<Mobile.IDeviceApplicationInformation[]> {
return this.GetDebuggableAppsResult;
}
async getMappedAbstractToTcpPorts(deviceIdentifier: string, appIdentifiers: string[], framework: string): Promise<IDictionary<number>> {
return this.GetMappedAbstractToTcpPortsResult;
}
async getAppProcessId(deviceIdentifier: string, appIdentifier: string): Promise<string> {
while (this.GetAppProcessIdFailAttempts) {
this.GetAppProcessIdFailAttempts--;
return null;
}
return this.GetAppProcessIdResult;
}
async forwardFreeTcpToAbstractPort(portForwardInputData: Mobile.IPortForwardData): Promise<number> {
return this.ForwardFreeTcpToAbstractPortResult;
}
}
export class LogcatHelperStub implements Mobile.ILogcatHelper {
public StopCallCount = 0;
public StartCallCount = 0;
public DumpCallCount = 0;
public LastStartCallOptions: Mobile.ILogcatStartOptions = {
deviceIdentifier: ""
};
public LastStopDeviceId = "";
async start(options: Mobile.ILogcatStartOptions): Promise<void> {
this.LastStartCallOptions = options;
this.StartCallCount++;
}
stop(deviceIdentifier: string): void {
this.LastStopDeviceId = deviceIdentifier;
this.StopCallCount++;
}
dump(): Promise<void> {
this.DumpCallCount++;
return Promise.resolve();
}
}
export class DeviceLogProviderStub extends EventEmitter implements Mobile.IDeviceLogProvider {
public logger = new CommonLoggerStub();
public currentDevicePids: IStringDictionary = {};
public currentDeviceProjectNames: IStringDictionary = {};
public currentDeviceProjectDirs: IStringDictionary = {};
async setSourceFileLocation(pathToSourceFile: string): Promise<void> {
}
logData(line: string, platform: string, deviceIdentifier: string): void {
this.logger.info(line, platform, deviceIdentifier, { [LoggerConfigData.skipNewLine]: true });
}
setLogLevel(level: string, deviceIdentifier?: string): void {
}
setApplicationPidForDevice(deviceIdentifier: string, pid: string): void {
this.currentDevicePids[deviceIdentifier] = pid;
}
setProjectNameForDevice(deviceIdentifier: string, projectName: string): void {
this.currentDeviceProjectNames[deviceIdentifier] = projectName;
}
setProjectDirForDevice(deviceIdentifier: string, projectDir: string): void {
this.currentDeviceProjectDirs[deviceIdentifier] = projectDir;
}
}