From edb707d83ab126c74856856d8df2ac0064b9c640 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, 6 insertions(+), 5 deletions(-) diff --git a/packages/toolkit/src/test/srcShared/fs.test.ts b/packages/toolkit/src/test/srcShared/fs.test.ts index c15ba79165f..217aa1a01ec 100644 --- a/packages/toolkit/src/test/srcShared/fs.test.ts +++ b/packages/toolkit/src/test/srcShared/fs.test.ts @@ -24,6 +24,7 @@ describe('FileSystem', function () { before(async function () { fakeContext = await FakeExtensionContext.create() + await deleteTestRoot() // incase a previous test run failed to clean }) beforeEach(async function () { @@ -161,7 +162,7 @@ describe('FileSystem', function () { it(`creates folder: '${p}'`, async function () { const dirPath = createTestPath(p) await fsCommon.mkdir(dirPath) - assert.ok(existsSync(dirPath)) + assert(existsSync(dirPath)) }) }) @@ -173,8 +174,8 @@ describe('FileSystem', function () { await fsCommon.mkdir(dirPath) - assert.ok(existsSync(dirPath)) - assert.ok(mkdirSpy.calledOnce) + assert(existsSync(dirPath)) + assert.strictEqual(mkdirSpy.callCount, 1) }) }) }) @@ -300,7 +301,7 @@ describe('FileSystem', function () { } function testRootPath() { - return path.join(fakeContext.globalStorageUri.fsPath, 'testDir') + return path.join(fakeContext.globalStorageUri.fsPath, 'fsTestDir') } async function makeTestRoot() { @@ -308,6 +309,6 @@ describe('FileSystem', function () { } async function deleteTestRoot() { - return rmSync(testRootPath(), { recursive: true }) + rmSync(testRootPath(), { recursive: true, force: true }) } })