2021-07-03 18:40:17 +02:00
|
|
|
import fs from 'node:fs'
|
|
|
|
|
2021-06-09 20:31:45 +02:00
|
|
|
import fsMock from 'mock-fs'
|
|
|
|
|
|
|
|
import {
|
|
|
|
TEMPORARY_PATH,
|
|
|
|
createTemporaryEmptyFolder
|
2022-02-19 18:30:29 +01:00
|
|
|
} from '../createTemporaryEmptyFolder.js'
|
|
|
|
import { isExistingPath } from '../isExistingPath.js'
|
2021-06-09 20:31:45 +02:00
|
|
|
|
|
|
|
describe('utils/createTemporaryEmptyFolder', () => {
|
2022-02-19 18:30:29 +01:00
|
|
|
afterEach(() => {
|
2021-06-09 20:31:45 +02:00
|
|
|
fsMock.restore()
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should remove and create again the temporary folder', async () => {
|
|
|
|
fsMock({
|
|
|
|
[TEMPORARY_PATH]: {
|
|
|
|
'file.txt': ''
|
|
|
|
}
|
2021-12-06 17:18:14 +01:00
|
|
|
}, { createCwd: false })
|
2021-06-09 20:31:45 +02:00
|
|
|
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)
|
|
|
|
})
|
|
|
|
})
|