From 18fc98ff550bcd8f1f81066c33d99db4a5d36c35 Mon Sep 17 00:00:00 2001 From: shati-patel <42641846+shati-patel@users.noreply.github.com> Date: Fri, 14 May 2021 18:03:33 +0100 Subject: [PATCH 1/5] Specify custom directory for storing query server logs --- extensions/ql-vscode/package.json | 8 ++++++ extensions/ql-vscode/src/config.ts | 8 +++++- extensions/ql-vscode/src/extension.ts | 6 ++--- extensions/ql-vscode/src/logging.ts | 20 +++++++++----- .../ql-vscode/src/queryserver-client.ts | 26 ++++++++++++++++--- 5 files changed, 55 insertions(+), 13 deletions(-) diff --git a/extensions/ql-vscode/package.json b/extensions/ql-vscode/package.json index 89173e82546..956bee20562 100644 --- a/extensions/ql-vscode/package.json +++ b/extensions/ql-vscode/package.json @@ -179,6 +179,14 @@ "default": 20, "description": "Max number of simultaneous queries to run using the 'CodeQL: Run Queries' command." }, + "codeQL.runningQueries.customLogDirectory": { + "type": [ + "string", + null + ], + "default": null, + "description": "Path to a directory where the CodeQL extension should store query server logs. If empty, the extension stores logs in a temporary workspace folder and deletes the contents after each run." + }, "codeQL.resultsDisplay.pageSize": { "type": "integer", "default": 200, diff --git a/extensions/ql-vscode/src/config.ts b/extensions/ql-vscode/src/config.ts index 9621a9c7265..21f80942180 100644 --- a/extensions/ql-vscode/src/config.ts +++ b/extensions/ql-vscode/src/config.ts @@ -87,9 +87,10 @@ export const NUMBER_OF_TEST_THREADS_SETTING = new Setting('numberOfThreads', RUN export const MAX_QUERIES = new Setting('maxQueries', RUNNING_QUERIES_SETTING); export const AUTOSAVE_SETTING = new Setting('autoSave', RUNNING_QUERIES_SETTING); export const PAGE_SIZE = new Setting('pageSize', RESULTS_DISPLAY_SETTING); +const CUSTOM_LOG_DIRECTORY_SETTING = new Setting('customLogDirectory', RUNNING_QUERIES_SETTING); /** When these settings change, the running query server should be restarted. */ -const QUERY_SERVER_RESTARTING_SETTINGS = [NUMBER_OF_THREADS_SETTING, SAVE_CACHE_SETTING, CACHE_SIZE_SETTING, MEMORY_SETTING, DEBUG_SETTING]; +const QUERY_SERVER_RESTARTING_SETTINGS = [NUMBER_OF_THREADS_SETTING, SAVE_CACHE_SETTING, CACHE_SIZE_SETTING, MEMORY_SETTING, DEBUG_SETTING, CUSTOM_LOG_DIRECTORY_SETTING]; export interface QueryServerConfig { codeQlPath: string; @@ -99,6 +100,7 @@ export interface QueryServerConfig { cacheSize: number; queryMemoryMb?: number; timeoutSecs: number; + customLogDirectory?: string; onDidChangeConfiguration?: Event; } @@ -197,6 +199,10 @@ export class QueryServerConfigListener extends ConfigListener implements QuerySe return this._codeQlPath; } + public get customLogDirectory(): string | undefined { + return CUSTOM_LOG_DIRECTORY_SETTING.getValue() || undefined; + } + public get numThreads(): number { return NUMBER_OF_THREADS_SETTING.getValue(); } diff --git a/extensions/ql-vscode/src/extension.ts b/extensions/ql-vscode/src/extension.ts index 1dcbf1b4dcf..bb9bb4129cd 100644 --- a/extensions/ql-vscode/src/extension.ts +++ b/extensions/ql-vscode/src/extension.ts @@ -380,6 +380,7 @@ async function activateWithInstalledDistribution( cliServer, { logger: queryServerLogger, + contextStoragePath: getContextStoragePath(ctx), }, (task) => Window.withProgress( @@ -768,9 +769,8 @@ function getContextStoragePath(ctx: ExtensionContext) { function initializeLogging(ctx: ExtensionContext): void { const storagePath = getContextStoragePath(ctx); - logger.init(storagePath); - queryServerLogger.init(storagePath); - ideServerLogger.init(storagePath); + logger.setLogStoragePath(storagePath, false); + ideServerLogger.setLogStoragePath(storagePath, false); ctx.subscriptions.push(logger); ctx.subscriptions.push(queryServerLogger); ctx.subscriptions.push(ideServerLogger); diff --git a/extensions/ql-vscode/src/logging.ts b/extensions/ql-vscode/src/logging.ts index 043fb3501f9..b39a6a90763 100644 --- a/extensions/ql-vscode/src/logging.ts +++ b/extensions/ql-vscode/src/logging.ts @@ -40,18 +40,24 @@ export class OutputChannelLogger extends DisposableObject implements Logger { public readonly outputChannel: OutputChannel; private readonly additionalLocations = new Map(); private additionalLogLocationPath: string | undefined; + isCustomLogDirectory: boolean; constructor(private title: string) { super(); this.outputChannel = Window.createOutputChannel(title); this.push(this.outputChannel); + this.isCustomLogDirectory = false; } - init(storagePath: string): void { + setLogStoragePath(storagePath: string, isCustomLogDirectory: boolean): void { this.additionalLogLocationPath = path.join(storagePath, this.title); - // clear out any old state from previous runs - fs.remove(this.additionalLogLocationPath); + this.isCustomLogDirectory = isCustomLogDirectory; + + if (!this.isCustomLogDirectory) { + // clear out any old state from previous runs + fs.remove(this.additionalLogLocationPath); + } } /** @@ -80,7 +86,7 @@ export class OutputChannelLogger extends DisposableObject implements Logger { this.outputChannel.appendLine(separator); this.outputChannel.appendLine(msg); this.outputChannel.appendLine(separator); - additional = new AdditionalLogLocation(logPath); + additional = new AdditionalLogLocation(logPath, !this.isCustomLogDirectory); this.additionalLocations.set(logPath, additional); this.track(additional); } @@ -112,7 +118,7 @@ export class OutputChannelLogger extends DisposableObject implements Logger { } class AdditionalLogLocation extends Disposable { - constructor(private location: string) { + constructor(private location: string, private shouldDeleteLogs: boolean) { super(() => { /**/ }); } @@ -128,7 +134,9 @@ class AdditionalLogLocation extends Disposable { } async dispose(): Promise { - await fs.remove(this.location); + if (this.shouldDeleteLogs) { + await fs.remove(this.location); + } } } diff --git a/extensions/ql-vscode/src/queryserver-client.ts b/extensions/ql-vscode/src/queryserver-client.ts index 297315d4414..7e6c9fa8bb9 100644 --- a/extensions/ql-vscode/src/queryserver-client.ts +++ b/extensions/ql-vscode/src/queryserver-client.ts @@ -5,13 +5,16 @@ import { Disposable, CancellationToken, commands } from 'vscode'; import { createMessageConnection, MessageConnection, RequestType } from 'vscode-jsonrpc'; import * as cli from './cli'; import { QueryServerConfig } from './config'; -import { Logger, ProgressReporter } from './logging'; +import { Logger, ProgressReporter, queryServerLogger } from './logging'; import { completeQuery, EvaluationResult, progress, ProgressMessage, WithProgressId } from './pure/messages'; import * as messages from './pure/messages'; import { ProgressCallback, ProgressTask } from './commandRunner'; +import * as fs from 'fs-extra'; +import * as helpers from './helpers'; type ServerOpts = { logger: Logger; + contextStoragePath: string; } /** A running query server process and its associated message connection. */ @@ -86,8 +89,24 @@ export class QueryServerClient extends DisposableObject { this.evaluationResultCallbacks = {}; } + initLogger() { + let storagePath = this.opts.contextStoragePath; + let isCustomLogDirectory = false; + if (this.config.customLogDirectory) { + if (fs.existsSync(this.config.customLogDirectory) && fs.statSync(this.config.customLogDirectory).isDirectory()) { + storagePath = this.config.customLogDirectory; + isCustomLogDirectory = true; + } else if (this.config.customLogDirectory) { + helpers.showAndLogErrorMessage(`${this.config.customLogDirectory} is not a valid directory. Logs will be stored in a temporary workspace directory instead.`); + } + } + + queryServerLogger.setLogStoragePath(storagePath, isCustomLogDirectory); + + } + get logger(): Logger { - return this.opts.logger; + return queryServerLogger; } /** Stops the query server by disposing of the current server process. */ @@ -151,6 +170,7 @@ export class QueryServerClient extends DisposableObject { args.push('-J=-agentlib:jdwp=transport=dt_socket,address=localhost:9010,server=y,suspend=n,quiet=y'); } + this.initLogger(); const child = cli.spawnServer( this.config.codeQlPath, 'CodeQL query server', @@ -185,7 +205,7 @@ export class QueryServerClient extends DisposableObject { callback(res); } }); - this.serverProcess = new ServerProcess(child, connection, this.opts.logger); + this.serverProcess = new ServerProcess(child, connection, this.logger); // Ensure the server process is disposed together with this client. this.track(this.serverProcess); connection.listen(); From 25a696569b16ef06b84b74ca255ded042ede918c Mon Sep 17 00:00:00 2001 From: shati-patel <42641846+shati-patel@users.noreply.github.com> Date: Thu, 20 May 2021 22:38:31 +0100 Subject: [PATCH 2/5] Create custom log directory, if possible (I haven't got the error handling to work asynchronously, so I stuck with `mkdirSync` for now) --- extensions/ql-vscode/src/queryserver-client.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/extensions/ql-vscode/src/queryserver-client.ts b/extensions/ql-vscode/src/queryserver-client.ts index 7e6c9fa8bb9..25a4e2ef33b 100644 --- a/extensions/ql-vscode/src/queryserver-client.ts +++ b/extensions/ql-vscode/src/queryserver-client.ts @@ -93,10 +93,12 @@ export class QueryServerClient extends DisposableObject { let storagePath = this.opts.contextStoragePath; let isCustomLogDirectory = false; if (this.config.customLogDirectory) { - if (fs.existsSync(this.config.customLogDirectory) && fs.statSync(this.config.customLogDirectory).isDirectory()) { + try { + fs.mkdirSync(this.config.customLogDirectory); + helpers.showAndLogInformationMessage(`Storing query server logs to user-specified directory: ${this.config.customLogDirectory}.`); storagePath = this.config.customLogDirectory; isCustomLogDirectory = true; - } else if (this.config.customLogDirectory) { + } catch (e) { helpers.showAndLogErrorMessage(`${this.config.customLogDirectory} is not a valid directory. Logs will be stored in a temporary workspace directory instead.`); } } From ad0fb754362ad416ad8f6e1bf95f805377534e23 Mon Sep 17 00:00:00 2001 From: shati-patel <42641846+shati-patel@users.noreply.github.com> Date: Fri, 21 May 2021 15:48:15 +0100 Subject: [PATCH 3/5] Update tests --- .../ql-vscode/test/pure-tests/logging.test.ts | 52 ++++++++++++++++--- 1 file changed, 46 insertions(+), 6 deletions(-) diff --git a/extensions/ql-vscode/test/pure-tests/logging.test.ts b/extensions/ql-vscode/test/pure-tests/logging.test.ts index f8439a803dd..103c8fecda6 100644 --- a/extensions/ql-vscode/test/pure-tests/logging.test.ts +++ b/extensions/ql-vscode/test/pure-tests/logging.test.ts @@ -48,7 +48,7 @@ describe('OutputChannelLogger tests', () => { }); it('should create a side log in the workspace area', async () => { - logger.init(tempFolders.storagePath.name); + logger.setLogStoragePath(tempFolders.storagePath.name, false); await logger.log('xxx', { additionalLogLocation: 'first' }); await logger.log('yyy', { additionalLogLocation: 'second' }); @@ -65,7 +65,7 @@ describe('OutputChannelLogger tests', () => { }); it('should delete side logs on dispose', async () => { - logger.init(tempFolders.storagePath.name); + logger.setLogStoragePath(tempFolders.storagePath.name, false); await logger.log('xxx', { additionalLogLocation: 'first' }); await logger.log('yyy', { additionalLogLocation: 'second' }); @@ -79,8 +79,23 @@ describe('OutputChannelLogger tests', () => { expect(mockOutputChannel.dispose).to.have.been.calledWith(); }); + it('should not delete side logs on dispose in a custom directory', async () => { + logger.setLogStoragePath(tempFolders.storagePath.name, true); + await logger.log('xxx', { additionalLogLocation: 'first' }); + await logger.log('yyy', { additionalLogLocation: 'second' }); + + const testLoggerFolder = path.join(tempFolders.storagePath.name, 'test-logger'); + expect(fs.readdirSync(testLoggerFolder).length).to.equal(2); + + await logger.dispose(); + // need to wait for disposable-object to dispose + await waitABit(); + expect(fs.readdirSync(testLoggerFolder).length).to.equal(2); + expect(mockOutputChannel.dispose).to.have.been.calledWith(); + }); + it('should remove an additional log location', async () => { - logger.init(tempFolders.storagePath.name); + logger.setLogStoragePath(tempFolders.storagePath.name, false); await logger.log('xxx', { additionalLogLocation: 'first' }); await logger.log('yyy', { additionalLogLocation: 'second' }); @@ -94,11 +109,36 @@ describe('OutputChannelLogger tests', () => { expect(fs.readFileSync(path.join(testLoggerFolder, 'second'), 'utf8')).to.equal('yyy\n'); }); - it('should delete an existing folder on init', async () => { + it('should not remove an additional log location in a custom directory', async () => { + logger.setLogStoragePath(tempFolders.storagePath.name, true); + await logger.log('xxx', { additionalLogLocation: 'first' }); + await logger.log('yyy', { additionalLogLocation: 'second' }); + + const testLoggerFolder = path.join(tempFolders.storagePath.name, 'test-logger'); + expect(fs.readdirSync(testLoggerFolder).length).to.equal(2); + + await logger.removeAdditionalLogLocation('first'); + // need to wait for disposable-object to dispose + await waitABit(); + expect(fs.readdirSync(testLoggerFolder).length).to.equal(2); + expect(fs.readFileSync(path.join(testLoggerFolder, 'second'), 'utf8')).to.equal('yyy\n'); + }); + + it('should delete an existing folder when setting the log storage path', async () => { fs.createFileSync(path.join(tempFolders.storagePath.name, 'test-logger', 'xxx')); - logger.init(tempFolders.storagePath.name); + logger.setLogStoragePath(tempFolders.storagePath.name, false); // should be empty dir + const testLoggerFolder = path.join(tempFolders.storagePath.name, 'test-logger'); + // TODO: Why does this test pass? I'd expect the length to be 0 if it's correctly deleted the existing folder. + expect(fs.readdirSync(testLoggerFolder).length).to.equal(1); + }); + + it('should not delete an existing folder when setting the log storage path for a custom directory', async () => { + fs.createFileSync(path.join(tempFolders.storagePath.name, 'test-logger', 'xxx')); + logger.setLogStoragePath(tempFolders.storagePath.name, true); + // should not be empty dir + const testLoggerFolder = path.join(tempFolders.storagePath.name, 'test-logger'); expect(fs.readdirSync(testLoggerFolder).length).to.equal(1); }); @@ -130,7 +170,7 @@ describe('OutputChannelLogger tests', () => { }); } - function waitABit(ms = 50): Promise { + function waitABit(ms = 50): Promise { return new Promise(resolve => setTimeout(resolve, ms)); } }); From 0c03195ecc9030529bc64f618fc021ad28853627 Mon Sep 17 00:00:00 2001 From: shati-patel <42641846+shati-patel@users.noreply.github.com> Date: Fri, 21 May 2021 15:58:49 +0100 Subject: [PATCH 4/5] Add changelog note --- extensions/ql-vscode/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/extensions/ql-vscode/CHANGELOG.md b/extensions/ql-vscode/CHANGELOG.md index 164f19ca239..1c6b6c0246e 100644 --- a/extensions/ql-vscode/CHANGELOG.md +++ b/extensions/ql-vscode/CHANGELOG.md @@ -5,6 +5,7 @@ - Display CodeQL CLI version being downloaded during an upgrade. [#862](https://github.com/github/vscode-codeql/pull/862) - Display a helpful message and link to documentation when a query produces no results. [#866](https://github.com/github/vscode-codeql/pull/866) - Refresh test databases automatically after a test run. [#868](https://github.com/github/vscode-codeql/pull/868) +- Allow users to specify a custom directory for storing query server logs (`codeQL.runningQueries.customLogDirectory`). The extension will not delete these logs automatically. [#863](https://github.com/github/vscode-codeql/pull/863) ## 1.4.8 - 05 May 2021 From 43fba352700e00fc43b1ed7dff56510ad7d7efca Mon Sep 17 00:00:00 2001 From: shati-patel <42641846+shati-patel@users.noreply.github.com> Date: Fri, 21 May 2021 20:01:43 +0100 Subject: [PATCH 5/5] Make functions async + other review comments --- extensions/ql-vscode/src/extension.ts | 8 ++++---- extensions/ql-vscode/src/logging.ts | 13 ++++++++++--- extensions/ql-vscode/src/queryserver-client.ts | 16 +++++++++------- .../ql-vscode/test/pure-tests/logging.test.ts | 18 +++++++++--------- 4 files changed, 32 insertions(+), 23 deletions(-) diff --git a/extensions/ql-vscode/src/extension.ts b/extensions/ql-vscode/src/extension.ts index bb9bb4129cd..81335ea6a2b 100644 --- a/extensions/ql-vscode/src/extension.ts +++ b/extensions/ql-vscode/src/extension.ts @@ -155,7 +155,7 @@ export async function activate(ctx: ExtensionContext): Promise { const storagePath = getContextStoragePath(ctx); - logger.setLogStoragePath(storagePath, false); - ideServerLogger.setLogStoragePath(storagePath, false); + await logger.setLogStoragePath(storagePath, false); + await ideServerLogger.setLogStoragePath(storagePath, false); ctx.subscriptions.push(logger); ctx.subscriptions.push(queryServerLogger); ctx.subscriptions.push(ideServerLogger); diff --git a/extensions/ql-vscode/src/logging.ts b/extensions/ql-vscode/src/logging.ts index b39a6a90763..c1b31bfc3a5 100644 --- a/extensions/ql-vscode/src/logging.ts +++ b/extensions/ql-vscode/src/logging.ts @@ -28,9 +28,16 @@ export interface Logger { removeAdditionalLogLocation(location: string | undefined): void; /** - * The base location location where all side log files are stored. + * The base location where all side log files are stored. */ getBaseLocation(): string | undefined; + + /** + * Sets the location where logs are stored. + * @param storagePath The path where logs are stored. + * @param isCustomLogDirectory Whether the logs are stored in a custom, user-specified directory. + */ + setLogStoragePath(storagePath: string, isCustomLogDirectory: boolean): Promise; } export type ProgressReporter = Progress<{ message: string }>; @@ -49,14 +56,14 @@ export class OutputChannelLogger extends DisposableObject implements Logger { this.isCustomLogDirectory = false; } - setLogStoragePath(storagePath: string, isCustomLogDirectory: boolean): void { + async setLogStoragePath(storagePath: string, isCustomLogDirectory: boolean): Promise { this.additionalLogLocationPath = path.join(storagePath, this.title); this.isCustomLogDirectory = isCustomLogDirectory; if (!this.isCustomLogDirectory) { // clear out any old state from previous runs - fs.remove(this.additionalLogLocationPath); + await fs.remove(this.additionalLogLocationPath); } } diff --git a/extensions/ql-vscode/src/queryserver-client.ts b/extensions/ql-vscode/src/queryserver-client.ts index 25a4e2ef33b..e27dfc38c78 100644 --- a/extensions/ql-vscode/src/queryserver-client.ts +++ b/extensions/ql-vscode/src/queryserver-client.ts @@ -5,7 +5,7 @@ import { Disposable, CancellationToken, commands } from 'vscode'; import { createMessageConnection, MessageConnection, RequestType } from 'vscode-jsonrpc'; import * as cli from './cli'; import { QueryServerConfig } from './config'; -import { Logger, ProgressReporter, queryServerLogger } from './logging'; +import { Logger, ProgressReporter } from './logging'; import { completeQuery, EvaluationResult, progress, ProgressMessage, WithProgressId } from './pure/messages'; import * as messages from './pure/messages'; import { ProgressCallback, ProgressTask } from './commandRunner'; @@ -89,13 +89,15 @@ export class QueryServerClient extends DisposableObject { this.evaluationResultCallbacks = {}; } - initLogger() { + async initLogger() { let storagePath = this.opts.contextStoragePath; let isCustomLogDirectory = false; if (this.config.customLogDirectory) { try { - fs.mkdirSync(this.config.customLogDirectory); - helpers.showAndLogInformationMessage(`Storing query server logs to user-specified directory: ${this.config.customLogDirectory}.`); + if (!(await fs.pathExists(this.config.customLogDirectory))) { + await fs.mkdir(this.config.customLogDirectory); + } + this.logger.log(`Saving query server logs to user-specified directory: ${this.config.customLogDirectory}.`); storagePath = this.config.customLogDirectory; isCustomLogDirectory = true; } catch (e) { @@ -103,12 +105,12 @@ export class QueryServerClient extends DisposableObject { } } - queryServerLogger.setLogStoragePath(storagePath, isCustomLogDirectory); + await this.logger.setLogStoragePath(storagePath, isCustomLogDirectory); } get logger(): Logger { - return queryServerLogger; + return this.opts.logger; } /** Stops the query server by disposing of the current server process. */ @@ -148,6 +150,7 @@ export class QueryServerClient extends DisposableObject { /** Starts a new query server process, sending progress messages to the given reporter. */ private async startQueryServerImpl(progressReporter: ProgressReporter): Promise { + await this.initLogger(); const ramArgs = await this.cliServer.resolveRam(this.config.queryMemoryMb, progressReporter); const args = ['--threads', this.config.numThreads.toString()].concat(ramArgs); @@ -172,7 +175,6 @@ export class QueryServerClient extends DisposableObject { args.push('-J=-agentlib:jdwp=transport=dt_socket,address=localhost:9010,server=y,suspend=n,quiet=y'); } - this.initLogger(); const child = cli.spawnServer( this.config.codeQlPath, 'CodeQL query server', diff --git a/extensions/ql-vscode/test/pure-tests/logging.test.ts b/extensions/ql-vscode/test/pure-tests/logging.test.ts index 103c8fecda6..ef4f4fca281 100644 --- a/extensions/ql-vscode/test/pure-tests/logging.test.ts +++ b/extensions/ql-vscode/test/pure-tests/logging.test.ts @@ -48,7 +48,7 @@ describe('OutputChannelLogger tests', () => { }); it('should create a side log in the workspace area', async () => { - logger.setLogStoragePath(tempFolders.storagePath.name, false); + await logger.setLogStoragePath(tempFolders.storagePath.name, false); await logger.log('xxx', { additionalLogLocation: 'first' }); await logger.log('yyy', { additionalLogLocation: 'second' }); @@ -65,7 +65,7 @@ describe('OutputChannelLogger tests', () => { }); it('should delete side logs on dispose', async () => { - logger.setLogStoragePath(tempFolders.storagePath.name, false); + await logger.setLogStoragePath(tempFolders.storagePath.name, false); await logger.log('xxx', { additionalLogLocation: 'first' }); await logger.log('yyy', { additionalLogLocation: 'second' }); @@ -80,7 +80,7 @@ describe('OutputChannelLogger tests', () => { }); it('should not delete side logs on dispose in a custom directory', async () => { - logger.setLogStoragePath(tempFolders.storagePath.name, true); + await logger.setLogStoragePath(tempFolders.storagePath.name, true); await logger.log('xxx', { additionalLogLocation: 'first' }); await logger.log('yyy', { additionalLogLocation: 'second' }); @@ -95,7 +95,7 @@ describe('OutputChannelLogger tests', () => { }); it('should remove an additional log location', async () => { - logger.setLogStoragePath(tempFolders.storagePath.name, false); + await logger.setLogStoragePath(tempFolders.storagePath.name, false); await logger.log('xxx', { additionalLogLocation: 'first' }); await logger.log('yyy', { additionalLogLocation: 'second' }); @@ -110,7 +110,7 @@ describe('OutputChannelLogger tests', () => { }); it('should not remove an additional log location in a custom directory', async () => { - logger.setLogStoragePath(tempFolders.storagePath.name, true); + await logger.setLogStoragePath(tempFolders.storagePath.name, true); await logger.log('xxx', { additionalLogLocation: 'first' }); await logger.log('yyy', { additionalLogLocation: 'second' }); @@ -126,17 +126,17 @@ describe('OutputChannelLogger tests', () => { it('should delete an existing folder when setting the log storage path', async () => { fs.createFileSync(path.join(tempFolders.storagePath.name, 'test-logger', 'xxx')); - logger.setLogStoragePath(tempFolders.storagePath.name, false); + await logger.setLogStoragePath(tempFolders.storagePath.name, false); // should be empty dir + await waitABit(); const testLoggerFolder = path.join(tempFolders.storagePath.name, 'test-logger'); - // TODO: Why does this test pass? I'd expect the length to be 0 if it's correctly deleted the existing folder. - expect(fs.readdirSync(testLoggerFolder).length).to.equal(1); + expect(fs.existsSync(testLoggerFolder)).to.be.false; }); it('should not delete an existing folder when setting the log storage path for a custom directory', async () => { fs.createFileSync(path.join(tempFolders.storagePath.name, 'test-logger', 'xxx')); - logger.setLogStoragePath(tempFolders.storagePath.name, true); + await logger.setLogStoragePath(tempFolders.storagePath.name, true); // should not be empty dir const testLoggerFolder = path.join(tempFolders.storagePath.name, 'test-logger');