smoke - better exit application handling

This commit is contained in:
Benjamin Pasero 2021-08-05 09:05:17 +02:00
parent 801bbff282
commit 6c3bb99c63
No known key found for this signature in database
GPG key ID: E6380CC4C8219E65
5 changed files with 17 additions and 9 deletions

View file

@ -42,7 +42,7 @@ export interface IDriver {
getWindowIds(): Promise<number[]>;
capturePage(windowId: number): Promise<string>;
reloadWindow(windowId: number): Promise<void>;
exitApplication(): Promise<void>;
exitApplication(): Promise<boolean>;
dispatchKeybinding(windowId: number, keybinding: string): Promise<void>;
click(windowId: number, selector: string, xoffset?: number | undefined, yoffset?: number | undefined): Promise<void>;
doubleClick(windowId: number, selector: string): Promise<void>;

View file

@ -20,7 +20,6 @@ import { KeybindingParser } from 'vs/base/common/keybindingParser';
import { timeout } from 'vs/base/common/async';
import { IDriver, IDriverOptions, IElement, ILocaleInfo, ILocalizedStrings, IWindowDriver, IWindowDriverRegistry } from 'vs/platform/driver/common/driver';
import { ILifecycleMainService } from 'vs/platform/lifecycle/electron-main/lifecycleMainService';
import { INativeHostMainService } from 'vs/platform/native/electron-main/nativeHostMainService';
function isSilentKeyCode(keyCode: KeyCode) {
return keyCode < KeyCode.KEY_0;
@ -38,8 +37,7 @@ export class Driver implements IDriver, IWindowDriverRegistry {
private windowServer: IPCServer,
private options: IDriverOptions,
@IWindowsMainService private readonly windowsMainService: IWindowsMainService,
@ILifecycleMainService private readonly lifecycleMainService: ILifecycleMainService,
@INativeHostMainService private readonly nativeHostMainService: INativeHostMainService
@ILifecycleMainService private readonly lifecycleMainService: ILifecycleMainService
) { }
async registerWindowDriver(windowId: number): Promise<IDriverOptions> {
@ -82,8 +80,8 @@ export class Driver implements IDriver, IWindowDriverRegistry {
this.lifecycleMainService.reload(window);
}
async exitApplication(): Promise<void> {
return this.nativeHostMainService.quit(undefined);
exitApplication(): Promise<boolean> {
return this.lifecycleMainService.quit();
}
async dispatchKeybinding(windowId: number, keybinding: string): Promise<void> {

View file

@ -60,7 +60,7 @@ export class DriverChannelClient implements IDriver {
return this.channel.call('reloadWindow', windowId);
}
exitApplication(): Promise<void> {
exitApplication(): Promise<boolean> {
return this.channel.call('exitApplication');
}

View file

@ -294,7 +294,10 @@ export class Code {
}
async exit(): Promise<void> {
await this.driver.exitApplication();
const success = await this.driver.exitApplication();
if (success === false) {
throw new Error('Code exit was blocked by a veto.');
}
}
async waitForTextContent(selector: string, textContent?: string, accept?: (result: string) => boolean, retryCount?: number): Promise<string> {

View file

@ -50,6 +50,8 @@ function buildDriver(browser: playwright.Browser, context: playwright.BrowserCon
console.error(error); // do not fail the build when this fails
}
await teardown();
return true;
},
dispatchKeybinding: async (windowId, keybinding) => {
const chords = keybinding.split(' ');
@ -202,7 +204,12 @@ export function connect(options: Options = {}): Promise<{ client: IDisposable, d
const payloadParam = `[["enableProposedApi",""],["skipWelcome","true"]]`;
await page.goto(`${endpoint}&folder=vscode-remote://localhost:9888${URI.file(workspacePath!).path}&payload=${payloadParam}`);
const result = {
client: { dispose: () => browser.close() && teardown() },
client: {
dispose: () => {
browser.close();
teardown();
}
},
driver: buildDriver(browser, context, page)
};
c(result);