From 1894181c08b221b744a4d14c77195e2c0b94e78b Mon Sep 17 00:00:00 2001 From: Benjamin Pasero Date: Fri, 5 May 2023 07:02:40 +0200 Subject: [PATCH] logs - make sure to attach all logs in browser tests (#181578) * logs - make sure to attach all logs in browser tests * separate server logs into `server` folder --- src/vs/platform/driver/common/driver.ts | 2 +- src/vs/platform/log/browser/log.ts | 35 +++++++++++++++--------- test/automation/src/playwrightBrowser.ts | 5 ++-- test/automation/src/playwrightDriver.ts | 2 +- test/integration/browser/src/index.ts | 9 +++--- 5 files changed, 32 insertions(+), 21 deletions(-) diff --git a/src/vs/platform/driver/common/driver.ts b/src/vs/platform/driver/common/driver.ts index 49f076ef786..6fae57d5f52 100644 --- a/src/vs/platform/driver/common/driver.ts +++ b/src/vs/platform/driver/common/driver.ts @@ -28,7 +28,7 @@ export interface ILocalizedStrings { } export interface ILogFile { - readonly name: string; + readonly relativePath: string; readonly contents: string; } diff --git a/src/vs/platform/log/browser/log.ts b/src/vs/platform/log/browser/log.ts index 42e4b34dc64..d54c0b5f1fe 100644 --- a/src/vs/platform/log/browser/log.ts +++ b/src/vs/platform/log/browser/log.ts @@ -3,6 +3,8 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ +import { relativePath } from 'vs/base/common/resources'; +import { URI } from 'vs/base/common/uri'; import { IEnvironmentService } from 'vs/platform/environment/common/environment'; import { IFileService } from 'vs/platform/files/common/files'; import { AdapterLogger, DEFAULT_LOG_LEVEL, ILogger, LogLevel } from 'vs/platform/log/common/log'; @@ -13,7 +15,7 @@ export interface IAutomatedWindow { } export interface ILogFile { - readonly name: string; + readonly relativePath: string; readonly contents: string; } @@ -25,22 +27,29 @@ export interface ILogFile { export async function getLogs(fileService: IFileService, environmentService: IEnvironmentService): Promise { const result: ILogFile[] = []; - const logs = await fileService.resolve(environmentService.logsHome); - - for (const { name, isDirectory, resource } of logs.children || []) { - if (isDirectory) { - continue; - } - - const contents = (await fileService.readFile(resource)).value.toString(); - if (contents) { - result.push({ name, contents }); - } - } + await doGetLogs(fileService, result, environmentService.logsHome, environmentService.logsHome); return result; } +async function doGetLogs(fileService: IFileService, logs: ILogFile[], curFolder: URI, logsHome: URI): Promise { + const stat = await fileService.resolve(curFolder); + + for (const { resource, isDirectory } of stat.children || []) { + if (isDirectory) { + await doGetLogs(fileService, logs, resource, logsHome); + } else { + const contents = (await fileService.readFile(resource)).value.toString(); + if (contents) { + const path = relativePath(logsHome, resource); + if (path) { + logs.push({ relativePath: path, contents }); + } + } + } + } +} + function logLevelToString(level: LogLevel): string { switch (level) { case LogLevel.Trace: return 'trace'; diff --git a/test/automation/src/playwrightBrowser.ts b/test/automation/src/playwrightBrowser.ts index 7d35ba9517a..7223c49a13b 100644 --- a/test/automation/src/playwrightBrowser.ts +++ b/test/automation/src/playwrightBrowser.ts @@ -32,6 +32,7 @@ export async function launch(options: LaunchOptions): Promise<{ serverProcess: C async function launchServer(options: LaunchOptions) { const { userDataDir, codePath, extensionsPath, logger, logsPath } = options; + const serverLogsPath = join(logsPath, 'server'); const codeServerPath = codePath ?? process.env.VSCODE_REMOTE_SERVER_PATH; const agentFolder = userDataDir; await measureAndLog(() => mkdirp(agentFolder), `mkdirp(${agentFolder})`, logger); @@ -49,7 +50,7 @@ async function launchServer(options: LaunchOptions) { `--extensions-dir=${extensionsPath}`, `--server-data-dir=${agentFolder}`, '--accept-server-license-terms', - `--logsPath=${logsPath}` + `--logsPath=${serverLogsPath}` ]; if (options.verbose) { @@ -68,7 +69,7 @@ async function launchServer(options: LaunchOptions) { logger.log(`Starting server out of sources from '${serverLocation}'`); } - logger.log(`Storing log files into '${logsPath}'`); + logger.log(`Storing log files into '${serverLogsPath}'`); logger.log(`Command line: '${serverLocation}' ${args.join(' ')}`); const serverProcess = spawn( diff --git a/test/automation/src/playwrightDriver.ts b/test/automation/src/playwrightDriver.ts index 4ab495bef30..1b63f622f4e 100644 --- a/test/automation/src/playwrightDriver.ts +++ b/test/automation/src/playwrightDriver.ts @@ -145,7 +145,7 @@ export class PlaywrightDriver { const logs = await this.getLogs(); for (const log of logs) { - const absoluteLogsPath = join(this.options.logsPath, log.name); + const absoluteLogsPath = join(this.options.logsPath, log.relativePath); await promises.mkdir(dirname(absoluteLogsPath), { recursive: true }); await promises.writeFile(absoluteLogsPath, log.contents); diff --git a/test/integration/browser/src/index.ts b/test/integration/browser/src/index.ts index 311a3465382..f82a69b3430 100644 --- a/test/integration/browser/src/index.ts +++ b/test/integration/browser/src/index.ts @@ -67,10 +67,10 @@ async function runTestsInBrowser(browserType: BrowserType, endpoint: url.UrlWith console[type](...args); }); - await page.exposeFunction('codeAutomationExit', async (logs: Array<{ readonly name: string; readonly contents: string }>, code: number) => { + await page.exposeFunction('codeAutomationExit', async (logs: Array<{ readonly relativePath: string; readonly contents: string }>, code: number) => { try { for (const log of logs) { - const absoluteLogsPath = path.join(logsPath, log.name); + const absoluteLogsPath = path.join(logsPath, log.relativePath); await promises.mkdir(path.dirname(absoluteLogsPath), { recursive: true }); await promises.writeFile(absoluteLogsPath, log.contents); @@ -157,8 +157,9 @@ async function launchServer(browserType: BrowserType): Promise<{ endpoint: url.U } } - console.log(`Storing log files into '${logsPath}'`); - serverArgs.push('--logsPath', logsPath); + const serverLogsPath = path.join(logsPath, 'server'); + console.log(`Storing log files into '${serverLogsPath}'`); + serverArgs.push('--logsPath', serverLogsPath); const stdio: cp.StdioOptions = optimist.argv.debug ? 'pipe' : ['ignore', 'pipe', 'ignore'];