-
-
Notifications
You must be signed in to change notification settings - Fork 197
/
Copy pathstubs.ts
176 lines (143 loc) · 4.91 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
/* tslint:disable:no-empty */
import * as util from "util";
import { EventEmitter } from "events";
export class CommonLoggerStub implements ILogger {
setLevel(level: string): void { }
getLevel(): string { return undefined; }
fatal(...args: string[]): void { }
error(...args: string[]): void { }
warn(...args: string[]): void {
this.out.apply(this, args);
}
warnWithLabel(...args: string[]): void { }
info(...args: string[]): void {
this.out.apply(this, args);
}
debug(...args: string[]): void { }
trace(...args: string[]): void {
this.traceOutput += util.format.apply(null, args) + "\n";
}
public output = "";
public traceOutput = "";
out(...args: string[]): void {
this.output += util.format.apply(null, args) + "\n";
}
write(...args: string[]): void { }
prepare(item: any): string {
return "";
}
printInfoMessageOnSameLine(message: string): void { }
async printMsgWithTimeout(message: string, timeout: number): Promise<void> {
return null;
}
printMarkdown(message: string): void {
this.output += message;
}
printOnStderr(...args: string[]): void {
// nothing to do here
}
}
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 = {};
logData(line: string, platform: string, deviceIdentifier: string): void {
this.logger.write(line, platform, deviceIdentifier);
}
setLogLevel(level: string, deviceIdentifier?: string): void {
this.logger.setLevel(level);
}
setApplicationPidForDevice(deviceIdentifier: string, pid: string): void {
this.currentDevicePids[deviceIdentifier] = pid;
}
setProjectNameForDevice(deviceIdentifier: string, projectName: string): void {
this.currentDeviceProjectNames[deviceIdentifier] = projectName;
}
muteLogsForDevice(deviceIdentifier: string): void { }
}