gh-here 1.1.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.channels_cache_v2.json +10882 -0
- package/.claude/settings.local.json +10 -17
- package/.users_cache.json +16187 -0
- package/bin/gh-here.js +8 -9
- package/blog-post.md +100 -0
- package/lib/file-utils.js +45 -1
- package/lib/renderers.js +64 -13
- package/lib/server.js +25 -5
- package/package.json +1 -1
- package/public/styles.css +137 -10
- package/tests/fileTypeDetection.test.js +111 -0
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
// Simple unit tests for file type detection
|
|
2
|
+
// Run with: node tests/fileTypeDetection.test.js
|
|
3
|
+
|
|
4
|
+
// Import the functions from our file-utils module
|
|
5
|
+
const { isImageFile, isBinaryFile, isTextFile } = require('../lib/file-utils');
|
|
6
|
+
|
|
7
|
+
function test(description, testFn) {
|
|
8
|
+
try {
|
|
9
|
+
testFn();
|
|
10
|
+
console.log(`✅ ${description}`);
|
|
11
|
+
} catch (error) {
|
|
12
|
+
console.log(`❌ ${description}`);
|
|
13
|
+
console.log(` Error: ${error.message}`);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function assert(condition, message) {
|
|
18
|
+
if (!condition) {
|
|
19
|
+
throw new Error(message || 'Assertion failed');
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// Test isImageFile function
|
|
24
|
+
test('should detect PNG files as images', () => {
|
|
25
|
+
assert(isImageFile('photo.png'), 'PNG should be detected as image');
|
|
26
|
+
assert(isImageFile('PNG'), 'Extension-only PNG should work');
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
test('should detect common image formats', () => {
|
|
30
|
+
const imageFiles = ['test.jpg', 'test.jpeg', 'test.gif', 'test.svg', 'test.webp', 'test.bmp', 'test.tiff', 'test.ico'];
|
|
31
|
+
imageFiles.forEach(file => {
|
|
32
|
+
assert(isImageFile(file), `${file} should be detected as image`);
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
test('should not detect text files as images', () => {
|
|
37
|
+
const textFiles = ['readme.md', 'script.js', 'style.css', 'config.json'];
|
|
38
|
+
textFiles.forEach(file => {
|
|
39
|
+
assert(!isImageFile(file), `${file} should not be detected as image`);
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
// Test isBinaryFile function
|
|
44
|
+
test('should detect images as binary files', () => {
|
|
45
|
+
assert(isBinaryFile('photo.png'), 'Images should be binary');
|
|
46
|
+
assert(isBinaryFile('animation.gif'), 'GIFs should be binary');
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
test('should detect archives as binary files', () => {
|
|
50
|
+
const archives = ['file.zip', 'backup.tar', 'compressed.gz', 'archive.rar', 'package.7z'];
|
|
51
|
+
archives.forEach(file => {
|
|
52
|
+
assert(isBinaryFile(file), `${file} should be detected as binary`);
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
test('should detect executables as binary files', () => {
|
|
57
|
+
const executables = ['program.exe', 'binary.bin', 'application.app'];
|
|
58
|
+
executables.forEach(file => {
|
|
59
|
+
assert(isBinaryFile(file), `${file} should be detected as binary`);
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
test('should detect documents as binary files', () => {
|
|
64
|
+
const docs = ['document.pdf', 'spreadsheet.xlsx', 'presentation.pptx'];
|
|
65
|
+
docs.forEach(file => {
|
|
66
|
+
assert(isBinaryFile(file), `${file} should be detected as binary`);
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
test('should not detect text files as binary', () => {
|
|
71
|
+
const textFiles = ['readme.md', 'script.js', 'style.css', 'data.json', 'config.yml', 'index.html'];
|
|
72
|
+
textFiles.forEach(file => {
|
|
73
|
+
assert(!isBinaryFile(file), `${file} should not be detected as binary`);
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
// Test isTextFile function
|
|
78
|
+
test('should detect common text files', () => {
|
|
79
|
+
const textFiles = ['readme.md', 'script.js', 'style.css', 'data.json', 'config.yml', 'index.html', 'app.py', 'main.go'];
|
|
80
|
+
textFiles.forEach(file => {
|
|
81
|
+
assert(isTextFile(file), `${file} should be detected as text`);
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
test('should not detect binary files as text', () => {
|
|
86
|
+
const binaryFiles = ['photo.png', 'archive.zip', 'program.exe', 'document.pdf'];
|
|
87
|
+
binaryFiles.forEach(file => {
|
|
88
|
+
assert(!isTextFile(file), `${file} should not be detected as text`);
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
// Test edge cases
|
|
93
|
+
test('should handle files without extensions', () => {
|
|
94
|
+
assert(isTextFile('README'), 'Files without extensions should default to text');
|
|
95
|
+
assert(isTextFile('Makefile'), 'Common text files without extensions should be text');
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
test('should handle extension-only input', () => {
|
|
99
|
+
assert(isImageFile('png'), 'Should handle bare extensions');
|
|
100
|
+
assert(isBinaryFile('exe'), 'Should handle bare extensions for binary');
|
|
101
|
+
assert(isTextFile('js'), 'Should handle bare extensions for text');
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
test('should be case insensitive', () => {
|
|
105
|
+
assert(isImageFile('PHOTO.PNG'), 'Should handle uppercase extensions');
|
|
106
|
+
assert(isBinaryFile('ARCHIVE.ZIP'), 'Should handle uppercase extensions');
|
|
107
|
+
assert(isTextFile('SCRIPT.JS'), 'Should handle uppercase extensions');
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
// Run all tests
|
|
111
|
+
console.log('Running file type detection tests...\n');
|