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'
|
2022-04-23 18:41:14 +02:00
|
|
|
import tap from 'tap'
|
2021-06-09 20:31:45 +02:00
|
|
|
|
|
|
|
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
|
|
|
|
2022-04-23 18:41:14 +02:00
|
|
|
await tap.test('utils/createTemporaryEmptyFolder', async (t) => {
|
|
|
|
t.afterEach(() => {
|
2021-06-09 20:31:45 +02:00
|
|
|
fsMock.restore()
|
|
|
|
})
|
|
|
|
|
2022-04-23 18:41:14 +02:00
|
|
|
await t.test('should create the temporary folder', async (t) => {
|
|
|
|
fsMock({})
|
|
|
|
t.equal(await isExistingPath(TEMPORARY_PATH), false)
|
2021-06-09 20:31:45 +02:00
|
|
|
await createTemporaryEmptyFolder()
|
2022-04-23 18:41:14 +02:00
|
|
|
t.equal(await isExistingPath(TEMPORARY_PATH), true)
|
2021-06-09 20:31:45 +02:00
|
|
|
})
|
2022-04-23 18:41:14 +02:00
|
|
|
|
|
|
|
await t.test(
|
|
|
|
'should remove and create again the temporary folder',
|
|
|
|
async (t) => {
|
|
|
|
fsMock({
|
|
|
|
[TEMPORARY_PATH]: {
|
|
|
|
'file.txt': ''
|
|
|
|
}
|
|
|
|
})
|
|
|
|
t.equal(await isExistingPath(TEMPORARY_PATH), true)
|
|
|
|
t.equal((await fs.promises.readdir(TEMPORARY_PATH)).length, 1)
|
|
|
|
await createTemporaryEmptyFolder()
|
|
|
|
t.equal((await fs.promises.readdir(TEMPORARY_PATH)).length, 0)
|
|
|
|
}
|
|
|
|
)
|
2021-06-09 20:31:45 +02:00
|
|
|
})
|