-
Notifications
You must be signed in to change notification settings - Fork 170
Expand file tree
/
Copy pathcreate-application.ts
More file actions
67 lines (59 loc) · 2.21 KB
/
create-application.ts
File metadata and controls
67 lines (59 loc) · 2.21 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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
import * as Electron from 'electron';
import { AppConstructorOptions, Application } from 'spectron';
import { retry } from 'tests/common/retry';
import {
DEFAULT_APP_CONNECT_RETRIES,
DEFAULT_APP_CONNECT_TIMEOUT_MS,
DEFAULT_CHROMEDRIVER_START_RETRIES,
DEFAULT_CHROMEDRIVER_START_TIMEOUT_MS,
} from 'tests/electron/setup/timeouts';
import { AppController } from './view-controllers/app-controller';
export interface AppOptions extends Partial<AppConstructorOptions> {
suppressFirstTimeDialog: boolean;
}
export async function createApplication(options?: AppOptions): Promise<AppController> {
const targetApp = `${
(global as any).rootDir
}/drop/electron/unified-dev/product/bundle/main.bundle.js`;
const unifiedOptions = {
env: {
ANDROID_HOME: `${(global as any).rootDir}/drop/mock-adb`,
},
...options,
};
const appController = await createAppController(targetApp, unifiedOptions);
if (options?.suppressFirstTimeDialog === true) {
await appController.setTelemetryState(false);
}
return appController;
}
export async function createAppController(
targetApp: string,
overrideSpectronOptions?: Partial<AppConstructorOptions>,
): Promise<AppController> {
const app = await retry(
async () => {
const app = new Application({
path: Electron as any,
args: [targetApp],
connectionRetryCount: DEFAULT_APP_CONNECT_RETRIES,
connectionRetryTimeout: DEFAULT_APP_CONNECT_TIMEOUT_MS,
startTimeout: DEFAULT_CHROMEDRIVER_START_TIMEOUT_MS,
...overrideSpectronOptions,
});
await app.start();
return app;
},
{
operationLabel: 'app.start',
warnOnRetry: true,
maxRetries: DEFAULT_CHROMEDRIVER_START_RETRIES,
retryOnlyIfMatches: err =>
err?.message?.includes('ChromeDriver did not start within') ||
err?.message?.includes('Failed to create session.\nread ECONNRESET'),
},
);
return new AppController(app);
}