Split lib/utils.ts into: - lib/utils.ts: Client-safe utilities only (no Node.js imports) - lib/project-utils.ts: Server-only utilities with Node.js imports This fixes the Next.js build error where client components were importing modules that contained Node.js dependencies (fs, path). All tests pass and build succeeds. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
66 lines
2.1 KiB
TypeScript
66 lines
2.1 KiB
TypeScript
import { formatVersion, formatFileSize, formatDateTime } from '../utils';
|
|
|
|
describe('formatVersion', () => {
|
|
test('应该将下划线替换为点号', () => {
|
|
expect(formatVersion('0_42')).toBe('0.42');
|
|
expect(formatVersion('1_23_4')).toBe('1.23.4');
|
|
expect(formatVersion('2_0')).toBe('2.0');
|
|
});
|
|
|
|
test('应该处理没有下划线的版本号', () => {
|
|
expect(formatVersion('1.0')).toBe('1.0');
|
|
expect(formatVersion('2.3.4')).toBe('2.3.4');
|
|
});
|
|
|
|
test('应该处理空字符串', () => {
|
|
expect(formatVersion('')).toBe('');
|
|
});
|
|
});
|
|
|
|
describe('formatFileSize', () => {
|
|
test('应该格式化字节数', () => {
|
|
expect(formatFileSize(0)).toBe('0 B');
|
|
expect(formatFileSize(100)).toBe('100 B');
|
|
expect(formatFileSize(1023)).toBe('1023 B');
|
|
});
|
|
|
|
test('应该格式化KB', () => {
|
|
expect(formatFileSize(1024)).toBe('1.00 KB');
|
|
expect(formatFileSize(2048)).toBe('2.00 KB');
|
|
expect(formatFileSize(1536)).toBe('1.50 KB');
|
|
});
|
|
|
|
test('应该格式化MB', () => {
|
|
expect(formatFileSize(1024 * 1024)).toBe('1.00 MB');
|
|
expect(formatFileSize(2 * 1024 * 1024)).toBe('2.00 MB');
|
|
expect(formatFileSize(1.5 * 1024 * 1024)).toBe('1.50 MB');
|
|
});
|
|
|
|
test('应该格式化GB', () => {
|
|
expect(formatFileSize(1024 * 1024 * 1024)).toBe('1.00 GB');
|
|
expect(formatFileSize(2 * 1024 * 1024 * 1024)).toBe('2.00 GB');
|
|
});
|
|
});
|
|
|
|
describe('formatDateTime', () => {
|
|
test('应该格式化日期时间为标准格式', () => {
|
|
const date = new Date('2024-01-15T09:30:00');
|
|
expect(formatDateTime(date)).toBe('2024-01-15 09:30');
|
|
});
|
|
|
|
test('应该正确处理午夜时间', () => {
|
|
const date = new Date('2024-12-31T00:00:00');
|
|
expect(formatDateTime(date)).toBe('2024-12-31 00:00');
|
|
});
|
|
|
|
test('应该正确处理月末日期', () => {
|
|
const date = new Date('2024-12-31T23:59:00');
|
|
expect(formatDateTime(date)).toBe('2024-12-31 23:59');
|
|
});
|
|
|
|
test('应该正确处理单数月份和日期', () => {
|
|
const date = new Date('2024-01-05T09:05:00');
|
|
expect(formatDateTime(date)).toBe('2024-01-05 09:05');
|
|
});
|
|
});
|