From c7a1231006caa8fb213c2a75f7e3198c42054a45 Mon Sep 17 00:00:00 2001 From: nkomonen Date: Mon, 5 Feb 2024 15:40:20 -0500 Subject: [PATCH] fix: flaky fs test Reported by #4390, this test is failing on the mkdirSpy call count assertion. Not exactly sure why this is flaky, but maybe it is due to the previous folders not being cleaned up. This commit deletes the created folders after each test finishes. Additionally, this commit checks the actual spy call count so that we can better debug the issue Signed-off-by: nkomonen --- packages/toolkit/src/test/srcShared/fs.test.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/toolkit/src/test/srcShared/fs.test.ts b/packages/toolkit/src/test/srcShared/fs.test.ts index c15ba79165f..7d3a6ccefdc 100644 --- a/packages/toolkit/src/test/srcShared/fs.test.ts +++ b/packages/toolkit/src/test/srcShared/fs.test.ts @@ -13,6 +13,7 @@ import * as os from 'os' import { isMinimumVersion } from '../../shared/vscode/env' import Sinon from 'sinon' import * as extensionUtilities from '../../shared/extensionUtilities' +import crypto from 'crypto' function isWin() { return os.platform() === 'win32' @@ -174,7 +175,7 @@ describe('FileSystem', function () { await fsCommon.mkdir(dirPath) assert.ok(existsSync(dirPath)) - assert.ok(mkdirSpy.calledOnce) + assert.strictEqual(mkdirSpy.callCount, 1) }) }) }) @@ -299,8 +300,11 @@ describe('FileSystem', function () { return path.join(testRootPath(), relativePath) } + let _testRootPath: string | undefined + function testRootPath() { - return path.join(fakeContext.globalStorageUri.fsPath, 'testDir') + _testRootPath ??= path.join(fakeContext.globalStorageUri.fsPath, crypto.randomBytes(4).toString('hex')) + return _testRootPath } async function makeTestRoot() { @@ -308,6 +312,7 @@ describe('FileSystem', function () { } async function deleteTestRoot() { - return rmSync(testRootPath(), { recursive: true }) + rmSync(testRootPath(), { recursive: true }) + _testRootPath = undefined } })