create-fullstack-scaffold 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +154 -0
- package/dist/cli/index.d.ts +2 -0
- package/dist/cli/index.js +439 -0
- package/dist/cli/index.js.map +1 -0
- package/package.json +171 -0
- package/template/.agents/skills/writing-hookify-rules/SKILL.md +408 -0
- package/template/.ai-context.md +368 -0
- package/template/.claude/hookify.block-dangerous-commands.local.md +41 -0
- package/template/.claude/hookify.check-api-types.local.md +111 -0
- package/template/.claude/hookify.check-duplicate-types.local.md +287 -0
- package/template/.claude/hookify.check-test-assertions.local.md +93 -0
- package/template/.claude/hookify.remind-add-tests.local.md +209 -0
- package/template/.claude/hookify.remind-db-migration.local.md +58 -0
- package/template/.claude/hookify.remind-run-tests.local.md +52 -0
- package/template/.claude/hookify.warn-any-type.local.md +203 -0
- package/template/.claude/hookify.warn-console-log.local.md +73 -0
- package/template/.claude/rules/00-project-config.md +147 -0
- package/template/.claude/rules/01-file-types.md +127 -0
- package/template/.claude/rules/02-git-workflow.md +167 -0
- package/template/.claude/rules/10-api-type-inference.md +555 -0
- package/template/.claude/rules/20-server-api.md +349 -0
- package/template/.claude/rules/21-server-entrypoint.md +257 -0
- package/template/.claude/rules/30-client-components.md +314 -0
- package/template/.claude/rules/31-client-services.md +768 -0
- package/template/.claude/rules/32-client-state-zustand.md +324 -0
- package/template/.claude/rules/33-client-app-entry.md +276 -0
- package/template/.claude/rules/34-client-admin-module.md +445 -0
- package/template/.claude/rules/35-cli-module.md +259 -0
- package/template/.claude/rules/40-admin-module.md +495 -0
- package/template/.claude/rules/40-shared-types.md +450 -0
- package/template/.claude/rules/50-websocket.md +245 -0
- package/template/.claude/rules/51-sse.md +372 -0
- package/template/.claude/rules/52-cloudflare-realtime.md +384 -0
- package/template/.claude/rules/60-testing-standards.md +245 -0
- package/template/.claude/rules/61-hono-testing.md +200 -0
- package/template/.claude/scripts/README.md +187 -0
- package/template/.claude/scripts/check-duplicate-types.ts +188 -0
- package/template/.claude/scripts/post-edit-check-incremental.sh +61 -0
- package/template/.claude/scripts/post-edit-check.sh +22 -0
- package/template/.claude/scripts/pre-tool-use-check.sh +86 -0
- package/template/.claude/scripts/test-pre-tool-use.sh +73 -0
- package/template/.claude/scripts/validate-git-changes.sh +38 -0
- package/template/.claude/settings.json +32 -0
- package/template/.claude/skills/writing-hookify-rules/SKILL.md +408 -0
- package/template/.dev-context-compact.md +54 -0
- package/template/.dev-context.md +621 -0
- package/template/.dev-guide.md +243 -0
- package/template/.env.example +60 -0
- package/template/.eslintrc.routes.json +39 -0
- package/template/.husky/_/husky.sh +27 -0
- package/template/.husky/commit-msg +4 -0
- package/template/.husky/post-commit +4 -0
- package/template/.husky/pre-commit +19 -0
- package/template/.husky/pre-push +12 -0
- package/template/.prettierignore +22 -0
- package/template/.prettierrc +8 -0
- package/template/.sessions/3/2026-03-26T05-41-09-154Z_03bb597f-3898-4a2e-8c08-5746bbe8d95e.jsonl +18 -0
- package/template/.sessions/3/2026-03-26T05-48-30-052Z_12de4774-9cb3-494c-9852-bd1e6b0003c3.jsonl +6 -0
- package/template/.vscode/extensions.json +8 -0
- package/template/.vscode/settings.json +4 -0
- package/template/.workspaces/3/hello.py +1 -0
- package/template/.wrangler/state/v3/d1/miniflare-D1DatabaseObject/803c2e37182b913f8857edf6d8776515cef4af6d48fcb25913e457f4b14ffa97.sqlite +0 -0
- package/template/.wrangler/state/v3/d1/miniflare-D1DatabaseObject/803c2e37182b913f8857edf6d8776515cef4af6d48fcb25913e457f4b14ffa97.sqlite-shm +0 -0
- package/template/.wrangler/state/v3/d1/miniflare-D1DatabaseObject/803c2e37182b913f8857edf6d8776515cef4af6d48fcb25913e457f4b14ffa97.sqlite-wal +0 -0
- package/template/CLAUDE.md +296 -0
- package/template/DESIGN.md +260 -0
- package/template/DEV_CONTEXT_GUIDE.md +366 -0
- package/template/DEV_TOOLS_README.md +396 -0
- package/template/FRAMEWORK_HISTORY.md +34 -0
- package/template/PROJECT_SUMMARY.md +325 -0
- package/template/QUICKSTART.md +305 -0
- package/template/README.md +154 -0
- package/template/STRUCTURE.txt +81 -0
- package/template/admin.html +13 -0
- package/template/auth-inject.html +33 -0
- package/template/commitlint.config.js +12 -0
- package/template/docs/PERMISSION_ARCHITECTURE.md +279 -0
- package/template/docs/PERMISSION_EXAMPLES.md +230 -0
- package/template/docs/PERMISSION_SYSTEM.md +301 -0
- package/template/docs/SMART_TEST.md +171 -0
- package/template/docs/runtime-abstract.md +253 -0
- package/template/drizzle/0000_rainy_boomer.sql +101 -0
- package/template/drizzle/0001_add_todo_attachments.sql +12 -0
- package/template/drizzle/0002_chilly_magneto.sql +89 -0
- package/template/drizzle/meta/0000_snapshot.json +652 -0
- package/template/drizzle/meta/0001_snapshot.json +735 -0
- package/template/drizzle/meta/0002_snapshot.json +1198 -0
- package/template/drizzle/meta/_journal.json +27 -0
- package/template/drizzle.config.ts +13 -0
- package/template/eslint-rules/README-no-middleware-in-routes.md +154 -0
- package/template/eslint-rules/__tests__/enforce-valid-method.test.ts +251 -0
- package/template/eslint-rules/__tests__/layer-boundary.test.ts +102 -0
- package/template/eslint-rules/__tests__/module-boundary.test.ts +77 -0
- package/template/eslint-rules/__tests__/no-direct-zod-import-in-file-routes.test.ts +45 -0
- package/template/eslint-rules/__tests__/no-new-old-service-naming.test.ts +76 -0
- package/template/eslint-rules/e2e-test-location.js +153 -0
- package/template/eslint-rules/enforce-valid-method.js +217 -0
- package/template/eslint-rules/flat-routes-services.js +69 -0
- package/template/eslint-rules/framework-protect.js +186 -0
- package/template/eslint-rules/layer-boundary.js +164 -0
- package/template/eslint-rules/limit-type-complexity.js +130 -0
- package/template/eslint-rules/middleware-location.js +162 -0
- package/template/eslint-rules/module-boundary.js +125 -0
- package/template/eslint-rules/no-ambiguous-file-paths.js +64 -0
- package/template/eslint-rules/no-any-on-apiclient.js +173 -0
- package/template/eslint-rules/no-boolean-success.js +43 -0
- package/template/eslint-rules/no-deep-relative-imports.js +69 -0
- package/template/eslint-rules/no-direct-fetch.js +122 -0
- package/template/eslint-rules/no-direct-ws-sse.js +57 -0
- package/template/eslint-rules/no-direct-zod-import-in-file-routes.js +54 -0
- package/template/eslint-rules/no-disable-direct-fetch.js +57 -0
- package/template/eslint-rules/no-disable-type-safe-client.js +58 -0
- package/template/eslint-rules/no-inline-schema.js +220 -0
- package/template/eslint-rules/no-middleware-in-routes.js +81 -0
- package/template/eslint-rules/no-new-old-service-naming.js +123 -0
- package/template/eslint-rules/no-type-assertion-in-rpc.js +99 -0
- package/template/eslint-rules/no-type-assertion-on-shared-types.js +109 -0
- package/template/eslint-rules/no-util-functions-in-service.js +128 -0
- package/template/eslint-rules/prefer-shared-types.js +352 -0
- package/template/eslint-rules/protect-ws-sse-interface.js +66 -0
- package/template/eslint-rules/require-antd-generic-types.js +73 -0
- package/template/eslint-rules/require-file-openapi-props.js +114 -0
- package/template/eslint-rules/require-hono-chain-syntax.js +129 -0
- package/template/eslint-rules/require-nullable-for-optional.js +99 -0
- package/template/eslint-rules/require-response-helpers.js +140 -0
- package/template/eslint-rules/require-type-safe-test-client.js +106 -0
- package/template/eslint-rules/route-location.js +72 -0
- package/template/eslint.config.js +231 -0
- package/template/index.html +17 -0
- package/template/lint-scripts/DIRECTORY_RULES.md +335 -0
- package/template/lint-scripts/README.md +299 -0
- package/template/lint-scripts/TESTING.md +273 -0
- package/template/lint-scripts/ai-context-generator.ts +159 -0
- package/template/lint-scripts/check-framework-modify.sh +8 -0
- package/template/lint-scripts/check-menu-permissions.js +242 -0
- package/template/lint-scripts/check-refs.ts +165 -0
- package/template/lint-scripts/check-route-auth-complete.js +260 -0
- package/template/lint-scripts/check-route-auth.js +212 -0
- package/template/lint-scripts/check-route-permissions.js +210 -0
- package/template/lint-scripts/config/project.config.ts +358 -0
- package/template/lint-scripts/dev-context-analyzer.ts +707 -0
- package/template/lint-scripts/dev-guide-generator.ts +830 -0
- package/template/lint-scripts/dev-server.ts +58 -0
- package/template/lint-scripts/eslint-route-auth.js +158 -0
- package/template/lint-scripts/eslint-routes-permission.js +147 -0
- package/template/lint-scripts/fix-route-auth.js +245 -0
- package/template/lint-scripts/framework/check-modify.ts +152 -0
- package/template/lint-scripts/framework/hash-utils.ts +180 -0
- package/template/lint-scripts/framework/init-baseline.ts +84 -0
- package/template/lint-scripts/framework/update-baseline.ts +148 -0
- package/template/lint-scripts/post-commit-track.ts +66 -0
- package/template/lint-scripts/quick-test.sh +27 -0
- package/template/lint-scripts/smart-test.ts +268 -0
- package/template/lint-scripts/test-history.ts +360 -0
- package/template/lint-scripts/test-tracker.ts +350 -0
- package/template/lint-scripts/validate-all.ts +250 -0
- package/template/lint-scripts/validators/api-coverage.validator.ts +355 -0
- package/template/lint-scripts/validators/client-rpc.validator.ts +190 -0
- package/template/lint-scripts/validators/client-tests.validator.ts +155 -0
- package/template/lint-scripts/validators/console-log.validator.ts +122 -0
- package/template/lint-scripts/validators/directory-structure.validator.ts +181 -0
- package/template/lint-scripts/validators/imports.validator.ts +180 -0
- package/template/lint-scripts/validators/index.ts +271 -0
- package/template/lint-scripts/validators/md-refs.validator.ts +165 -0
- package/template/lint-scripts/validators/module-tests.validator.ts +112 -0
- package/template/lint-scripts/validators/sensitive.validator.ts +185 -0
- package/template/lint-scripts/validators/server-rpc.validator.ts +141 -0
- package/template/lint-scripts/validators/test-quality.validator.ts +257 -0
- package/template/lint-scripts/validators/todos.validator.ts +126 -0
- package/template/lint-scripts/watch-validator.ts +131 -0
- package/template/modules.config.ts +71 -0
- package/template/package-lock.json +14554 -0
- package/template/package.json +158 -0
- package/template/patches/@hono+zod-openapi+1.2.2.patch +67 -0
- package/template/patches/@hono+zod-validator+0.7.6.patch +13 -0
- package/template/patches/hono+4.12.16.patch +246 -0
- package/template/patches/typescript+5.8.3.patch +26 -0
- package/template/playwright.config.ts +60 -0
- package/template/pnpm-lock.yaml +7137 -0
- package/template/postcss.config.js +6 -0
- package/template/scripts/create-template.ts +1724 -0
- package/template/src/admin/App.tsx +59 -0
- package/template/src/admin/components/AccountSwitcher.tsx +104 -0
- package/template/src/admin/components/CaptchaModal.tsx +150 -0
- package/template/src/admin/components/NotificationDrawer.tsx +213 -0
- package/template/src/admin/components/PageHeader.tsx +45 -0
- package/template/src/admin/components/PermissionConfigEditor.tsx +237 -0
- package/template/src/admin/components/PermissionGuard.tsx +108 -0
- package/template/src/admin/components/PermissionTree.tsx +193 -0
- package/template/src/admin/components/ProtectedRoute.tsx +33 -0
- package/template/src/admin/components/StatsCard.tsx +44 -0
- package/template/src/admin/components/UserFormModal.tsx +67 -0
- package/template/src/admin/components/UserTable.tsx +72 -0
- package/template/src/admin/components/__tests__/PageHeader.test.tsx +48 -0
- package/template/src/admin/components/__tests__/PermissionConfigEditor.test.tsx +147 -0
- package/template/src/admin/components/__tests__/PermissionGuard.test.tsx +221 -0
- package/template/src/admin/components/__tests__/PermissionTree.test.tsx +187 -0
- package/template/src/admin/components/__tests__/ProtectedRoute.test.tsx +129 -0
- package/template/src/admin/components/__tests__/StatsCard.test.tsx +44 -0
- package/template/src/admin/components/__tests__/UserFormModal.test.tsx +125 -0
- package/template/src/admin/components/__tests__/UserTable.test.tsx +89 -0
- package/template/src/admin/components/index.ts +7 -0
- package/template/src/admin/hooks/__tests__/useAuditLogs.test.ts +109 -0
- package/template/src/admin/hooks/__tests__/usePermissions.test.tsx +327 -0
- package/template/src/admin/hooks/__tests__/usePermissionsBranches.test.ts +198 -0
- package/template/src/admin/hooks/__tests__/useRoles.test.ts +261 -0
- package/template/src/admin/hooks/useAdminNotifications.ts +156 -0
- package/template/src/admin/hooks/useAuditLogs.ts +44 -0
- package/template/src/admin/hooks/useConfig.ts +168 -0
- package/template/src/admin/hooks/usePermissions.ts +156 -0
- package/template/src/admin/hooks/useRoles.ts +120 -0
- package/template/src/admin/layouts/Header.tsx +93 -0
- package/template/src/admin/layouts/Layout.tsx +23 -0
- package/template/src/admin/layouts/Sidebar.tsx +120 -0
- package/template/src/admin/main.tsx +18 -0
- package/template/src/admin/pages/ContentPage.tsx +252 -0
- package/template/src/admin/pages/DashboardPage.tsx +141 -0
- package/template/src/admin/pages/DisputesPage.tsx +261 -0
- package/template/src/admin/pages/LoginPage.tsx +121 -0
- package/template/src/admin/pages/MediaTestPage.tsx +524 -0
- package/template/src/admin/pages/OrdersPage.tsx +302 -0
- package/template/src/admin/pages/PermissionsPage.tsx +95 -0
- package/template/src/admin/pages/RegisterPage.tsx +103 -0
- package/template/src/admin/pages/RolesPage.tsx +330 -0
- package/template/src/admin/pages/SettingsPage.tsx +73 -0
- package/template/src/admin/pages/SystemLogsPage.tsx +218 -0
- package/template/src/admin/pages/TestCaptchaPage.tsx +120 -0
- package/template/src/admin/pages/TicketsPage.tsx +292 -0
- package/template/src/admin/pages/UsersPage.tsx +282 -0
- package/template/src/admin/pages/__tests__/ContentPage.test.tsx +213 -0
- package/template/src/admin/pages/__tests__/DashboardPage.test.tsx +153 -0
- package/template/src/admin/pages/__tests__/DisputesPage.test.tsx +196 -0
- package/template/src/admin/pages/__tests__/LoginPage.test.tsx +112 -0
- package/template/src/admin/pages/__tests__/OrdersPage.test.tsx +217 -0
- package/template/src/admin/pages/__tests__/PermissionsPage.test.tsx +119 -0
- package/template/src/admin/pages/__tests__/RegisterPage.test.tsx +179 -0
- package/template/src/admin/pages/__tests__/RolesPage.test.tsx +256 -0
- package/template/src/admin/pages/__tests__/SettingsPage.test.tsx +66 -0
- package/template/src/admin/pages/__tests__/SystemLogsPage.test.tsx +125 -0
- package/template/src/admin/pages/__tests__/TicketsPage.test.tsx +202 -0
- package/template/src/admin/pages/__tests__/UsersPage.test.tsx +229 -0
- package/template/src/admin/services/README.md +263 -0
- package/template/src/admin/services/TESTING.md +323 -0
- package/template/src/admin/services/__tests__/skipLoading.test.ts +146 -0
- package/template/src/admin/services/apiClient.ts +66 -0
- package/template/src/admin/services/requestInterceptor.ts +127 -0
- package/template/src/admin/services/types.ts +5 -0
- package/template/src/admin/stores/__tests__/adminStore.test.ts +184 -0
- package/template/src/admin/stores/__tests__/adminStoreBranches.test.ts +148 -0
- package/template/src/admin/stores/__tests__/captchaStore.test.ts +75 -0
- package/template/src/admin/stores/__tests__/captchaStoreBranches.test.ts +37 -0
- package/template/src/admin/stores/__tests__/loadingStore.test.ts +68 -0
- package/template/src/admin/stores/adminStore.ts +88 -0
- package/template/src/admin/stores/captchaStore.ts +47 -0
- package/template/src/admin/stores/loadingStore.ts +27 -0
- package/template/src/cli/index.ts +22 -0
- package/template/src/cli/modules/config/index.ts +132 -0
- package/template/src/cli/modules/index.ts +12 -0
- package/template/src/cli/modules/notification/index.ts +86 -0
- package/template/src/cli/modules/todo/index.ts +60 -0
- package/template/src/cli/rpc/client.ts +23 -0
- package/template/src/cli/rpc/index.ts +1 -0
- package/template/src/cli/utils/api.ts +17 -0
- package/template/src/cli/utils/auto-command.ts +229 -0
- package/template/src/cli/utils/index.ts +8 -0
- package/template/src/cli/utils/logger.ts +79 -0
- package/template/src/client/App.tsx +24 -0
- package/template/src/client/Layout.tsx +27 -0
- package/template/src/client/components/AuthButton.tsx +41 -0
- package/template/src/client/components/ConnectionStatus.tsx +75 -0
- package/template/src/client/components/EmptyState.tsx +26 -0
- package/template/src/client/components/Footer.tsx +17 -0
- package/template/src/client/components/LoadingSpinner.tsx +26 -0
- package/template/src/client/components/MessageCard.tsx +61 -0
- package/template/src/client/components/Navigation.tsx +65 -0
- package/template/src/client/components/StatusBadge.tsx +50 -0
- package/template/src/client/components/__tests__/App.test.tsx +79 -0
- package/template/src/client/components/__tests__/AuthButton.test.tsx +119 -0
- package/template/src/client/components/__tests__/ConnectionStatus.test.tsx +188 -0
- package/template/src/client/components/__tests__/EmptyState.test.tsx +70 -0
- package/template/src/client/components/__tests__/Footer.test.tsx +22 -0
- package/template/src/client/components/__tests__/LoadingSpinner.test.tsx +75 -0
- package/template/src/client/components/__tests__/MessageCard.test.tsx +142 -0
- package/template/src/client/components/__tests__/Navigation.test.tsx +40 -0
- package/template/src/client/components/__tests__/StatusBadge.test.tsx +107 -0
- package/template/src/client/components/index.ts +6 -0
- package/template/src/client/index.css +27 -0
- package/template/src/client/main.tsx +25 -0
- package/template/src/client/pages/ContentDetailPage.tsx +142 -0
- package/template/src/client/pages/ContentListPage.tsx +169 -0
- package/template/src/client/pages/NotificationPage.tsx +288 -0
- package/template/src/client/pages/TodoPage.tsx +389 -0
- package/template/src/client/pages/WebSocketPage.tsx +239 -0
- package/template/src/client/pages/__tests__/ContentDetailPage.test.tsx +176 -0
- package/template/src/client/pages/__tests__/ContentListPage.test.tsx +202 -0
- package/template/src/client/pages/__tests__/NotificationPage.test.tsx +246 -0
- package/template/src/client/pages/__tests__/TodoPage.test.tsx +433 -0
- package/template/src/client/pages/__tests__/WebSocketPage.test.tsx +378 -0
- package/template/src/client/services/apiClient.ts +66 -0
- package/template/src/client/stores/__tests__/authStore.test.ts +139 -0
- package/template/src/client/stores/__tests__/chatWSStore.test.ts +416 -0
- package/template/src/client/stores/__tests__/notificationStore.test.ts +453 -0
- package/template/src/client/stores/__tests__/todoStore.test.ts +509 -0
- package/template/src/client/stores/authStore.ts +51 -0
- package/template/src/client/stores/chatWSStore.ts +122 -0
- package/template/src/client/stores/notificationStore.ts +199 -0
- package/template/src/client/stores/todoStore.ts +207 -0
- package/template/src/server/__tests__/integration/todos-api.test.ts +138 -0
- package/template/src/server/app.ts +105 -0
- package/template/src/server/config.ts +86 -0
- package/template/src/server/core/__tests__/realtime-core.test.ts +329 -0
- package/template/src/server/core/__tests__/realtime-scanner.test.ts +210 -0
- package/template/src/server/core/__tests__/runtime-node.test.ts +330 -0
- package/template/src/server/core/__tests__/runtime.test.ts +219 -0
- package/template/src/server/core/__tests__/typed-runtime.test.ts +178 -0
- package/template/src/server/core/durable-objects/RealtimeDO.ts +206 -0
- package/template/src/server/core/index.ts +83 -0
- package/template/src/server/core/module-loader.ts +281 -0
- package/template/src/server/core/realtime-core.ts +152 -0
- package/template/src/server/core/realtime-scanner.ts +99 -0
- package/template/src/server/core/runtime-cloudflare.ts +207 -0
- package/template/src/server/core/runtime-node.ts +170 -0
- package/template/src/server/core/runtime.ts +129 -0
- package/template/src/server/core/typed-runtime.ts +80 -0
- package/template/src/server/db/__tests__/driver.test.ts +203 -0
- package/template/src/server/db/config.ts +1 -0
- package/template/src/server/db/driver-cloudflare.ts +50 -0
- package/template/src/server/db/driver.ts +116 -0
- package/template/src/server/db/index.ts +3 -0
- package/template/src/server/db/init.ts +412 -0
- package/template/src/server/db/schema/api-endpoints.ts +23 -0
- package/template/src/server/db/schema/contents.ts +31 -0
- package/template/src/server/db/schema/disputes.ts +39 -0
- package/template/src/server/db/schema/index.ts +14 -0
- package/template/src/server/db/schema/notifications.ts +16 -0
- package/template/src/server/db/schema/orders.ts +30 -0
- package/template/src/server/db/schema/permission-audit-logs.ts +17 -0
- package/template/src/server/db/schema/permission-route-mappings.ts +22 -0
- package/template/src/server/db/schema/permissions.ts +17 -0
- package/template/src/server/db/schema/role-permissions.ts +22 -0
- package/template/src/server/db/schema/roles.ts +17 -0
- package/template/src/server/db/schema/tickets.ts +62 -0
- package/template/src/server/db/schema/todo-attachments.ts +22 -0
- package/template/src/server/db/schema/todos.ts +21 -0
- package/template/src/server/db/schema/user-roles.ts +17 -0
- package/template/src/server/db/seeds/index.ts +1 -0
- package/template/src/server/db/seeds/permission-data.ts +354 -0
- package/template/src/server/db/test-setup.ts +647 -0
- package/template/src/server/entries/cloudflare.ts +71 -0
- package/template/src/server/entries/node.ts +190 -0
- package/template/src/server/index.ts +62 -0
- package/template/src/server/middleware/__tests__/auth-simple.test.ts +147 -0
- package/template/src/server/middleware/__tests__/auth.test.ts +276 -0
- package/template/src/server/middleware/__tests__/captcha.test.ts +258 -0
- package/template/src/server/middleware/__tests__/error-handler.test.ts +364 -0
- package/template/src/server/middleware/__tests__/error-response-format.test.ts +80 -0
- package/template/src/server/middleware/__tests__/permission.test.ts +312 -0
- package/template/src/server/middleware/audit-log.ts +101 -0
- package/template/src/server/middleware/auth.ts +235 -0
- package/template/src/server/middleware/captcha.ts +166 -0
- package/template/src/server/middleware/cors.ts +30 -0
- package/template/src/server/middleware/error-handler.ts +135 -0
- package/template/src/server/middleware/index.ts +24 -0
- package/template/src/server/middleware/logger.ts +73 -0
- package/template/src/server/middleware/permission.ts +127 -0
- package/template/src/server/middleware/rate-limit.ts +69 -0
- package/template/src/server/middleware/realtime-env.ts +12 -0
- package/template/src/server/module-admin/__tests__/admin-routes.test.ts +360 -0
- package/template/src/server/module-admin/__tests__/admin-service.test.ts +222 -0
- package/template/src/server/module-admin/__tests__/audit-log-routes.test.ts +261 -0
- package/template/src/server/module-admin/__tests__/export-routes.test.ts +160 -0
- package/template/src/server/module-admin/__tests__/media-routes.test.ts +122 -0
- package/template/src/server/module-admin/module.ts +40 -0
- package/template/src/server/module-admin/routes/admin-notification-routes.ts +197 -0
- package/template/src/server/module-admin/routes/admin-routes.ts +20 -0
- package/template/src/server/module-admin/routes/auth-routes.ts +86 -0
- package/template/src/server/module-admin/routes/export-routes.ts +207 -0
- package/template/src/server/module-admin/routes/media-routes.ts +78 -0
- package/template/src/server/module-admin/routes/system-routes.ts +89 -0
- package/template/src/server/module-admin/routes/user-management-routes.ts +143 -0
- package/template/src/server/module-admin/services/admin-service.ts +268 -0
- package/template/src/server/module-captcha/__tests__/captcha-route.test.ts +35 -0
- package/template/src/server/module-captcha/__tests__/captcha-service.test.ts +53 -0
- package/template/src/server/module-captcha/module.ts +35 -0
- package/template/src/server/module-captcha/routes/captcha-routes.ts +68 -0
- package/template/src/server/module-captcha/services/captcha-service.ts +3 -0
- package/template/src/server/module-chat/__tests__/chat-routes.test.ts +39 -0
- package/template/src/server/module-chat/__tests__/chat-rpc.test.ts +185 -0
- package/template/src/server/module-chat/__tests__/chat-service.test.ts +64 -0
- package/template/src/server/module-chat/module.ts +27 -0
- package/template/src/server/module-chat/routes/chat-routes.ts +46 -0
- package/template/src/server/module-chat/services/chat-service.ts +38 -0
- package/template/src/server/module-content/__tests__/content-route.test.ts +40 -0
- package/template/src/server/module-content/__tests__/content-service.test.ts +107 -0
- package/template/src/server/module-content/module.ts +39 -0
- package/template/src/server/module-content/routes/content-routes.ts +182 -0
- package/template/src/server/module-content/routes/public-content-routes.ts +58 -0
- package/template/src/server/module-content/services/content-service.ts +224 -0
- package/template/src/server/module-dispute/__tests__/dispute-route.test.ts +43 -0
- package/template/src/server/module-dispute/__tests__/dispute-service.test.ts +135 -0
- package/template/src/server/module-dispute/module.ts +30 -0
- package/template/src/server/module-dispute/routes/dispute-routes.ts +153 -0
- package/template/src/server/module-dispute/services/dispute-service.ts +255 -0
- package/template/src/server/module-file/__tests__/file-routes.test.ts +284 -0
- package/template/src/server/module-file/__tests__/file-storage-service.test.ts +323 -0
- package/template/src/server/module-file/module.ts +28 -0
- package/template/src/server/module-file/routes/file-routes.ts +288 -0
- package/template/src/server/module-notifications/__tests__/notification-route-rpc.test.ts +375 -0
- package/template/src/server/module-notifications/__tests__/notification-service.test.ts +241 -0
- package/template/src/server/module-notifications/__tests__/sse-rpc.test.ts +289 -0
- package/template/src/server/module-notifications/module.ts +32 -0
- package/template/src/server/module-notifications/routes/notification-routes.ts +190 -0
- package/template/src/server/module-notifications/services/notification-service.ts +104 -0
- package/template/src/server/module-order/__tests__/order-route.test.ts +258 -0
- package/template/src/server/module-order/__tests__/order-service.test.ts +222 -0
- package/template/src/server/module-order/module.ts +30 -0
- package/template/src/server/module-order/routes/order-routes.ts +202 -0
- package/template/src/server/module-order/services/order-service.ts +268 -0
- package/template/src/server/module-permission/__tests__/permission-middleware.test.ts +90 -0
- package/template/src/server/module-permission/__tests__/permission-routes.test.ts +330 -0
- package/template/src/server/module-permission/__tests__/permission-service-impl.test.ts +388 -0
- package/template/src/server/module-permission/__tests__/permission-service.test.ts +190 -0
- package/template/src/server/module-permission/__tests__/role-routes.test.ts +215 -0
- package/template/src/server/module-permission/module.ts +68 -0
- package/template/src/server/module-permission/routes/audit-log-routes.ts +76 -0
- package/template/src/server/module-permission/routes/permission-routes.ts +184 -0
- package/template/src/server/module-permission/routes/role-routes.ts +263 -0
- package/template/src/server/module-permission/services/audit-log-service.ts +108 -0
- package/template/src/server/module-permission/services/permission-service-impl.ts +233 -0
- package/template/src/server/module-permission/services/permission-service.ts +256 -0
- package/template/src/server/module-permission/services/role-service.ts +122 -0
- package/template/src/server/module-ticket/__tests__/ticket-route.test.ts +173 -0
- package/template/src/server/module-ticket/__tests__/ticket-service.test.ts +201 -0
- package/template/src/server/module-ticket/module.ts +30 -0
- package/template/src/server/module-ticket/routes/ticket-routes.ts +210 -0
- package/template/src/server/module-ticket/services/ticket-service.ts +297 -0
- package/template/src/server/module-todos/__tests__/todo-service.test.ts +196 -0
- package/template/src/server/module-todos/__tests__/todos-file-upload.test.ts +439 -0
- package/template/src/server/module-todos/__tests__/todos-route-rpc.test.ts +575 -0
- package/template/src/server/module-todos/module.ts +30 -0
- package/template/src/server/module-todos/routes/todos-routes.ts +260 -0
- package/template/src/server/module-todos/services/todo-service.ts +202 -0
- package/template/src/server/route-registry.ts +47 -0
- package/template/src/server/test-utils/test-client.ts +66 -0
- package/template/src/server/test-utils/test-server.ts +131 -0
- package/template/src/server/types/bindings.ts +10 -0
- package/template/src/server/utils/__tests__/app-error.test.ts +374 -0
- package/template/src/server/utils/__tests__/auth.test.ts +76 -0
- package/template/src/server/utils/__tests__/captcha.test.ts +80 -0
- package/template/src/server/utils/__tests__/file-storage.test.ts +472 -0
- package/template/src/server/utils/__tests__/logger.test.ts +221 -0
- package/template/src/server/utils/__tests__/route-helpers.test.ts +264 -0
- package/template/src/server/utils/app-error.ts +355 -0
- package/template/src/server/utils/auth.ts +65 -0
- package/template/src/server/utils/captcha.ts +119 -0
- package/template/src/server/utils/date.ts +50 -0
- package/template/src/server/utils/env.ts +4 -0
- package/template/src/server/utils/file-storage.ts +462 -0
- package/template/src/server/utils/generate.ts +26 -0
- package/template/src/server/utils/id-helpers.ts +5 -0
- package/template/src/server/utils/logger.ts +139 -0
- package/template/src/server/utils/permission-utils.ts +6 -0
- package/template/src/server/utils/response.ts +40 -0
- package/template/src/server/utils/route-helpers.ts +200 -0
- package/template/src/server/utils/uuid.ts +8 -0
- package/template/src/server/utils/ws-helper.ts +30 -0
- package/template/src/shared/constants/index.ts +1 -0
- package/template/src/shared/constants/resource-types.ts +72 -0
- package/template/src/shared/core/__tests__/sse-client.test.ts +376 -0
- package/template/src/shared/core/__tests__/ws-client.test.ts +468 -0
- package/template/src/shared/core/api-request.ts +192 -0
- package/template/src/shared/core/api-schemas.ts +41 -0
- package/template/src/shared/core/index.ts +37 -0
- package/template/src/shared/core/module-manifest.ts +120 -0
- package/template/src/shared/core/protocol-types.ts +26 -0
- package/template/src/shared/core/sse-client.ts +185 -0
- package/template/src/shared/core/ws-client.ts +236 -0
- package/template/src/shared/hooks/index.ts +2 -0
- package/template/src/shared/hooks/useSSE.ts +57 -0
- package/template/src/shared/hooks/useWebSocket.ts +66 -0
- package/template/src/shared/index.ts +5 -0
- package/template/src/shared/modules/admin/index.ts +1 -0
- package/template/src/shared/modules/admin/schemas.ts +100 -0
- package/template/src/shared/modules/audit/index.ts +1 -0
- package/template/src/shared/modules/audit/schemas.ts +24 -0
- package/template/src/shared/modules/captcha/index.ts +1 -0
- package/template/src/shared/modules/captcha/schemas.ts +19 -0
- package/template/src/shared/modules/chat/index.ts +38 -0
- package/template/src/shared/modules/content/index.ts +1 -0
- package/template/src/shared/modules/content/schemas.ts +53 -0
- package/template/src/shared/modules/dispute/index.ts +1 -0
- package/template/src/shared/modules/dispute/schemas.ts +62 -0
- package/template/src/shared/modules/files/index.ts +11 -0
- package/template/src/shared/modules/files/schemas.ts +44 -0
- package/template/src/shared/modules/index.ts +70 -0
- package/template/src/shared/modules/notifications/index.ts +26 -0
- package/template/src/shared/modules/notifications/schemas.ts +73 -0
- package/template/src/shared/modules/order/index.ts +1 -0
- package/template/src/shared/modules/order/schemas.ts +63 -0
- package/template/src/shared/modules/permission/index.ts +42 -0
- package/template/src/shared/modules/permission/permission-dependencies.ts +50 -0
- package/template/src/shared/modules/permission/permissions.ts +275 -0
- package/template/src/shared/modules/permission/schemas.ts +92 -0
- package/template/src/shared/modules/permission/types.ts +23 -0
- package/template/src/shared/modules/role/index.ts +1 -0
- package/template/src/shared/modules/role/schemas.ts +46 -0
- package/template/src/shared/modules/ticket/index.ts +1 -0
- package/template/src/shared/modules/ticket/schemas.ts +77 -0
- package/template/src/shared/modules/todos/index.ts +20 -0
- package/template/src/shared/modules/todos/schemas.ts +65 -0
- package/template/src/shared/schemas/index.ts +79 -0
- package/template/src/types/global.d.ts +14 -0
- package/template/src/vite-env.d.ts +21 -0
- package/template/tailwind.config.js +11 -0
- package/template/tests/e2e/admin-crud.spec.ts +81 -0
- package/template/tests/e2e/case-o1.spec.ts +108 -0
- package/template/tests/e2e/global-setup.ts +73 -0
- package/template/tests/e2e/global-teardown.ts +28 -0
- package/template/tests/e2e/notification.spec.ts +458 -0
- package/template/tests/e2e/todo.spec.ts +623 -0
- package/template/tests/e2e/websocket.spec.ts +254 -0
- package/template/tsconfig.json +35 -0
- package/template/tsup.config.ts +95 -0
- package/template/vite-plugins.ts +113 -0
- package/template/vite.config.ts +96 -0
- package/template/vitest.config.ts +53 -0
- package/template/vitest.integration.config.ts +24 -0
- package/template/vitest.integration.setup.ts +22 -0
- package/template/vitest.setup.ts +74 -0
- package/template/wrangler.toml +33 -0
|
@@ -0,0 +1,355 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* API 覆盖率验证器
|
|
3
|
+
*
|
|
4
|
+
* 检查:
|
|
5
|
+
* 1. 每个 createRoute 定义的 API 是否有对应的测试
|
|
6
|
+
* 2. 每个服务层导出的函数是否有对应的测试
|
|
7
|
+
*
|
|
8
|
+
* 路由 -> 测试映射:
|
|
9
|
+
* - getAllRolesRoute -> test("get all roles")
|
|
10
|
+
* - getPermissionsRoute -> test("get all permissions")
|
|
11
|
+
* - getUserPermissionsRoute -> test("get user permissions")
|
|
12
|
+
*
|
|
13
|
+
* 服务函数 -> 测试映射:
|
|
14
|
+
* - getAllRoles() -> test("get all roles")
|
|
15
|
+
* - getAllPermissions() -> test("get all permissions")
|
|
16
|
+
* - getUserPermissions() -> test("get user permissions")
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import { readFileSync, readdirSync, existsSync } from 'node:fs'
|
|
20
|
+
import { join, relative } from 'node:path'
|
|
21
|
+
import type { ModuleTestsConfig, ModuleTestError } from './index.js'
|
|
22
|
+
import { minimatch } from 'minimatch'
|
|
23
|
+
|
|
24
|
+
interface Route {
|
|
25
|
+
name: string
|
|
26
|
+
path: string
|
|
27
|
+
method: string
|
|
28
|
+
line: number
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
interface ServiceFunction {
|
|
32
|
+
name: string
|
|
33
|
+
line: number
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
interface TestCase {
|
|
37
|
+
name: string
|
|
38
|
+
file: string
|
|
39
|
+
line: number
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
interface CoverageResult {
|
|
43
|
+
module: string
|
|
44
|
+
uncoveredRoutes: Route[]
|
|
45
|
+
uncoveredFunctions: ServiceFunction[]
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// 解析路由文件,提取所有 createRoute 定义
|
|
49
|
+
function parseRoutes(filePath: string): Route[] {
|
|
50
|
+
const content = readFileSync(filePath, 'utf-8')
|
|
51
|
+
const routes: Route[] = []
|
|
52
|
+
const lines = content.split('\n')
|
|
53
|
+
|
|
54
|
+
for (let i = 0; i < lines.length; i++) {
|
|
55
|
+
const line = lines[i]
|
|
56
|
+
|
|
57
|
+
// 匹配 const xxxRoute = createRoute({
|
|
58
|
+
const routeMatch = line.match(/const\s+(\w+Route)\s*=\s*createRoute/)
|
|
59
|
+
if (routeMatch) {
|
|
60
|
+
const routeName = routeMatch[1]
|
|
61
|
+
let method = ''
|
|
62
|
+
let path = ''
|
|
63
|
+
|
|
64
|
+
// 向下查找 method 和 path
|
|
65
|
+
for (let j = i; j < Math.min(i + 20, lines.length); j++) {
|
|
66
|
+
const methodMatch = lines[j].match(/method:\s*['"](\w+)['"]/)
|
|
67
|
+
if (methodMatch) {
|
|
68
|
+
method = methodMatch[1]
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const pathMatch = lines[j].match(/path:\s*['"]([^'"]+)['"]/)
|
|
72
|
+
if (pathMatch) {
|
|
73
|
+
path = pathMatch[1]
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (method && path) {
|
|
77
|
+
break
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (routeName && path) {
|
|
82
|
+
routes.push({ name: routeName, path, method: method || 'get', line: i + 1 })
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return routes
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// 解析服务文件,提取所有导出的函数
|
|
91
|
+
function parseServiceFunctions(filePath: string): ServiceFunction[] {
|
|
92
|
+
const content = readFileSync(filePath, 'utf-8')
|
|
93
|
+
const functions: ServiceFunction[] = []
|
|
94
|
+
const lines = content.split('\n')
|
|
95
|
+
|
|
96
|
+
for (let i = 0; i < lines.length; i++) {
|
|
97
|
+
const line = lines[i]
|
|
98
|
+
|
|
99
|
+
// 匹配 export function xxx() 或 export const xxx =
|
|
100
|
+
const funcMatch = line.match(/export\s+(?:function\s+(\w+)|const\s+(\w+)\s*=\s*(?:async\s+)?\()/)
|
|
101
|
+
if (funcMatch) {
|
|
102
|
+
const funcName = funcMatch[1] || funcMatch[2]
|
|
103
|
+
|
|
104
|
+
if (funcName) {
|
|
105
|
+
// 排除类型导出和测试辅助函数
|
|
106
|
+
if (!funcName.startsWith('type') && !funcName.includes('Test') && !funcName.includes('Mock')) {
|
|
107
|
+
functions.push({ name: funcName, line: i + 1 })
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return functions
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// 解析测试文件,提取所有测试用例名称
|
|
117
|
+
function parseTestCases(filePath: string): TestCase[] {
|
|
118
|
+
const content = readFileSync(filePath, 'utf-8')
|
|
119
|
+
const tests: TestCase[] = []
|
|
120
|
+
const lines = content.split('\n')
|
|
121
|
+
|
|
122
|
+
for (let i = 0; i < lines.length; i++) {
|
|
123
|
+
const line = lines[i]
|
|
124
|
+
|
|
125
|
+
// 匹配 it('xxx', ...) 或 test('xxx', ...) 或 describe('xxx', ...)
|
|
126
|
+
const testMatch = line.match(/(?:it|test|describe)\s*\(\s*['"]([^'"]+)['"]/)
|
|
127
|
+
if (testMatch) {
|
|
128
|
+
const testName = testMatch[1].toLowerCase()
|
|
129
|
+
|
|
130
|
+
tests.push({
|
|
131
|
+
name: testName,
|
|
132
|
+
file: filePath,
|
|
133
|
+
line: i + 1,
|
|
134
|
+
})
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
return tests
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// 检查路由是否有对应的测试
|
|
142
|
+
function isRouteCovered(route: Route, testCases: TestCase[]): boolean {
|
|
143
|
+
const routeKeywords = [
|
|
144
|
+
route.name.replace('Route', '').toLowerCase(),
|
|
145
|
+
route.path.replace(/\/:id|\/:[^/]+/g, '').toLowerCase(),
|
|
146
|
+
route.method.toLowerCase(),
|
|
147
|
+
]
|
|
148
|
+
|
|
149
|
+
for (const test of testCases) {
|
|
150
|
+
const testName = test.name
|
|
151
|
+
|
|
152
|
+
// 检查测试名称是否包含路由关键词
|
|
153
|
+
for (const keyword of routeKeywords) {
|
|
154
|
+
// 移除特殊字符进行比较
|
|
155
|
+
const cleanKeyword = keyword.replace(/[^a-z0-9]/g, '')
|
|
156
|
+
const cleanTestName = testName.replace(/[^a-z0-9]/g, '')
|
|
157
|
+
|
|
158
|
+
if (cleanTestName.includes(cleanKeyword) && cleanKeyword.length > 2) {
|
|
159
|
+
return true
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
return false
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// 检查服务函数是否有对应的测试
|
|
168
|
+
function isFunctionCovered(func: ServiceFunction, testCases: TestCase[]): boolean {
|
|
169
|
+
const funcKeywords = [
|
|
170
|
+
func.name.toLowerCase(),
|
|
171
|
+
// 移除常见前缀/后缀
|
|
172
|
+
func.name.replace(/^(get|create|update|delete|find|fetch)/i, '').toLowerCase(),
|
|
173
|
+
]
|
|
174
|
+
|
|
175
|
+
for (const test of testCases) {
|
|
176
|
+
const testName = test.name
|
|
177
|
+
|
|
178
|
+
for (const keyword of funcKeywords) {
|
|
179
|
+
const cleanKeyword = keyword.replace(/[^a-z0-9]/g, '')
|
|
180
|
+
const cleanTestName = testName.replace(/[^a-z0-9]/g, '')
|
|
181
|
+
|
|
182
|
+
if (cleanTestName.includes(cleanKeyword) && cleanKeyword.length > 2) {
|
|
183
|
+
return true
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
return false
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// 查找模块的测试文件
|
|
192
|
+
function findTestFiles(modulePath: string, testsDir: string): string[] {
|
|
193
|
+
const testFiles: string[] = []
|
|
194
|
+
const fullTestsDir = join(modulePath, testsDir)
|
|
195
|
+
|
|
196
|
+
if (!existsSync(fullTestsDir)) {
|
|
197
|
+
return testFiles
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
const entries = readdirSync(fullTestsDir, { withFileTypes: true })
|
|
201
|
+
|
|
202
|
+
for (const entry of entries) {
|
|
203
|
+
if (entry.isFile() && (entry.name.endsWith('.test.ts') || entry.name.endsWith('.spec.ts'))) {
|
|
204
|
+
testFiles.push(join(fullTestsDir, entry.name))
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
return testFiles
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
// 检查模块的 API 覆盖率
|
|
212
|
+
function checkModuleCoverage(modulePath: string, testsDir: string): CoverageResult {
|
|
213
|
+
const moduleName = relative(process.cwd(), modulePath)
|
|
214
|
+
const uncoveredRoutes: Route[] = []
|
|
215
|
+
const uncoveredFunctions: ServiceFunction[] = []
|
|
216
|
+
|
|
217
|
+
// 查找路由文件
|
|
218
|
+
const routesDir = join(modulePath, 'routes')
|
|
219
|
+
let routes: Route[] = []
|
|
220
|
+
|
|
221
|
+
if (existsSync(routesDir)) {
|
|
222
|
+
const routeFiles = readdirSync(routesDir).filter(f => f.endsWith('.ts'))
|
|
223
|
+
|
|
224
|
+
for (const routeFile of routeFiles) {
|
|
225
|
+
const filePath = join(routesDir, routeFile)
|
|
226
|
+
routes = routes.concat(parseRoutes(filePath))
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
// 查找服务文件
|
|
231
|
+
const servicesDir = join(modulePath, 'services')
|
|
232
|
+
let functions: ServiceFunction[] = []
|
|
233
|
+
|
|
234
|
+
if (existsSync(servicesDir)) {
|
|
235
|
+
const serviceFiles = readdirSync(servicesDir).filter(f => f.endsWith('-service.ts') || f.endsWith('.ts'))
|
|
236
|
+
|
|
237
|
+
for (const serviceFile of serviceFiles) {
|
|
238
|
+
const filePath = join(servicesDir, serviceFile)
|
|
239
|
+
functions = functions.concat(parseServiceFunctions(filePath))
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
// 收集所有测试用例
|
|
244
|
+
const testFiles = findTestFiles(modulePath, testsDir)
|
|
245
|
+
const allTestCases: TestCase[] = []
|
|
246
|
+
|
|
247
|
+
for (const testFile of testFiles) {
|
|
248
|
+
allTestCases.push(...parseTestCases(testFile))
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
// 检查路由覆盖率
|
|
252
|
+
for (const route of routes) {
|
|
253
|
+
if (!isRouteCovered(route, allTestCases)) {
|
|
254
|
+
uncoveredRoutes.push(route)
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
// 检查函数覆盖率
|
|
259
|
+
for (const func of functions) {
|
|
260
|
+
if (!isFunctionCovered(func, allTestCases)) {
|
|
261
|
+
uncoveredFunctions.push(func)
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
return {
|
|
266
|
+
module: moduleName,
|
|
267
|
+
uncoveredRoutes,
|
|
268
|
+
uncoveredFunctions,
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
export function validateAPICoverage(config: ModuleTestsConfig, rootPath: string): ModuleTestError[] {
|
|
273
|
+
const errors: ModuleTestError[] = []
|
|
274
|
+
const modules: string[] = []
|
|
275
|
+
|
|
276
|
+
// 查找所有模块
|
|
277
|
+
function scanDir(dir: string) {
|
|
278
|
+
if (!existsSync(dir)) return
|
|
279
|
+
|
|
280
|
+
const entries = readdirSync(dir, { withFileTypes: true })
|
|
281
|
+
|
|
282
|
+
for (const entry of entries) {
|
|
283
|
+
const fullPath = join(dir, entry.name)
|
|
284
|
+
|
|
285
|
+
if (entry.isDirectory()) {
|
|
286
|
+
if (minimatch(entry.name, config.modulePattern)) {
|
|
287
|
+
modules.push(fullPath)
|
|
288
|
+
} else if (!config.ignoreDirs.includes(entry.name)) {
|
|
289
|
+
scanDir(fullPath)
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
for (const checkDir of config.checkDirs) {
|
|
296
|
+
scanDir(join(rootPath, checkDir))
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
// 检查每个模块的覆盖率
|
|
300
|
+
for (const modulePath of modules) {
|
|
301
|
+
const coverage = checkModuleCoverage(modulePath, config.testsDir)
|
|
302
|
+
|
|
303
|
+
const missing: string[] = []
|
|
304
|
+
|
|
305
|
+
if (coverage.uncoveredRoutes.length > 0) {
|
|
306
|
+
missing.push(
|
|
307
|
+
`${coverage.uncoveredRoutes.length} uncovered route(s): ${coverage.uncoveredRoutes.map(r => r.name).join(', ')}`
|
|
308
|
+
)
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
if (coverage.uncoveredFunctions.length > 0) {
|
|
312
|
+
missing.push(
|
|
313
|
+
`${coverage.uncoveredFunctions.length} uncovered function(s): ${coverage.uncoveredFunctions.map(f => f.name).join(', ')}`
|
|
314
|
+
)
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
if (missing.length > 0) {
|
|
318
|
+
errors.push({
|
|
319
|
+
module: coverage.module,
|
|
320
|
+
missingTests: missing,
|
|
321
|
+
suggestion: `添加缺失的测试用例覆盖以下路由和函数`,
|
|
322
|
+
})
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
return errors
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
export function formatAPICoverageErrors(errors: ModuleTestError[]): string {
|
|
330
|
+
if (errors.length === 0) return ''
|
|
331
|
+
|
|
332
|
+
let output = `❌ Found API coverage issues:\n\n`
|
|
333
|
+
|
|
334
|
+
for (const err of errors) {
|
|
335
|
+
output += ` 📁 ${err.module}\n`
|
|
336
|
+
|
|
337
|
+
for (const issue of err.missingTests) {
|
|
338
|
+
output += ` ${issue}\n`
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
output += ` Suggestion: ${err.suggestion}\n\n`
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
output += `📋 How to fix:\n\n`
|
|
345
|
+
output += ` 1. 确保每个 createRoute 都有对应的测试用例\n`
|
|
346
|
+
output += ` 2. 确保每个导出的服务函数都有对应的测试用例\n`
|
|
347
|
+
output += ` 3. 测试名称应该包含被测对象的关键词\n\n`
|
|
348
|
+
output += ` 示例:\n`
|
|
349
|
+
output += ` // 路由: getAllRolesRoute (path: /permissions/roles)\n`
|
|
350
|
+
output += ` it('should get all roles') // ✅ 匹配\n`
|
|
351
|
+
output += ` it('get roles') // ✅ 匹配\n`
|
|
352
|
+
output += ` it('fetch roles') // ✅ 匹配\n\n`
|
|
353
|
+
|
|
354
|
+
return output
|
|
355
|
+
}
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 客户端 RPC 调用验证器
|
|
3
|
+
*
|
|
4
|
+
* 检查客户端代码是否符合 API 调用规范:
|
|
5
|
+
* 1. 必须使用 apiClient 进行 API 调用
|
|
6
|
+
* 2. 必须使用类型安全的方法($get, $post, $ws, $sse 等)
|
|
7
|
+
* 3. 禁止直接使用 fetch 调用内部 API
|
|
8
|
+
* 4. 禁止直接使用 WebSocket/EventSource
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { readFileSync, readdirSync, existsSync } from 'node:fs'
|
|
12
|
+
import { join, relative } from 'node:path'
|
|
13
|
+
import type { ClientRPCConfig, ClientRPCError } from './index.js'
|
|
14
|
+
|
|
15
|
+
export function validateClientRPCInFile(
|
|
16
|
+
filePath: string,
|
|
17
|
+
rootPath: string,
|
|
18
|
+
config: ClientRPCConfig,
|
|
19
|
+
fileContent?: string
|
|
20
|
+
): ClientRPCError[] {
|
|
21
|
+
const content = fileContent || readFileSync(filePath, 'utf-8')
|
|
22
|
+
const errors: ClientRPCError[] = []
|
|
23
|
+
|
|
24
|
+
if (config.forbidDirectFetch) {
|
|
25
|
+
const fetchPattern = /(?:await\s+)?fetch\s*\(\s*['"`](\/api\/|\/ws\/)/g
|
|
26
|
+
let match
|
|
27
|
+
while ((match = fetchPattern.exec(content)) !== null) {
|
|
28
|
+
const lineNumber = content.substring(0, match.index).split('\n').length
|
|
29
|
+
const matchedText = match[0]
|
|
30
|
+
|
|
31
|
+
errors.push({
|
|
32
|
+
file: relative(rootPath, filePath),
|
|
33
|
+
line: lineNumber,
|
|
34
|
+
message: `Direct fetch() call to internal API detected: ${matchedText}`,
|
|
35
|
+
suggestion: `Use apiClient instead: apiClient.api.todos.$get()`,
|
|
36
|
+
})
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (config.requireAPIClient) {
|
|
41
|
+
const hasAPIClientImport =
|
|
42
|
+
/import\s+.*apiClient.*from\s+['"]@client\/services\/apiClient['"]/.test(content)
|
|
43
|
+
const hasAPIClientUsage = /apiClient\s*\.\s*api\s*\./.test(content)
|
|
44
|
+
|
|
45
|
+
const hasAPIPathUsage = /['"`](\/api\/\w+)['"`]/.test(content)
|
|
46
|
+
|
|
47
|
+
if (hasAPIPathUsage && !hasAPIClientImport && !hasAPIClientUsage) {
|
|
48
|
+
const lineNumber = content.split('\n').findIndex(line => /['"`]\/api\//.test(line)) + 1
|
|
49
|
+
errors.push({
|
|
50
|
+
file: relative(rootPath, filePath),
|
|
51
|
+
line: lineNumber || 1,
|
|
52
|
+
message: 'API path detected but apiClient is not used',
|
|
53
|
+
suggestion: `Import and use apiClient: import { apiClient } from '@client/services/apiClient'`,
|
|
54
|
+
})
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (config.requireAPIClient) {
|
|
59
|
+
const nonTypeSafePattern = /apiClient\s*\.\s*api\s*\.\s*\w+\s*\(\s*\)/g
|
|
60
|
+
let match
|
|
61
|
+
while ((match = nonTypeSafePattern.exec(content)) !== null) {
|
|
62
|
+
const matchedText = match[0]
|
|
63
|
+
if (!matchedText.includes('$')) {
|
|
64
|
+
const lineNumber = content.substring(0, match.index).split('\n').length
|
|
65
|
+
errors.push({
|
|
66
|
+
file: relative(rootPath, filePath),
|
|
67
|
+
line: lineNumber,
|
|
68
|
+
message: `Non-type-safe API method call: ${matchedText}`,
|
|
69
|
+
suggestion: `Use type-safe method with $ prefix: apiClient.api.todos.$get()`,
|
|
70
|
+
})
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (config.forbidDirectWebSocket !== false) {
|
|
76
|
+
const wsPattern = /new\s+WebSocket\s*\(/g
|
|
77
|
+
let match
|
|
78
|
+
while ((match = wsPattern.exec(content)) !== null) {
|
|
79
|
+
const lineNumber = content.substring(0, match.index).split('\n').length
|
|
80
|
+
errors.push({
|
|
81
|
+
file: relative(rootPath, filePath),
|
|
82
|
+
line: lineNumber,
|
|
83
|
+
message: 'Direct new WebSocket() is not allowed',
|
|
84
|
+
suggestion: `Use type-safe $ws() method: apiClient.api.chat.ws.$ws()`,
|
|
85
|
+
})
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (config.forbidDirectEventSource !== false) {
|
|
90
|
+
const isImplementationFile =
|
|
91
|
+
filePath.endsWith('wsClient.ts') ||
|
|
92
|
+
filePath.endsWith('sseClient.ts') ||
|
|
93
|
+
filePath.includes('/services/wsClient.ts') ||
|
|
94
|
+
filePath.includes('/services/sseClient.ts')
|
|
95
|
+
|
|
96
|
+
if (!isImplementationFile) {
|
|
97
|
+
const ssePattern = /new\s+EventSource\s*\(/g
|
|
98
|
+
let match
|
|
99
|
+
while ((match = ssePattern.exec(content)) !== null) {
|
|
100
|
+
const lineNumber = content.substring(0, match.index).split('\n').length
|
|
101
|
+
errors.push({
|
|
102
|
+
file: relative(rootPath, filePath),
|
|
103
|
+
line: lineNumber,
|
|
104
|
+
message: 'Direct new EventSource() is not allowed',
|
|
105
|
+
suggestion: `Use type-safe $sse() method: await apiClient.api.notifications.stream.$sse()`,
|
|
106
|
+
})
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
return errors
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function scanDirectory(
|
|
115
|
+
rootPath: string,
|
|
116
|
+
targetDir: string,
|
|
117
|
+
config: ClientRPCConfig
|
|
118
|
+
): ClientRPCError[] {
|
|
119
|
+
const errors: ClientRPCError[] = []
|
|
120
|
+
const targetPath = join(rootPath, targetDir)
|
|
121
|
+
|
|
122
|
+
if (!existsSync(targetPath)) {
|
|
123
|
+
return errors
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function scanDir(dir: string) {
|
|
127
|
+
const entries = readdirSync(dir, { withFileTypes: true })
|
|
128
|
+
|
|
129
|
+
for (const entry of entries) {
|
|
130
|
+
const fullPath = join(dir, entry.name)
|
|
131
|
+
|
|
132
|
+
if (entry.isDirectory()) {
|
|
133
|
+
if (!config.ignoreDirs.includes(entry.name)) {
|
|
134
|
+
scanDir(fullPath)
|
|
135
|
+
}
|
|
136
|
+
} else if (entry.isFile() && (entry.name.endsWith('.ts') || entry.name.endsWith('.tsx'))) {
|
|
137
|
+
const fileErrors = validateClientRPCInFile(fullPath, rootPath, config)
|
|
138
|
+
errors.push(...fileErrors)
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
scanDir(targetPath)
|
|
144
|
+
return errors
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export function validateClientRPC(config: ClientRPCConfig, rootPath: string): ClientRPCError[] {
|
|
148
|
+
const allErrors: ClientRPCError[] = []
|
|
149
|
+
|
|
150
|
+
for (const dir of config.checkDirs) {
|
|
151
|
+
const errors = scanDirectory(rootPath, dir, config)
|
|
152
|
+
allErrors.push(...errors)
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
return allErrors
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
export function formatClientRPCErrors(errors: ClientRPCError[]): string {
|
|
159
|
+
if (errors.length === 0) return ''
|
|
160
|
+
|
|
161
|
+
let output = `❌ Found ${errors.length} client RPC usage error(s):\n\n`
|
|
162
|
+
|
|
163
|
+
for (const err of errors) {
|
|
164
|
+
output += ` ${err.file}:${err.line}\n`
|
|
165
|
+
output += ` Error: ${err.message}\n`
|
|
166
|
+
output += ` Suggestion: ${err.suggestion}\n\n`
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
output += '📋 Client RPC Guidelines:\n'
|
|
170
|
+
output += ' ✅ DO: Use apiClient with type-safe methods\n'
|
|
171
|
+
output += " import { apiClient } from '@client/services/apiClient'\n"
|
|
172
|
+
output += ' const response = await apiClient.api.todos.$get()\n'
|
|
173
|
+
output += ' const result = await response.json()\n\n'
|
|
174
|
+
output += ' ✅ DO: Use $ws() for WebSocket\n'
|
|
175
|
+
output += ' const ws = apiClient.api.chat.ws.$ws()\n'
|
|
176
|
+
output += ' const result = await ws.call("echo", { message: "hello" })\n\n'
|
|
177
|
+
output += ' ✅ DO: Use $sse() for SSE\n'
|
|
178
|
+
output += ' const conn = await apiClient.api.notifications.stream.$sse()\n'
|
|
179
|
+
output += ' conn.on("notification", (n) => { ... })\n\n'
|
|
180
|
+
output += " ❌ DON'T: Use direct fetch for internal APIs\n"
|
|
181
|
+
output += " const response = await fetch('/api/todos')\n\n"
|
|
182
|
+
output += " ❌ DON'T: Use non-type-safe methods\n"
|
|
183
|
+
output += ' apiClient.api.todos() // Missing $ prefix\n\n'
|
|
184
|
+
output += " ❌ DON'T: Use direct WebSocket/EventSource\n"
|
|
185
|
+
output += ' new WebSocket(...) // Use $ws() instead\n'
|
|
186
|
+
output += ' new EventSource(...) // Use $sse() instead\n\n'
|
|
187
|
+
output += ' 📖 See: .claude/rules/client-service-rules.md\n'
|
|
188
|
+
|
|
189
|
+
return output
|
|
190
|
+
}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Client 测试覆盖验证器
|
|
3
|
+
*
|
|
4
|
+
* 检查 client 端文件是否有对应的测试文件:
|
|
5
|
+
* 1. components/*.tsx -> components/__tests__/*.test.tsx
|
|
6
|
+
* 2. pages/*.tsx -> pages/__tests__/*.test.tsx
|
|
7
|
+
* 3. stores/*.ts -> stores/__tests__/*.test.ts
|
|
8
|
+
* 4. hooks/*.ts -> hooks/__tests__/*.test.ts
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { readdirSync, existsSync } from 'node:fs'
|
|
12
|
+
import { join, relative, dirname, basename } from 'node:path'
|
|
13
|
+
import type { ClientTestsConfig, ClientTestError, ClientTestRule } from './index.js'
|
|
14
|
+
import { minimatch } from 'minimatch'
|
|
15
|
+
|
|
16
|
+
interface SourceFile {
|
|
17
|
+
path: string
|
|
18
|
+
relativePath: string
|
|
19
|
+
dir: string
|
|
20
|
+
name: string
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function findSourceFiles(rootPath: string, config: ClientTestsConfig): Map<string, SourceFile[]> {
|
|
24
|
+
const filesByRule = new Map<string, SourceFile[]>()
|
|
25
|
+
|
|
26
|
+
for (const rule of config.rules) {
|
|
27
|
+
filesByRule.set(rule.dir, [])
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function scanDir(dir: string) {
|
|
31
|
+
if (!existsSync(dir)) return
|
|
32
|
+
|
|
33
|
+
const entries = readdirSync(dir, { withFileTypes: true })
|
|
34
|
+
|
|
35
|
+
for (const entry of entries) {
|
|
36
|
+
const fullPath = join(dir, entry.name)
|
|
37
|
+
|
|
38
|
+
if (entry.isDirectory()) {
|
|
39
|
+
if (!config.ignoreDirs.includes(entry.name)) {
|
|
40
|
+
scanDir(fullPath)
|
|
41
|
+
}
|
|
42
|
+
} else if (entry.isFile()) {
|
|
43
|
+
const relativePath = relative(rootPath, fullPath)
|
|
44
|
+
const fileDir = dirname(relativePath)
|
|
45
|
+
const fileName = basename(entry.name)
|
|
46
|
+
|
|
47
|
+
if (config.ignoreFiles.some(pattern => minimatch(relativePath, pattern))) {
|
|
48
|
+
continue
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
for (const rule of config.rules) {
|
|
52
|
+
if (fileDir === rule.dir && minimatch(fileName, rule.filePattern)) {
|
|
53
|
+
const files = filesByRule.get(rule.dir) || []
|
|
54
|
+
files.push({
|
|
55
|
+
path: fullPath,
|
|
56
|
+
relativePath,
|
|
57
|
+
dir: rule.dir,
|
|
58
|
+
name: fileName,
|
|
59
|
+
})
|
|
60
|
+
filesByRule.set(rule.dir, files)
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
for (const checkDir of config.checkDirs) {
|
|
68
|
+
scanDir(join(rootPath, checkDir))
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return filesByRule
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function checkTestExists(sourceFile: SourceFile, rule: ClientTestRule, rootPath: string): boolean {
|
|
75
|
+
const testsDir = join(rootPath, rule.dir, '__tests__')
|
|
76
|
+
if (!existsSync(testsDir)) {
|
|
77
|
+
return false
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const testFiles = readdirSync(testsDir)
|
|
81
|
+
const baseName = sourceFile.name.replace(/\.(tsx?|jsx?)$/, '')
|
|
82
|
+
|
|
83
|
+
return testFiles.some(file => {
|
|
84
|
+
const testBaseName = file.replace(/\.test\.(tsx?|jsx?)$/, '')
|
|
85
|
+
return (
|
|
86
|
+
testBaseName === baseName || minimatch(file, rule.testPattern.replace('{name}', baseName))
|
|
87
|
+
)
|
|
88
|
+
})
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export function validateClientTests(
|
|
92
|
+
config: ClientTestsConfig,
|
|
93
|
+
rootPath: string
|
|
94
|
+
): ClientTestError[] {
|
|
95
|
+
const errors: ClientTestError[] = []
|
|
96
|
+
const filesByRule = findSourceFiles(rootPath, config)
|
|
97
|
+
|
|
98
|
+
for (const rule of config.rules) {
|
|
99
|
+
const files = filesByRule.get(rule.dir) || []
|
|
100
|
+
|
|
101
|
+
for (const file of files) {
|
|
102
|
+
const hasTest = checkTestExists(file, rule, rootPath)
|
|
103
|
+
|
|
104
|
+
if (!hasTest) {
|
|
105
|
+
const baseName = file.name.replace(/\.(tsx?|jsx?)$/, '')
|
|
106
|
+
errors.push({
|
|
107
|
+
file: file.relativePath,
|
|
108
|
+
expectedTest: `${rule.dir}/__tests__/${baseName}.test.tsx`,
|
|
109
|
+
suggestion: `为 ${file.relativePath} 添加测试文件: ${rule.dir}/__tests__/${baseName}.test.tsx`,
|
|
110
|
+
})
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return errors
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export function formatClientTestErrors(errors: ClientTestError[]): string {
|
|
119
|
+
if (errors.length === 0) return ''
|
|
120
|
+
|
|
121
|
+
let output = `❌ Found ${errors.length} client file(s) without tests:\n\n`
|
|
122
|
+
|
|
123
|
+
for (const err of errors) {
|
|
124
|
+
output += ` 📄 ${err.file}\n`
|
|
125
|
+
output += ` Expected test: ${err.expectedTest}\n`
|
|
126
|
+
output += ` Suggestion: ${err.suggestion}\n\n`
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
output += '📋 测试文件位置: src/client/{components,pages}/__tests__/*.test.tsx\n\n'
|
|
130
|
+
|
|
131
|
+
output += '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n'
|
|
132
|
+
output += '📚 测试规范文档\n'
|
|
133
|
+
output += '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n\n'
|
|
134
|
+
output += ' 📖 测试规范: .trae/rules/60-testing-standards.md\n'
|
|
135
|
+
output += ' 📖 组件规范: .trae/rules/30-client-components.md\n\n'
|
|
136
|
+
|
|
137
|
+
output += '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n'
|
|
138
|
+
output += '🎯 测试价值 & 快速上手\n'
|
|
139
|
+
output += '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n\n'
|
|
140
|
+
output += ' 💡 为什么测试?防止回归 | 文档作用 | 重构信心\n\n'
|
|
141
|
+
output += ' 📝 示例:\n'
|
|
142
|
+
output += " import { render, screen } from '@testing-library/react'\n"
|
|
143
|
+
output += " import { Button } from '../Button'\n"
|
|
144
|
+
output += ' \n'
|
|
145
|
+
output += " describe('Button', () => {\n"
|
|
146
|
+
output += " it('renders label', () => {\n"
|
|
147
|
+
output += ' render(<Button label="Click" onClick={() => {}} />)\n'
|
|
148
|
+
output += " expect(screen.getByText('Click')).toBeInTheDocument()\n"
|
|
149
|
+
output += ' })\n'
|
|
150
|
+
output += ' })\n\n'
|
|
151
|
+
|
|
152
|
+
output += ' 💡 提示: 测试用户行为而非实现细节 | Mock 外部依赖\n\n'
|
|
153
|
+
|
|
154
|
+
return output
|
|
155
|
+
}
|