mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-03-10 22:21:22 -07:00
fix(cli): enable typechecking for ui/commands tests (#11413)
This commit is contained in:
@@ -99,8 +99,10 @@ describe('chatCommand', () => {
|
||||
const date1 = new Date();
|
||||
const date2 = new Date(date1.getTime() + 1000);
|
||||
|
||||
mockFs.readdir.mockResolvedValue(fakeFiles);
|
||||
mockFs.stat.mockImplementation(async (path: string): Promise<Stats> => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
mockFs.readdir.mockResolvedValue(fakeFiles as any);
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
mockFs.stat.mockImplementation(async (path: any): Promise<Stats> => {
|
||||
if (path.endsWith('test1.json')) {
|
||||
return { mtime: date1 } as Stats;
|
||||
}
|
||||
@@ -500,7 +502,7 @@ Hi there!`;
|
||||
const expectedPath = path.join(process.cwd(), 'my-chat.json');
|
||||
const [actualPath, actualContent] = mockFs.writeFile.mock.calls[0];
|
||||
expect(actualPath).toEqual(expectedPath);
|
||||
const parsedContent = JSON.parse(actualContent);
|
||||
const parsedContent = JSON.parse(actualContent as string);
|
||||
expect(Array.isArray(parsedContent)).toBe(true);
|
||||
parsedContent.forEach((item: Content) => {
|
||||
expect(item).toHaveProperty('role');
|
||||
@@ -515,9 +517,9 @@ Hi there!`;
|
||||
const expectedPath = path.join(process.cwd(), 'my-chat.md');
|
||||
const [actualPath, actualContent] = mockFs.writeFile.mock.calls[0];
|
||||
expect(actualPath).toEqual(expectedPath);
|
||||
const entries = actualContent.split('\n\n---\n\n');
|
||||
const entries = (actualContent as string).split('\n\n---\n\n');
|
||||
expect(entries.length).toBe(mockHistory.length);
|
||||
entries.forEach((entry, index) => {
|
||||
entries.forEach((entry: string, index: number) => {
|
||||
const { role, parts } = mockHistory[index];
|
||||
const text = parts.map((p) => p.text).join('');
|
||||
const roleIcon = role === 'user' ? '🧑💻' : '✨';
|
||||
|
||||
@@ -226,6 +226,7 @@ describe('extensionsCommand', () => {
|
||||
version: '1.0.0',
|
||||
isActive: true,
|
||||
path: '/test/dir/ext-one',
|
||||
contextFiles: [],
|
||||
installMetadata: {
|
||||
type: 'git',
|
||||
autoUpdate: false,
|
||||
@@ -237,6 +238,7 @@ describe('extensionsCommand', () => {
|
||||
version: '1.0.0',
|
||||
isActive: true,
|
||||
path: '/test/dir/another-ext',
|
||||
contextFiles: [],
|
||||
installMetadata: {
|
||||
type: 'git',
|
||||
autoUpdate: false,
|
||||
@@ -248,6 +250,7 @@ describe('extensionsCommand', () => {
|
||||
version: '1.0.0',
|
||||
isActive: true,
|
||||
path: '/test/dir/all-ext',
|
||||
contextFiles: [],
|
||||
installMetadata: {
|
||||
type: 'git',
|
||||
autoUpdate: false,
|
||||
|
||||
@@ -9,7 +9,7 @@ import * as fs from 'node:fs';
|
||||
import * as path from 'node:path';
|
||||
import { initCommand } from './initCommand.js';
|
||||
import { createMockCommandContext } from '../../test-utils/mockCommandContext.js';
|
||||
import { type CommandContext } from './types.js';
|
||||
import type { SubmitPromptActionReturn, CommandContext } from './types.js';
|
||||
|
||||
// Mock the 'fs' module
|
||||
vi.mock('fs', () => ({
|
||||
@@ -61,7 +61,10 @@ describe('initCommand', () => {
|
||||
vi.mocked(fs.existsSync).mockReturnValue(false);
|
||||
|
||||
// Act: Run the command's action
|
||||
const result = await initCommand.action!(mockContext, '');
|
||||
const result = (await initCommand.action!(
|
||||
mockContext,
|
||||
'',
|
||||
)) as SubmitPromptActionReturn;
|
||||
|
||||
// Assert: Check that writeFileSync was called correctly
|
||||
expect(fs.writeFileSync).toHaveBeenCalledWith(geminiMdPath, '', 'utf8');
|
||||
|
||||
@@ -198,7 +198,7 @@ describe('memoryCommand', () => {
|
||||
importFormat: 'tree',
|
||||
},
|
||||
},
|
||||
} as LoadedSettings,
|
||||
} as unknown as LoadedSettings,
|
||||
},
|
||||
ui: {
|
||||
setGeminiMdFileCount: vi.fn(),
|
||||
|
||||
@@ -28,7 +28,7 @@ describe('terminalSetupCommand', () => {
|
||||
message: 'Terminal configured successfully',
|
||||
});
|
||||
|
||||
const result = await terminalSetupCommand.action({} as CommandContext, '');
|
||||
const result = await terminalSetupCommand.action!({} as CommandContext, '');
|
||||
|
||||
expect(result).toEqual({
|
||||
type: 'message',
|
||||
@@ -44,7 +44,7 @@ describe('terminalSetupCommand', () => {
|
||||
requiresRestart: true,
|
||||
});
|
||||
|
||||
const result = await terminalSetupCommand.action({} as CommandContext, '');
|
||||
const result = await terminalSetupCommand.action!({} as CommandContext, '');
|
||||
|
||||
expect(result).toEqual({
|
||||
type: 'message',
|
||||
@@ -60,7 +60,7 @@ describe('terminalSetupCommand', () => {
|
||||
message: 'Failed to detect terminal',
|
||||
});
|
||||
|
||||
const result = await terminalSetupCommand.action({} as CommandContext, '');
|
||||
const result = await terminalSetupCommand.action!({} as CommandContext, '');
|
||||
|
||||
expect(result).toEqual({
|
||||
type: 'message',
|
||||
@@ -74,7 +74,7 @@ describe('terminalSetupCommand', () => {
|
||||
new Error('Unexpected error'),
|
||||
);
|
||||
|
||||
const result = await terminalSetupCommand.action({} as CommandContext, '');
|
||||
const result = await terminalSetupCommand.action!({} as CommandContext, '');
|
||||
|
||||
expect(result).toEqual({
|
||||
type: 'message',
|
||||
|
||||
@@ -9,7 +9,7 @@ import { describe, it, expect } from 'vitest';
|
||||
import { toolsCommand } from './toolsCommand.js';
|
||||
import { createMockCommandContext } from '../../test-utils/mockCommandContext.js';
|
||||
import { MessageType } from '../types.js';
|
||||
import type { Tool } from '@google/gemini-cli-core';
|
||||
import type { ToolBuilder, ToolResult } from '@google/gemini-cli-core';
|
||||
|
||||
// Mock tools for testing
|
||||
const mockTools = [
|
||||
@@ -25,7 +25,7 @@ const mockTools = [
|
||||
description: 'Edits code files.',
|
||||
schema: {},
|
||||
},
|
||||
] as Tool[];
|
||||
] as unknown as Array<ToolBuilder<object, ToolResult>>;
|
||||
|
||||
describe('toolsCommand', () => {
|
||||
it('should display an error if the tool registry is unavailable', async () => {
|
||||
@@ -53,7 +53,9 @@ describe('toolsCommand', () => {
|
||||
const mockContext = createMockCommandContext({
|
||||
services: {
|
||||
config: {
|
||||
getToolRegistry: () => ({ getAllTools: () => [] as Tool[] }),
|
||||
getToolRegistry: () => ({
|
||||
getAllTools: () => [] as Array<ToolBuilder<object, ToolResult>>,
|
||||
}),
|
||||
},
|
||||
},
|
||||
});
|
||||
@@ -83,7 +85,8 @@ describe('toolsCommand', () => {
|
||||
if (!toolsCommand.action) throw new Error('Action not defined');
|
||||
await toolsCommand.action(mockContext, '');
|
||||
|
||||
const [message] = (mockContext.ui.addItem as vi.Mock).mock.calls[0];
|
||||
const [message] = (mockContext.ui.addItem as ReturnType<typeof vi.fn>).mock
|
||||
.calls[0];
|
||||
expect(message.type).toBe(MessageType.TOOLS_LIST);
|
||||
expect(message.showDescriptions).toBe(false);
|
||||
expect(message.tools).toHaveLength(2);
|
||||
@@ -103,7 +106,8 @@ describe('toolsCommand', () => {
|
||||
if (!toolsCommand.action) throw new Error('Action not defined');
|
||||
await toolsCommand.action(mockContext, 'desc');
|
||||
|
||||
const [message] = (mockContext.ui.addItem as vi.Mock).mock.calls[0];
|
||||
const [message] = (mockContext.ui.addItem as ReturnType<typeof vi.fn>).mock
|
||||
.calls[0];
|
||||
expect(message.type).toBe(MessageType.TOOLS_LIST);
|
||||
expect(message.showDescriptions).toBe(true);
|
||||
expect(message.tools).toHaveLength(2);
|
||||
|
||||
@@ -28,31 +28,6 @@
|
||||
"src/utils/handleAutoUpdate.test.ts",
|
||||
"src/utils/startupWarnings.test.ts",
|
||||
"src/ui/App.test.tsx",
|
||||
"src/ui/commands/aboutCommand.test.ts",
|
||||
"src/ui/commands/authCommand.test.ts",
|
||||
"src/ui/commands/bugCommand.test.ts",
|
||||
"src/ui/commands/clearCommand.test.ts",
|
||||
"src/ui/commands/compressCommand.test.ts",
|
||||
"src/ui/commands/copyCommand.test.ts",
|
||||
"src/ui/commands/corgiCommand.test.ts",
|
||||
"src/ui/commands/docsCommand.test.ts",
|
||||
"src/ui/commands/editorCommand.test.ts",
|
||||
"src/ui/commands/extensionsCommand.test.ts",
|
||||
"src/ui/commands/helpCommand.test.ts",
|
||||
"src/ui/commands/restoreCommand.test.ts",
|
||||
"src/ui/commands/settingsCommand.test.ts",
|
||||
"src/ui/commands/themeCommand.test.ts",
|
||||
"src/ui/commands/chatCommand.test.ts",
|
||||
"src/ui/commands/directoryCommand.test.tsx",
|
||||
"src/ui/commands/ideCommand.test.ts",
|
||||
"src/ui/commands/initCommand.test.ts",
|
||||
"src/ui/commands/privacyCommand.test.ts",
|
||||
"src/ui/commands/quitCommand.test.ts",
|
||||
"src/ui/commands/mcpCommand.test.ts",
|
||||
"src/ui/commands/memoryCommand.test.ts",
|
||||
"src/ui/commands/statsCommand.test.ts",
|
||||
"src/ui/commands/terminalSetupCommand.test.ts",
|
||||
"src/ui/commands/toolsCommand.test.ts",
|
||||
"src/ui/components/ContextSummaryDisplay.test.tsx",
|
||||
"src/ui/components/Footer.test.tsx",
|
||||
"src/ui/components/InputPrompt.test.tsx",
|
||||
|
||||
Reference in New Issue
Block a user