-
Notifications
You must be signed in to change notification settings - Fork 0
/
fs.test.ts
51 lines (40 loc) · 1.78 KB
/
fs.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import { asserts, pathUtils } from './deps.ts'
import { copyDir, PathPair, readText, recursiveReadFiles, recursiveReadInsideDir, writeText } from './fs.ts'
const testFileNames = [
'some/file/all/the/way/in/here',
'surface.txt',
'a space here',
'some/file/all/frat/way/in/here',
'surface.txt.js',
'a space here',
'some/file/all/the/way/in/there',
'surface.txt.json',
'a space here ',
]
Deno.test('recursiveReadInsideDir reads inside the dir', async () => {
const dir = await Deno.makeTempDir()
const sort = (pairs: PathPair[]) => pairs.sort((a, b) => a.innerPath.localeCompare(b.innerPath))
const expected = sort(testFileNames.map((file) => ({ path: pathUtils.join(dir, file), innerPath: file })))
for (const { path } of expected) await writeText(path, crypto.randomUUID())
asserts.assertEquals(sort(await recursiveReadInsideDir(dir)), expected)
asserts.assertEquals(sort(await recursiveReadInsideDir(dir + '/')), expected)
asserts.assertEquals(sort(await recursiveReadInsideDir(dir + '/.')), expected)
asserts.assertEquals(sort(await recursiveReadInsideDir(dir + '///.//.///')), expected)
})
Deno.test('copyDir copies directories', async () => {
const wrapper = await Deno.makeTempDir()
const src = pathUtils.join(wrapper, 'src')
const dest = pathUtils.join(wrapper, 'dest')
const midIndex = Math.round(testFileNames.length / 2)
const naughtyFile = testFileNames[midIndex]
for (const file of testFileNames) await writeText(pathUtils.join(src, file), crypto.randomUUID())
await copyDir(src, dest, {
pathFilter(file) {
return file !== naughtyFile
},
})
const srcFiles = await recursiveReadFiles(src, readText)
srcFiles.delete(naughtyFile)
const destFiles = await recursiveReadFiles(dest, readText)
asserts.assertEquals([...srcFiles.entries()], [...destFiles.entries()])
})