From fcef50f5f75b4d5996a8d30b0c7c4f2683e9586f 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 --- src/test/srcShared/fs.test.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/test/srcShared/fs.test.ts b/src/test/srcShared/fs.test.ts index c15ba79165f..f137beb45fc 100644 --- a/src/test/srcShared/fs.test.ts +++ b/src/test/srcShared/fs.test.ts @@ -156,10 +156,15 @@ describe('FileSystem', function () { describe('mkdir()', function () { const paths = ['a', 'a/b', 'a/b/c', 'a/b/c/d/'] + let dirPath: string // store path for easy cleanup + + afterEach(async function () { + await fsCommon.delete(dirPath) + }) paths.forEach(async function (p) { it(`creates folder: '${p}'`, async function () { - const dirPath = createTestPath(p) + dirPath = createTestPath(p) await fsCommon.mkdir(dirPath) assert.ok(existsSync(dirPath)) }) @@ -169,12 +174,12 @@ describe('FileSystem', function () { it(`creates folder but uses the "fs" module if in C9: '${p}'`, async function () { sandbox.stub(extensionUtilities, 'isCloud9').returns(true) const mkdirSpy = sandbox.spy(fsPromises, 'mkdir') - const dirPath = createTestPath(p) + dirPath = createTestPath(p) await fsCommon.mkdir(dirPath) assert.ok(existsSync(dirPath)) - assert.ok(mkdirSpy.calledOnce) + assert.strictEqual(mkdirSpy.callCount, 1) }) }) })