From b1bc7be9d1c790f17d74f482369307e04da72a4f Mon Sep 17 00:00:00 2001 From: Alexandru Dima Date: Wed, 9 Jun 2021 21:47:18 +0200 Subject: [PATCH] Do not rely on `console.log` for exiting tests --- src/vs/platform/log/browser/log.ts | 5 ++-- .../extensions/browser/extensionService.ts | 9 +++--- test/integration/browser/src/index.ts | 29 +++++++++---------- 3 files changed, 21 insertions(+), 22 deletions(-) diff --git a/src/vs/platform/log/browser/log.ts b/src/vs/platform/log/browser/log.ts index 8fe0f14599d..536c8195d20 100644 --- a/src/vs/platform/log/browser/log.ts +++ b/src/vs/platform/log/browser/log.ts @@ -5,8 +5,9 @@ import { DEFAULT_LOG_LEVEL, LogLevel, AdapterLogger, ILogger } from 'vs/platform/log/common/log'; -interface IAutomatedWindow { +export interface IAutomatedWindow { codeAutomationLog(type: string, args: any[]): void; + codeAutomationExit(code: number): void; } function logLevelToString(level: LogLevel): string { @@ -16,7 +17,7 @@ function logLevelToString(level: LogLevel): string { case LogLevel.Info: return 'info'; case LogLevel.Warning: return 'warn'; case LogLevel.Error: return 'error'; - case LogLevel.Critical: return 'critical'; + case LogLevel.Critical: return 'error'; } return 'info'; } diff --git a/src/vs/workbench/services/extensions/browser/extensionService.ts b/src/vs/workbench/services/extensions/browser/extensionService.ts index 1ab766411c3..5cbfab21495 100644 --- a/src/vs/workbench/services/extensions/browser/extensionService.ts +++ b/src/vs/workbench/services/extensions/browser/extensionService.ts @@ -28,6 +28,7 @@ import { IExtensionManagementService } from 'vs/platform/extensionManagement/com import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace'; import { IExtensionManifestPropertiesService } from 'vs/workbench/services/extensions/common/extensionManifestPropertiesService'; import { IUserDataInitializationService } from 'vs/workbench/services/userData/browser/userDataInit'; +import { IAutomatedWindow } from 'vs/platform/log/browser/log'; export class ExtensionService extends AbstractExtensionService implements IExtensionService { @@ -220,10 +221,10 @@ export class ExtensionService extends AbstractExtensionService implements IExten // Dispose everything associated with the extension host this.stopExtensionHosts(); - // We log the exit code to the console. Do NOT remove this - // code as the automated integration tests in browser rely - // on this message to exit properly. - console.log(`vscode:exit ${code}`); + const automatedWindow = window as unknown as IAutomatedWindow; + if (typeof automatedWindow.codeAutomationExit === 'function') { + automatedWindow.codeAutomationExit(code); + } } } diff --git a/test/integration/browser/src/index.ts b/test/integration/browser/src/index.ts index a9034524657..9c35b9470c2 100644 --- a/test/integration/browser/src/index.ts +++ b/test/integration/browser/src/index.ts @@ -54,23 +54,20 @@ async function runTestsInBrowser(browserType: BrowserType, endpoint: url.UrlWith console[type](...args); }); - page.on('console', async (msg: playwright.ConsoleMessage) => { - const msgText = msg.text(); - if (msgText.indexOf('vscode:exit') >= 0) { - try { - await browser.close(); - } catch (error) { - console.error(`Error when closing browser: ${error}`); - } - - try { - await pkill(server.pid); - } catch (error) { - console.error(`Error when killing server process tree: ${error}`); - } - - process.exit(msgText === 'vscode:exit 0' ? 0 : 1); + await page.exposeFunction('codeAutomationExit', async (code: number) => { + try { + await browser.close(); + } catch (error) { + console.error(`Error when closing browser: ${error}`); } + + try { + await pkill(server.pid); + } catch (error) { + console.error(`Error when killing server process tree: ${error}`); + } + + process.exit(code); }); }