Files
ftdl/lib/__tests__/project-utils.test.ts
tech edc4cb770f fix: separate client and server utilities to fix build error
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>
2026-03-04 22:17:31 +08:00

45 lines
1.2 KiB
TypeScript

import { getProjectDisplayName } from '../project-utils';
// Mock fs module
const fs = require('fs');
const path = require('path');
jest.mock('fs');
jest.mock('path');
describe('getProjectDisplayName', () => {
const originalAliases = {
'FT': '外放构建',
'FT_DEV': '开发构建',
};
beforeEach(() => {
// Mock the aliases file
path.join.mockReturnValue('/mock/lib/project-aliases.json');
fs.readFileSync.mockReturnValue(JSON.stringify(originalAliases));
});
afterEach(() => {
jest.clearAllMocks();
});
it('should return display name for aliased project', () => {
expect(getProjectDisplayName('FT')).toBe('外放构建');
});
it('should return directory name when no alias exists', () => {
expect(getProjectDisplayName('UNKNOWN')).toBe('UNKNOWN');
});
it('should return directory name when aliases file is empty', () => {
fs.readFileSync.mockReturnValue('{}');
expect(getProjectDisplayName('FT')).toBe('FT');
});
it('should return directory name when aliases file cannot be read', () => {
fs.readFileSync.mockImplementation(() => {
throw new Error('File not found');
});
expect(getProjectDisplayName('FT')).toBe('FT');
});
});