forked from codinit-dev/codinit-dev
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdiff.test.ts
More file actions
43 lines (35 loc) · 1.42 KB
/
Copy pathdiff.test.ts
File metadata and controls
43 lines (35 loc) · 1.42 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
import { describe, it, expect } from 'vitest';
import { extractRelativePath } from '~/utils/diff';
import { WORK_DIR } from '~/utils/constants';
describe('extractRelativePath', () => {
it('should strip out WORK_DIR from file paths', () => {
const filePath = `${WORK_DIR}/src/components/Button.tsx`;
const result = extractRelativePath(filePath);
expect(result).toBe('src/components/Button.tsx');
});
it('should handle nested directories', () => {
const filePath = `${WORK_DIR}/app/lib/stores/chat.ts`;
const result = extractRelativePath(filePath);
expect(result).toBe('app/lib/stores/chat.ts');
});
it('should handle root level files', () => {
const filePath = `${WORK_DIR}/package.json`;
const result = extractRelativePath(filePath);
expect(result).toBe('package.json');
});
it('should return original path if WORK_DIR is not at the start', () => {
const filePath = '/some/other/path/file.ts';
const result = extractRelativePath(filePath);
expect(result).toBe('/some/other/path/file.ts');
});
it('should handle empty WORK_DIR', () => {
const originalWorkDir = WORK_DIR;
// Temporarily mock WORK_DIR as empty
(global as any).WORK_DIR = '';
const filePath = '/app/src/main.ts';
const result = extractRelativePath(filePath);
expect(result).toBe('/app/src/main.ts');
// Restore original value
(global as any).WORK_DIR = originalWorkDir;
});
});