Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/test/automation/src/application.ts
3520 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import { Workbench } from './workbench';
7
import { Code, launch, LaunchOptions } from './code';
8
import { Logger, measureAndLog } from './logger';
9
import { Profiler } from './profiler';
10
11
export const enum Quality {
12
Dev,
13
Insiders,
14
Stable,
15
Exploration,
16
OSS
17
}
18
19
export interface ApplicationOptions extends LaunchOptions {
20
quality: Quality;
21
}
22
23
export class Application {
24
25
constructor(private options: ApplicationOptions) {
26
this._userDataPath = options.userDataDir;
27
this._workspacePathOrFolder = options.workspacePath;
28
}
29
30
private _code: Code | undefined;
31
get code(): Code { return this._code!; }
32
33
private _workbench: Workbench | undefined;
34
get workbench(): Workbench { return this._workbench!; }
35
36
get quality(): Quality {
37
return this.options.quality;
38
}
39
40
get logger(): Logger {
41
return this.options.logger;
42
}
43
44
get remote(): boolean {
45
return !!this.options.remote;
46
}
47
48
get web(): boolean {
49
return !!this.options.web;
50
}
51
52
private _workspacePathOrFolder: string;
53
get workspacePathOrFolder(): string {
54
return this._workspacePathOrFolder;
55
}
56
57
get extensionsPath(): string | undefined {
58
return this.options.extensionsPath;
59
}
60
61
private _userDataPath: string | undefined;
62
get userDataPath(): string | undefined {
63
return this._userDataPath;
64
}
65
66
private _profiler: Profiler | undefined;
67
68
get profiler(): Profiler { return this._profiler!; }
69
70
async start(): Promise<void> {
71
await this._start();
72
}
73
74
async restart(options?: { workspaceOrFolder?: string; extraArgs?: string[] }): Promise<void> {
75
await measureAndLog(() => (async () => {
76
await this.stop();
77
await this._start(options?.workspaceOrFolder, options?.extraArgs);
78
})(), 'Application#restart()', this.logger);
79
}
80
81
private async _start(workspaceOrFolder = this.workspacePathOrFolder, extraArgs: string[] = []): Promise<void> {
82
this._workspacePathOrFolder = workspaceOrFolder;
83
84
// Launch Code...
85
const code = await this.startApplication(extraArgs);
86
87
// ...and make sure the window is ready to interact
88
await measureAndLog(() => this.checkWindowReady(code), 'Application#checkWindowReady()', this.logger);
89
}
90
91
async stop(): Promise<void> {
92
if (this._code) {
93
try {
94
await this._code.exit();
95
} finally {
96
this._code = undefined;
97
}
98
}
99
}
100
101
async startTracing(name: string): Promise<void> {
102
await this._code?.startTracing(name);
103
}
104
105
async stopTracing(name: string, persist: boolean): Promise<void> {
106
await this._code?.stopTracing(name, persist);
107
}
108
109
private async startApplication(extraArgs: string[] = []): Promise<Code> {
110
const code = this._code = await launch({
111
...this.options,
112
extraArgs: [...(this.options.extraArgs || []), ...extraArgs],
113
});
114
115
this._workbench = new Workbench(this._code);
116
this._profiler = new Profiler(this.code);
117
118
return code;
119
}
120
121
private async checkWindowReady(code: Code): Promise<void> {
122
123
// We need a rendered workbench
124
await measureAndLog(() => code.didFinishLoad(), 'Application#checkWindowReady: wait for navigation to be committed', this.logger);
125
await measureAndLog(() => code.waitForElement('.monaco-workbench'), 'Application#checkWindowReady: wait for .monaco-workbench element', this.logger);
126
await measureAndLog(() => code.whenWorkbenchRestored(), 'Application#checkWorkbenchRestored', this.logger);
127
128
// Remote but not web: wait for a remote connection state change
129
if (this.remote) {
130
await measureAndLog(() => code.waitForTextContent('.monaco-workbench .statusbar-item[id="status.host"]', undefined, statusHostLabel => {
131
this.logger.log(`checkWindowReady: remote indicator text is ${statusHostLabel}`);
132
133
// The absence of "Opening Remote" is not a strict
134
// indicator for a successful connection, but we
135
// want to avoid hanging here until timeout because
136
// this method is potentially called from a location
137
// that has no tracing enabled making it hard to
138
// diagnose this. As such, as soon as the connection
139
// state changes away from the "Opening Remote..." one
140
// we return.
141
return !statusHostLabel.includes('Opening Remote');
142
}, 300 /* = 30s of retry */), 'Application#checkWindowReady: wait for remote indicator', this.logger);
143
}
144
}
145
}
146
147