smoke - take screenshot when waiting long for window ready

This commit is contained in:
Benjamin Pasero 2021-12-28 15:32:07 +01:00
parent 23f72a0aa7
commit 9c0cce1dae
No known key found for this signature in database
GPG key ID: E6380CC4C8219E65

View file

@ -21,7 +21,11 @@ export interface ApplicationOptions extends LaunchOptions {
export class Application {
private static INSTANCES = 0;
constructor(private options: ApplicationOptions) {
Application.INSTANCES++;
this._userDataPath = options.userDataDir;
this._workspacePathOrFolder = options.workspacePath;
}
@ -75,8 +79,21 @@ export class Application {
private async _start(workspaceOrFolder = this.workspacePathOrFolder, extraArgs: string[] = []): Promise<any> {
this._workspacePathOrFolder = workspaceOrFolder;
// Launch Code...
const code = await this.startApplication(extraArgs);
await this.checkWindowReady(code);
// ...and make sure the window is ready to interact
const windowReady = this.checkWindowReady(code);
// Make sure to take a screenshot if waiting for window ready
// takes unusually long to help diagnose issues when Code does
// not seem to startup healthy.
const timeoutHandle = setTimeout(() => this.takeScreenshot(`checkWindowReady_instance_${Application.INSTANCES}`), 20000);
try {
await windowReady;
} finally {
clearTimeout(timeoutHandle);
}
}
async stop(): Promise<any> {
@ -97,6 +114,15 @@ export class Application {
await this._code?.stopTracing(name, persist);
}
private async takeScreenshot(name: string): Promise<void> {
if (this.web) {
return; // supported only on desktop
}
// Desktop: call `stopTracing` to take a screenshot
return this._code?.stopTracing(name, true);
}
private async startApplication(extraArgs: string[] = []): Promise<Code> {
const code = this._code = await launch({
...this.options,