-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathtest.js
More file actions
171 lines (146 loc) · 4.13 KB
/
Copy pathtest.js
File metadata and controls
171 lines (146 loc) · 4.13 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#!/usr/bin/env node
/**
* Test file for treeview CLI tool
* This file creates test files and directories to verify the ignore functionality
*/
const fs = require('fs');
const path = require('path');
const { execSync } = require('child_process');
console.log('🌳 Treeview CLI Test Suite\n');
// Create test directory structure
const testDir = path.join(__dirname, 'test-project');
const testFiles = [
'package.json',
'README.md',
'src/index.js',
'src/utils.js',
'src/components/Button.js',
'src/components/Modal.js',
'build/app.js',
'build/style.css',
'dist/app.min.js',
'dist/style.min.css',
'temp.txt',
'debug.log',
'error.log',
'test-file.tmp',
'backup-file.bak',
'config.json',
'data.csv',
'notes.md',
'temp-folder/file1.txt',
'temp-folder/file2.txt',
'logs/2024-01-01.log',
'logs/2024-01-02.log',
'cache/data.cache',
'.env',
'.env.local',
'coverage/lcov.info',
'coverage/index.html'
];
// Clean up previous test
if (fs.existsSync(testDir)) {
fs.rmSync(testDir, { recursive: true, force: true });
}
// Create test directory structure
console.log('📁 Creating test directory structure...');
fs.mkdirSync(testDir, { recursive: true });
// Create all test files
testFiles.forEach(file => {
const filePath = path.join(testDir, file);
const dir = path.dirname(filePath);
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir, { recursive: true });
}
fs.writeFileSync(filePath, `// Test file: ${file}\n// Created for treeview testing\n`);
});
console.log(`✅ Created ${testFiles.length} test files\n`);
// Test functions
function runTest(testName, command, expectedBehavior) {
console.log(`🧪 Testing: ${testName}`);
console.log(` Command: ${command}`);
try {
const result = execSync(command, {
cwd: testDir,
encoding: 'utf8',
stdio: 'pipe'
});
console.log(` ✅ Success`);
console.log(` Output preview: ${result.split('\n').slice(0, 3).join(' | ')}...`);
} catch (error) {
console.log(` ❌ Failed: ${error.message}`);
}
console.log('');
}
// Run tests
console.log('🚀 Running tests...\n');
// Test 1: Basic functionality
runTest(
'Basic tree output',
'node ../bin/index.js',
'Should show all files in tree format'
);
// Test 2: Ignore specific files
runTest(
'Ignore specific files',
'node ../bin/index.js --ignore-files temp.txt debug.log',
'Should hide temp.txt and debug.log'
);
// Test 3: Ignore glob patterns
runTest(
'Ignore glob patterns - log files',
'node ../bin/index.js --ignore-pattern "*.log"',
'Should hide all .log files'
);
// Test 4: Ignore glob patterns - multiple patterns
runTest(
'Ignore multiple glob patterns',
'node ../bin/index.js --ignore-pattern "*.log" "*.tmp" "*.bak"',
'Should hide .log, .tmp, and .bak files'
);
// Test 5: Ignore directories
runTest(
'Ignore directories',
'node ../bin/index.js --ignore-files build dist',
'Should hide build and dist directories'
);
// Test 6: Ignore with glob patterns for directories
runTest(
'Ignore directories with glob',
'node ../bin/index.js --ignore-pattern "temp-*" "logs"',
'Should hide temp-folder and logs directories'
);
// Test 7: Combined ignore flags
runTest(
'Combined ignore flags',
'node ../bin/index.js --ignore-files temp.txt --ignore-pattern "*.log" "*.tmp"',
'Should hide temp.txt and all .log/.tmp files'
);
// Test 8: Help flag
runTest(
'Help flag',
'node ../bin/index.js --help',
'Should show help information'
);
// Test 9: Complex glob patterns
runTest(
'Complex glob patterns',
'node ../bin/index.js --ignore-pattern "*.min.*" "coverage/*" ".env*"',
'Should hide minified files, coverage directory, and .env files'
);
// Test 10: Edge case - no matches
runTest(
'No matching patterns',
'node ../bin/index.js --ignore-pattern "*.nonexistent"',
'Should show all files (no matches)'
);
// Test 11: Dirs only
runTest(
'Directories only',
'node ../bin/index.js --dirs-only',
'Should show only directories, no files'
);
console.log('🎉 Test suite completed!');
console.log('\n🧹 Cleaning up test directory...');
fs.rmSync(testDir, { recursive: true, force: true });
console.log('✅ Cleanup complete!');