1
1
mirror of https://github.com/theoludwig/programming-challenges.git synced 2024-11-09 22:08:58 +01:00
programming-challenges/cli/utils/__test__/createTemporaryEmptyFolder.test.ts

35 lines
957 B
TypeScript
Raw Normal View History

import fs from 'node:fs'
import fsMock from 'mock-fs'
import {
TEMPORARY_PATH,
createTemporaryEmptyFolder
} from '../createTemporaryEmptyFolder'
import { isExistingPath } from '../isExistingPath'
describe('utils/createTemporaryEmptyFolder', () => {
afterEach(async () => {
fsMock.restore()
})
it('should create the temporary folder', async () => {
fsMock({})
expect(await isExistingPath(TEMPORARY_PATH)).toBeFalsy()
await createTemporaryEmptyFolder()
expect(await isExistingPath(TEMPORARY_PATH)).toBeTruthy()
})
it('should remove and create again the temporary folder', async () => {
fsMock({
[TEMPORARY_PATH]: {
'file.txt': ''
}
})
expect(await isExistingPath(TEMPORARY_PATH)).toBeTruthy()
expect((await fs.promises.readdir(TEMPORARY_PATH)).length).toEqual(1)
await createTemporaryEmptyFolder()
expect((await fs.promises.readdir(TEMPORARY_PATH)).length).toEqual(0)
})
})