-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscanDir_test.ts
64 lines (54 loc) · 1.49 KB
/
scanDir_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
52
53
54
55
56
57
58
59
60
61
62
63
64
import { assertEquals } from 'jsr:@std/assert';
import { ensureDir } from 'jsr:@std/fs';
import { join } from 'jsr:@std/path';
import { scanDirectory } from './scanDir.ts';
async function cleanup(path: string) {
try {
await Deno.remove(path, { recursive: true });
} catch {
// Ignore errors if directory doesn't exist
}
}
Deno.test({
name: 'scanDirectory - correctly identifies files and nested directories',
async fn() {
const testDir = './test_scan_dir';
await cleanup(testDir);
// Create test directory structure
await ensureDir(join(testDir, 'subdir'));
await Deno.writeTextFile(join(testDir, 'file1.ts'), 'content');
await Deno.writeTextFile(join(testDir, 'subdir', 'file2.ts'), 'content');
const files = await scanDirectory(testDir);
// Sort files by path for consistent testing
const sortedFiles = files.sort((a, b) => a.path.localeCompare(b.path));
assertEquals(sortedFiles, [
{
path: join(testDir, 'file1.ts'),
name: 'file1.ts',
isDirectory: false,
},
{
path: join(testDir, 'subdir'),
name: 'subdir',
isDirectory: true,
},
{
path: join(testDir, 'subdir', 'file2.ts'),
name: 'file2.ts',
isDirectory: false,
},
]);
await cleanup(testDir);
},
});
Deno.test({
name: 'scanDirectory - handles empty directories',
async fn() {
const testDir = './test_empty_dir';
await cleanup(testDir);
await ensureDir(testDir);
const files = await scanDirectory(testDir);
assertEquals(files, []);
await cleanup(testDir);
},
});