1
1
mirror of https://github.com/theoludwig/programming-challenges.git synced 2024-12-08 00:45:29 +01:00
programming-challenges/cli/utils/__test__/createTemporaryEmptyFolder.test.ts
2022-02-19 18:30:29 +01:00

28 lines
739 B
TypeScript

import fs from 'node:fs'
import fsMock from 'mock-fs'
import {
TEMPORARY_PATH,
createTemporaryEmptyFolder
} from '../createTemporaryEmptyFolder.js'
import { isExistingPath } from '../isExistingPath.js'
describe('utils/createTemporaryEmptyFolder', () => {
afterEach(() => {
fsMock.restore()
})
it('should remove and create again the temporary folder', async () => {
fsMock({
[TEMPORARY_PATH]: {
'file.txt': ''
}
}, { createCwd: false })
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)
})
})