Skip to content

Commit

Permalink
fix: flaky fs test
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
nkomonen-amazon committed Feb 6, 2024
1 parent 06d3fff commit edb707d
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions packages/toolkit/src/test/srcShared/fs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down Expand Up @@ -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))
})
})

Expand All @@ -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)
})
})
})
Expand Down Expand Up @@ -300,14 +301,14 @@ describe('FileSystem', function () {
}

function testRootPath() {
return path.join(fakeContext.globalStorageUri.fsPath, 'testDir')
return path.join(fakeContext.globalStorageUri.fsPath, 'fsTestDir')
}

async function makeTestRoot() {
return mkdirSync(testRootPath())
}

async function deleteTestRoot() {
return rmSync(testRootPath(), { recursive: true })
rmSync(testRootPath(), { recursive: true, force: true })
}
})

0 comments on commit edb707d

Please sign in to comment.