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'); }); });