Skip to content

Commit

Permalink
fix: flaky fs test
Browse files Browse the repository at this point in the history
Reported by aws#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 <[email protected]>
  • Loading branch information
nkomonen-amazon committed Feb 6, 2024
1 parent 06d3fff commit c7a1231
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions packages/toolkit/src/test/srcShared/fs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -174,7 +175,7 @@ describe('FileSystem', function () {
await fsCommon.mkdir(dirPath)

assert.ok(existsSync(dirPath))
assert.ok(mkdirSpy.calledOnce)
assert.strictEqual(mkdirSpy.callCount, 1)
})
})
})
Expand Down Expand Up @@ -299,15 +300,19 @@ 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() {
return mkdirSync(testRootPath())
}

async function deleteTestRoot() {
return rmSync(testRootPath(), { recursive: true })
rmSync(testRootPath(), { recursive: true })
_testRootPath = undefined
}
})

0 comments on commit c7a1231

Please sign in to comment.