Files
Genarrative/apps/ai-game-creator-shell/tests/cocosProjectOpen.test.tsx
T
k88936 25c5ecdf6e
Project CI / AI game creator shell Rust crates (pull_request) Successful in 2m58s
Project CI / AI game creator shell Rust lane 1/2 (pull_request) Successful in 6m34s
Project CI / AI game creator shell Rust lane 2/2 (pull_request) Successful in 5m29s
Project CI / Backend tests (pull_request) Failing after 4m38s
Project CI / Frontend tests (pull_request) Successful in 3m33s
Project CI / Repository checks (pull_request) Failing after 4m4s
Project CI / AI game creator shell web tests (pull_request) Successful in 3m13s
Project CI / Native shell tests (pull_request) Successful in 6m35s
测试:全仓测试统一 Tauri 运行时替身安装点
- 78 处内联 window.__TAURI__ 赋值改为 installTauriRuntime,覆盖 appSurface 之外的 37 个测试文件
- 31 处 delete window.__TAURI__ / window.__TAURI__ = undefined 复位改为 resetTauriRuntime
- 删除 recentProjectsHook、projectCreationDirectory、projectResourceLiveIntegration、useProjectResourceCardPreviews、resourceVersionReplacementModel、unityProjectOpen 里的本地 asTauriInvoke / asTauriListen 适配器与相关类型别名
- designProjectRestore 的 setup 参数由 ReturnType<typeof vi.fn> 收窄为具体 invoke 签名
- 迁移后仅 tests/tauriRuntimeFake.ts 直接读写 window.__TAURI__
2026-10-03 20:19:45 +08:00

79 lines
2.7 KiB
TypeScript

// @vitest-environment jsdom
import { act, renderHook } from '@testing-library/react';
import { afterEach, expect, test, vi } from 'vitest';
import { createGameCreationAppManifest } from '../../../packages/shared/src/contracts/gameCreationApp';
import { useHomeProjectCreation } from '../src/features/app-shell/useHomeProjectCreation';
import { installTauriRuntime, resetTauriRuntime } from './tauriRuntimeFake';
afterEach(() => {
resetTauriRuntime();
});
test('打开 Cocos 目录走导入入口,不创建 Web 脚手架或发送初始消息', async () => {
const manifest = {
...createGameCreationAppManifest('cocos-project', 'Cocos 项目'),
cocosProjectRoot: '.',
};
const invoke = vi.fn(async (command: string) => {
if (command === 'inspect_local_project_directory') {
return {
exists: true,
isDirectory: true,
isGameCreatorProject: false,
isGodotProject: false,
godotProjectRoot: null,
isCocosProject: true,
cocosProjectRoot: '.',
projectName: 'Cocos 项目',
recentRunStatus: null,
recentRunStopReason: null,
};
}
if (command === 'import_local_cocos_project') {
return { projectPath: 'C:/projects/cocos', manifest };
}
if (command === 'get_local_game_project_revision') return { revision: 0 };
if (command === 'get_design_agent_runtime_mode') {
return { activeRuntime: 'game' };
}
throw new Error(`意外调用:${command}`);
});
// TauriInvoke 是泛型函数签名,vi.fn 的具体返回类型无法直接赋给它,这里只在装配处桥接。
installTauriRuntime({ core: { invoke } });
const setLauncherView = vi.fn();
const { result } = renderHook(() =>
useHomeProjectCreation({
setStatus: vi.fn(),
// 现行 UseHomeProjectCreationOptions 必填 showTransientNotice,旧的 setAgentChatProjectPath 已移除。
showTransientNotice: vi.fn(),
setLauncherView,
rememberRecentWorkspace: vi.fn(),
}),
);
await act(() => result.current.openProject('C:/projects/cocos', 'open'));
expect(invoke).toHaveBeenCalledWith('import_local_cocos_project', {
projectPath: 'C:/projects/cocos',
projectId: expect.any(String),
name: 'cocos',
});
expect(result.current.currentProjectContext).toMatchObject({
projectKind: 'cocos',
projectPath: 'C:/projects/cocos',
initialPrompt: '',
startMode: null,
manifest,
});
expect(setLauncherView).toHaveBeenCalledWith('project-development');
expect(invoke).toHaveBeenCalledWith('get_design_agent_runtime_mode', {
projectPath: 'C:/projects/cocos',
});
expect(
invoke.mock.calls.some(
([command]) => command === 'init_local_game_project',
),
).toBe(false);
});