forked from microsoft/react-native-code-push
-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathcode-push-plugin-testing-framework.d.ts
More file actions
491 lines (483 loc) · 17.7 KB
/
code-push-plugin-testing-framework.d.ts
File metadata and controls
491 lines (483 loc) · 17.7 KB
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
declare module 'code-push-plugin-testing-framework/script/platform' {
import Q = require("q");
/**
* Defines a platform supported by CodePush.
*/
export interface IPlatform {
/**
* Gets the platform name. (e.g. "android" for the Android platform).
*/
getName(): string;
/**
* The command line flag used to determine whether or not this platform should run.
* Runs when the flag is present, doesn't run otherwise.
*/
getCommandLineFlagName(): string;
/**
* Gets the server url used for testing.
*/
getServerUrl(): string;
/**
* Gets an IEmulatorManager that is used to control the emulator during the tests.
*/
getEmulatorManager(): IEmulatorManager;
/**
* Gets the default deployment key.
*/
getDefaultDeploymentKey(): string;
}
/**
* Manages the interaction with the emulator.
*/
export interface IEmulatorManager {
/**
* Returns the target emulator, which is specified through the command line.
*/
getTargetEmulator(): Q.Promise<string>;
/**
* Boots the target emulator.
*/
bootEmulator(restartEmulators: boolean): Q.Promise<void>;
/**
* Launches an already installed application by app id.
*/
launchInstalledApplication(appId: string): Q.Promise<void>;
/**
* Ends a running application given its app id.
*/
endRunningApplication(appId: string): Q.Promise<void>;
/**
* Restarts an already installed application by app id.
*/
restartApplication(appId: string): Q.Promise<void>;
/**
* Navigates away from the current app, waits for a delay (defaults to 1 second), then navigates to the specified app.
*/
resumeApplication(appId: string, delayBeforeResumingMs?: number): Q.Promise<void>;
/**
* Prepares the emulator for a test.
*/
prepareEmulatorForTest(appId: string): Q.Promise<void>;
/**
* Uninstalls the app from the emulator.
*/
uninstallApplication(appId: string): Q.Promise<void>;
}
/**
* Android implementations of IPlatform.
*/
export class Android implements IPlatform {
private emulatorManager;
private serverUrl;
constructor(emulatorManager: IEmulatorManager);
/**
* Gets the platform name. (e.g. "android" for the Android platform).
*/
getName(): string;
/**
* The command line flag used to determine whether or not this platform should run.
* Runs when the flag is present, doesn't run otherwise.
*/
getCommandLineFlagName(): string;
private static DEFAULT_ANDROID_SERVER_URL;
/**
* Gets the server url used for testing.
*/
getServerUrl(): string;
/**
* Gets an IEmulatorManager that is used to control the emulator during the tests.
*/
getEmulatorManager(): IEmulatorManager;
/**
* Gets the default deployment key.
*/
getDefaultDeploymentKey(): string;
}
/**
* IOS implementation of IPlatform.
*/
export class IOS implements IPlatform {
private emulatorManager;
private serverUrl;
constructor(emulatorManager: IEmulatorManager);
/**
* Gets the platform name. (e.g. "android" for the Android platform).
*/
getName(): string;
/**
* The command line flag used to determine whether or not this platform should run.
* Runs when the flag is present, doesn't run otherwise.
*/
getCommandLineFlagName(): string;
private static DEFAULT_IOS_SERVER_URL;
/**
* Gets the server url used for testing.
*/
getServerUrl(): string;
/**
* Gets an IEmulatorManager that is used to control the emulator during the tests.
*/
getEmulatorManager(): IEmulatorManager;
/**
* Gets the default deployment key.
*/
getDefaultDeploymentKey(): string;
}
export class AndroidEmulatorManager implements IEmulatorManager {
private targetEmulator;
/**
* Returns the target emulator, which is specified through the command line.
*/
getTargetEmulator(): Q.Promise<string>;
/**
* Boots the target emulator.
*/
bootEmulator(restartEmulators: boolean): Q.Promise<void>;
/**
* Launches an already installed application by app id.
*/
launchInstalledApplication(appId: string): Q.Promise<void>;
/**
* Ends a running application given its app id.
*/
endRunningApplication(appId: string): Q.Promise<void>;
/**
* Restarts an already installed application by app id.
*/
restartApplication(appId: string): Q.Promise<void>;
/**
* Navigates away from the current app, waits for a delay (defaults to 1 second), then navigates to the specified app.
*/
resumeApplication(appId: string, delayBeforeResumingMs?: number): Q.Promise<void>;
/**
* Prepares the emulator for a test.
*/
prepareEmulatorForTest(appId: string): Q.Promise<void>;
/**
* Uninstalls the app from the emulator.
*/
uninstallApplication(appId: string): Q.Promise<void>;
}
export class IOSEmulatorManager implements IEmulatorManager {
private targetEmulator;
/**
* Returns the target emulator, which is specified through the command line.
*/
getTargetEmulator(): Q.Promise<string>;
/**
* Boots the target emulator.
*/
bootEmulator(restartEmulators: boolean): Q.Promise<void>;
/**
* Launches an already installed application by app id.
*/
launchInstalledApplication(appId: string): Q.Promise<void>;
/**
* Ends a running application given its app id.
*/
endRunningApplication(appId: string): Q.Promise<void>;
/**
* Restarts an already installed application by app id.
*/
restartApplication(appId: string): Q.Promise<void>;
/**
* Navigates away from the current app, waits for a delay (defaults to 1 second), then navigates to the specified app.
*/
resumeApplication(appId: string, delayBeforeResumingMs?: number): Q.Promise<void>;
/**
* Prepares the emulator for a test.
*/
prepareEmulatorForTest(appId: string): Q.Promise<void>;
/**
* Uninstalls the app from the emulator.
*/
uninstallApplication(appId: string): Q.Promise<void>;
}
}
declare module 'code-push-plugin-testing-framework/script/projectManager' {
import Q = require("q");
import platform = require('code-push-plugin-testing-framework/script/platform');
/**
* In charge of project related operations.
*/
export class ProjectManager {
static DEFAULT_APP_VERSION: string;
private static NOT_IMPLEMENTED_ERROR_MSG;
/**
* Returns the name of the plugin being tested, for example Cordova or React-Native.
*
* Overwrite this in your implementation!
*/
getPluginName(): string;
/**
* Creates a new test application at the specified path, and configures it
* with the given server URL, android and ios deployment keys.
*
* Overwrite this in your implementation!
*/
setupProject(projectDirectory: string, templatePath: string, appName: string, appNamespace: string, version?: string): Q.Promise<void>;
/**
* Sets up the scenario for a test in an already existing project.
*
* Overwrite this in your implementation!
*/
setupScenario(projectDirectory: string, appId: string, templatePath: string, jsPath: string, targetPlatform: platform.IPlatform, version?: string): Q.Promise<void>;
/**
* Creates a CodePush update package zip for a project.
*
* Overwrite this in your implementation!
*/
createUpdateArchive(projectDirectory: string, targetPlatform: platform.IPlatform, isDiff?: boolean): Q.Promise<string>;
/**
* Prepares a specific platform for tests.
*
* Overwrite this in your implementation!
*/
preparePlatform(projectDirectory: string, targetPlatform: platform.IPlatform): Q.Promise<void>;
/**
* Cleans up a specific platform after tests.
*
* Overwrite this in your implementation!
*/
cleanupAfterPlatform(projectDirectory: string, targetPlatform: platform.IPlatform): Q.Promise<void>;
/**
* Runs the test app on the given target / platform.
*
* Overwrite this in your implementation!
*/
runApplication(projectDirectory: string, targetPlatform: platform.IPlatform): Q.Promise<void>;
}
/**
* Wrapper for ProjectManager.setupScenario in the TestRun directory.
*/
export function setupTestRunScenario(projectManager: ProjectManager, targetPlatform: platform.IPlatform, scenarioJsPath: string, version?: string): Q.Promise<void>;
/**
* Creates an update and zip for the test app using the specified scenario and version.
*/
export function setupUpdateScenario(projectManager: ProjectManager, targetPlatform: platform.IPlatform, scenarioJsPath: string, version: string): Q.Promise<string>;
}
declare module 'code-push-plugin-testing-framework/script/test' {
import Platform = require('code-push-plugin-testing-framework/script/platform');
import { ProjectManager } from 'code-push-plugin-testing-framework/script/projectManager';
/**
* Call this function to initialize the automated tests.
*/
export function initializeTests(projectManager: ProjectManager, supportedTargetPlatforms: Platform.IPlatform[], describeTests: (projectManager: ProjectManager, targetPlatform: Platform.IPlatform) => void): void;
}
declare module 'code-push-plugin-testing-framework/script/serverUtil' {
import platform = require('code-push-plugin-testing-framework/script/platform');
import Q = require("q");
/** The server to respond to requests from the app. */
export var server: any;
/** Response the server gives the next update check request */
export var updateResponse: any;
/** Number of times to mock a download failure */
export var mockDownloadFailureCount: number;
/** Response the server gives the next test message request */
export var testMessageResponse: any;
/** Called after the next test message request */
export var testMessageCallback: (requestBody: any) => void;
/** Called after the next update check request */
export var updateCheckCallback: (requestBody: any) => void;
/** Location of the update package given in the update check response */
export var updatePackagePath: string;
/**
* Sets up the server that the test app uses to send test messages and check for and download updates.
*/
export function setupServer(targetPlatform: platform.IPlatform): void;
/**
* Closes the server.
*/
export function cleanupServer(): void;
/**
* Class used to mock the codePush.checkForUpdate() response from the server.
*/
export class CheckForUpdateResponseMock {
download_url: string;
is_available: boolean;
should_run_binary_version: boolean;
package_size: number;
update_app_version: boolean;
target_binary_range: string;
is_disabled: boolean;
description: string;
label: string;
package_hash: string;
is_mandatory: boolean;
}
/**
* The model class of the codePush.checkForUpdate() request to the server.
*/
export class UpdateCheckRequestMock {
deploymentKey: string;
appVersion: string;
packageHash: string;
isCompanion: boolean;
}
/**
* Returns a default empty response to give to the app in a checkForUpdate request
*/
export function createDefaultResponse(): CheckForUpdateResponseMock;
/**
* Returns a default update response to give to the app in a checkForUpdate request
*/
export function createUpdateResponse(mandatory?: boolean, targetPlatform?: platform.IPlatform, randomHash?: boolean): CheckForUpdateResponseMock;
/**
* Returns a promise that waits for the next set of test messages sent by the app and resolves if that they are equal to the expected messages or rejects if they are not.
*/
export function expectTestMessages(expectedMessages: (string | AppMessage)[]): Q.Promise<void>;
/**
* Contains all the messages sent from the application to the mock server during tests.
*/
export class TestMessage {
static CHECK_UP_TO_DATE: string;
static CHECK_UPDATE_AVAILABLE: string;
static CHECK_ERROR: string;
static DOWNLOAD_SUCCEEDED: string;
static DOWNLOAD_ERROR: string;
static UPDATE_INSTALLED: string;
static INSTALL_ERROR: string;
static DEVICE_READY_AFTER_UPDATE: string;
static UPDATE_FAILED_PREVIOUSLY: string;
static NOTIFY_APP_READY_SUCCESS: string;
static NOTIFY_APP_READY_FAILURE: string;
static SKIPPED_NOTIFY_APPLICATION_READY: string;
static SYNC_STATUS: string;
static RESTART_SUCCEEDED: string;
static RESTART_FAILED: string;
static PENDING_PACKAGE: string;
static CURRENT_PACKAGE: string;
static SYNC_UP_TO_DATE: number;
static SYNC_UPDATE_INSTALLED: number;
static SYNC_UPDATE_IGNORED: number;
static SYNC_ERROR: number;
static SYNC_IN_PROGRESS: number;
static SYNC_CHECKING_FOR_UPDATE: number;
static SYNC_AWAITING_USER_ACTION: number;
static SYNC_DOWNLOADING_PACKAGE: number;
static SYNC_INSTALLING_UPDATE: number;
}
/**
* Contains all the messages sent from the mock server back to the application during tests.
*/
export class TestMessageResponse {
static SKIP_NOTIFY_APPLICATION_READY: string;
}
/**
* Defines the messages sent from the application to the mock server during tests.
*/
export class AppMessage {
message: string;
args: any[];
constructor(message: string, args: any[]);
static fromString(message: string): AppMessage;
}
/**
* Checks if two messages are equal.
*/
export function areEqual(m1: AppMessage, m2: AppMessage): boolean;
}
declare module 'code-push-plugin-testing-framework/script/testBuilder' {
import Platform = require('code-push-plugin-testing-framework/script/platform');
import { ProjectManager } from 'code-push-plugin-testing-framework/script/projectManager';
export class TestBuilder {
static describe: ITestBuilderContextDefintion;
static it: ITestBuilderTestDefinition;
}
/** Singleton class for TestBuilder.describe to use internally to define the context. */
export class TestContext {
static projectManager: ProjectManager;
static targetPlatform: Platform.IPlatform;
}
export interface ITestBuilderContextDefintion {
(description: string, spec: () => void, scenarioPath?: string): void;
only(description: string, spec: () => void, scenarioPath?: string): void;
skip(description: string, spec: () => void, scenarioPath?: string): void;
}
export interface ITestBuilderTestDefinition {
(expectation: string, isCoreTest: boolean, assertion: (done: Mocha.Done) => void): void;
only(expectation: string, isCoreTest: boolean, assertion: (done: Mocha.Done) => void): void;
skip(expectation: string, isCoreTest: boolean, assertion: (done: Mocha.Done) => void): void;
}
}
declare module 'code-push-plugin-testing-framework/script/testConfig' {
export const TestAppName: string;
export const TestNamespace: string;
export const AcquisitionSDKPluginName: string;
export const templatePath: string;
export const thisPluginInstallString: string;
export const testRunDirectory: string;
export const updatesDirectory: string;
export const onlyRunCoreTests: boolean;
export const shouldSetup: boolean;
export const isExpoApp: boolean;
export const restartEmulators: boolean;
export const testOldArch: boolean;
}
declare module 'code-push-plugin-testing-framework/script/testUtil' {
import Q = require("q");
export class TestUtil {
static ANDROID_KEY_PLACEHOLDER: string;
static IOS_KEY_PLACEHOLDER: string;
static SERVER_URL_PLACEHOLDER: string;
static INDEX_JS_PLACEHOLDER: string;
static CODE_PUSH_APP_VERSION_PLACEHOLDER: string;
static CODE_PUSH_TEST_APP_NAME_PLACEHOLDER: string;
static CODE_PUSH_APP_ID_PLACEHOLDER: string;
static PLUGIN_VERSION_PLACEHOLDER: string;
/**
* Reads a command line option passed to mocha and returns a default if unspecified.
*/
static readMochaCommandLineOption(optionName: string, defaultValue?: string): string;
/**
* Reads command line options passed to mocha.
*/
static readMochaCommandLineFlag(optionName: string): boolean;
/**
* Executes a child process and returns a promise that resolves with its output or rejects with its error.
*/
static getProcessOutput(command: string, options?: {
cwd?: string;
stdio?: any;
customFds?: any;
env?: any;
encoding?: string;
timeout?: number;
maxBuffer?: number;
killSignal?: string;
noLogCommand?: boolean;
noLogStdOut?: boolean;
noLogStdErr?: boolean;
}): Q.Promise<string>;
/**
* Returns the name of the plugin that is being tested.
*/
static getPluginName(): string;
/**
* Replaces a regex in a file with a given string.
*/
static replaceString(filePath: string, regex: string, replacement: string): void;
/**
* Copies a file from a given location to another.
*/
static copyFile(source: string, destination: string, overwrite: boolean): Q.Promise<void>;
/**
* Archives the contents of sourceFolder and puts it in an archive at archivePath in targetFolder.
*/
static archiveFolder(sourceFolder: string, targetFolder: string, archivePath: string, isDiff: boolean): Q.Promise<string>;
}
}
declare module 'code-push-plugin-testing-framework/script/index' {
import * as Platform from 'code-push-plugin-testing-framework/script/platform';
import * as PluginTestingFramework from 'code-push-plugin-testing-framework/script/test';
import { ProjectManager, setupTestRunScenario, setupUpdateScenario } from 'code-push-plugin-testing-framework/script/projectManager';
import * as ServerUtil from 'code-push-plugin-testing-framework/script/serverUtil';
import { TestBuilder } from 'code-push-plugin-testing-framework/script/testBuilder';
import * as TestConfig from 'code-push-plugin-testing-framework/script/testConfig';
import { TestUtil } from 'code-push-plugin-testing-framework/script/testUtil';
export { Platform, PluginTestingFramework, ProjectManager, setupTestRunScenario, setupUpdateScenario, ServerUtil, TestBuilder, TestConfig, TestUtil };
}
declare module 'code-push-plugin-testing-framework' {
import main = require('code-push-plugin-testing-framework/script/index');
export = main;
}