create-huenei-template 0.2.7 → 0.2.8
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/dist/config/templates.js +7 -0
- package/dist/templates/README.md +7 -1
- package/dist/templates/backend/README.md +19 -9
- package/dist/templates/backend/nestjs-api-mysql/.cursor/agents/nestjs-code-reviewer.md +54 -0
- package/dist/templates/backend/nestjs-api-mysql/.cursor/agents/prisma-guardian.md +67 -0
- package/dist/templates/backend/nestjs-api-mysql/.cursor/agents/test-runner.md +57 -0
- package/dist/templates/backend/nestjs-api-mysql/.cursor/hooks/autoTestOnStop.ts +127 -0
- package/dist/templates/backend/nestjs-api-mysql/.cursor/hooks/blockDangerous.ts +98 -0
- package/dist/templates/backend/nestjs-api-mysql/.cursor/hooks/ensureTestsExist.ts +405 -0
- package/dist/templates/backend/nestjs-api-mysql/.cursor/hooks/formatOnEdit.ts +70 -0
- package/dist/templates/backend/nestjs-api-mysql/.cursor/hooks/protectSecrets.ts +101 -0
- package/dist/templates/backend/nestjs-api-mysql/.cursor/hooks/sessionInit.ts +104 -0
- package/dist/templates/backend/nestjs-api-mysql/.cursor/hooks/validatePrisma.ts +121 -0
- package/dist/templates/backend/nestjs-api-mysql/.cursor/hooks.json +46 -0
- package/dist/templates/backend/nestjs-api-mysql/README.md +26 -0
- package/dist/templates/backend/nestjs-api-mysql/eslint.config.mjs +1 -1
- package/dist/templates/backend/nestjs-api-mysql/package.json +7 -7
- package/dist/templates/backend/nestjs-api-postgres/.cursor/agents/nestjs-code-reviewer.md +54 -0
- package/dist/templates/backend/nestjs-api-postgres/.cursor/agents/prisma-guardian.md +62 -0
- package/dist/templates/backend/nestjs-api-postgres/.cursor/agents/security-auditor.md +71 -0
- package/dist/templates/backend/nestjs-api-postgres/.cursor/agents/test-runner.md +58 -0
- package/dist/templates/backend/nestjs-api-postgres/.cursor/hooks/auto-retry.ts +62 -0
- package/dist/templates/backend/nestjs-api-postgres/.cursor/hooks/block-dangerous.ts +202 -0
- package/dist/templates/backend/nestjs-api-postgres/.cursor/hooks/format-and-validate.ts +124 -0
- package/dist/templates/backend/nestjs-api-postgres/.cursor/hooks/protect-secrets.ts +105 -0
- package/dist/templates/backend/nestjs-api-postgres/.cursor/hooks/session-context.ts +130 -0
- package/dist/templates/backend/nestjs-api-postgres/.cursor/hooks.json +36 -0
- package/dist/templates/backend/nestjs-api-postgres/eslint.config.mjs +1 -1
- package/dist/templates/backend/nestjs-api-postgres/package.json +6 -6
- package/dist/templates/backend/nestjs-api-sqlite/.cursor/agents/code-reviewer.md +153 -0
- package/dist/templates/backend/nestjs-api-sqlite/.cursor/agents/nestjs-architect.md +138 -0
- package/dist/templates/backend/nestjs-api-sqlite/.cursor/agents/prisma-analyst.md +164 -0
- package/dist/templates/backend/nestjs-api-sqlite/.cursor/agents/security-auditor.md +150 -0
- package/dist/templates/backend/nestjs-api-sqlite/.cursor/agents/test-engineer.md +290 -0
- package/dist/templates/backend/nestjs-api-sqlite/.cursor/hooks/auto-format.ts +80 -0
- package/dist/templates/backend/nestjs-api-sqlite/.cursor/hooks/block-dangerous-commands.ts +144 -0
- package/dist/templates/backend/nestjs-api-sqlite/.cursor/hooks/prisma-schema-watcher.ts +64 -0
- package/dist/templates/backend/nestjs-api-sqlite/.cursor/hooks/protect-sensitive-files.ts +122 -0
- package/dist/templates/backend/nestjs-api-sqlite/.cursor/hooks/session-context.ts +105 -0
- package/dist/templates/backend/nestjs-api-sqlite/.cursor/hooks.json +18 -0
- package/dist/templates/backend/nestjs-api-sqlite/.cursor/skills/conventional-commits/SKILL.md +318 -0
- package/dist/templates/backend/nestjs-api-sqlite/.cursor/skills/docker/SKILL.md +82 -0
- package/dist/templates/backend/nestjs-api-sqlite/.cursor/skills/jest/SKILL.md +72 -0
- package/dist/templates/backend/nestjs-api-sqlite/.cursor/skills/logging-best-practices/SKILL.md +127 -0
- package/dist/templates/backend/nestjs-api-sqlite/.cursor/skills/prisma-database-setup/SKILL.md +186 -0
- package/dist/templates/backend/nestjs-api-sqlite/.cursor/skills/quality-gates-enforcer/SKILL.md +301 -0
- package/dist/templates/backend/nestjs-api-sqlite/README.md +34 -1
- package/dist/templates/backend/nestjs-api-sqlite/eslint.config.mjs +1 -1
- package/dist/templates/backend/nestjs-api-sqlite/package.json +6 -6
- package/dist/templates/backend/nestjs-api-sqlite/prisma/schema.prisma +1 -0
- package/dist/templates/backend/nestjs-api-sqlite/prisma/seed.ts +2 -2
- package/dist/templates/backend/nestjs-api-sqlite/src/posts/dto/post-response.dto.ts +5 -1
- package/dist/templates/backend/nestjs-api-sqlite/src/users/dto/profile-response.dto.ts +1 -1
- package/dist/templates/backend/nestjs-api-sqlite/src/users/dto/update-profile.dto.ts +1 -1
- package/dist/templates/backend/nestjs-api-sqlite/src/users/dto/user-response.dto.ts +4 -0
- package/dist/templates/backend/nestjs-api-sqlite/src/users/profile.service.ts +24 -8
- package/dist/templates/backend/nestjs-api-sqlite/src/users/users.service.ts +1 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/agents/nestjs-code-reviewer.md +54 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/agents/prisma-guardian.md +67 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/agents/test-runner.md +57 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/commands/new-endpoint.md +209 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/commands/new-model.md +201 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/hooks/autoTestOnStop.ts +127 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/hooks/blockDangerous.ts +98 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/hooks/ensureTestsExist.ts +405 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/hooks/formatOnEdit.ts +70 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/hooks/protectSecrets.ts +101 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/hooks/sessionInit.ts +104 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/hooks/validatePrisma.ts +121 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/hooks.json +46 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/rules/api-rest.mdc +126 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/rules/authentication-security.mdc +86 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/rules/dto-validation.mdc +93 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/rules/general-rules.mdc +126 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/rules/nestjs-architecture.mdc +83 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/rules/prisma-standards.mdc +111 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/rules/swagger-documentation.mdc +90 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/skills/api-security-best-practices/SKILL.md +907 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/skills/docker-expert/SKILL.md +409 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/skills/nestjs-expert/SKILL.md +552 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/skills/nestjs-the-best-practices/AGENTS.md +5958 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/skills/nestjs-the-best-practices/SKILL.md +130 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/skills/nodejs-best-practices/SKILL.md +333 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/skills/prisma-expert/SKILL.md +355 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/skills/sqlserver-table-design/SKILL.md +125 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.dockerignore +50 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.env.example +17 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.env.test +17 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.prettierrc +4 -0
- package/dist/templates/backend/nestjs-api-sqlserver/README.md +587 -0
- package/dist/templates/backend/nestjs-api-sqlserver/docker-compose.yml +24 -0
- package/dist/templates/backend/nestjs-api-sqlserver/eslint.config.mjs +41 -0
- package/dist/templates/backend/nestjs-api-sqlserver/nest-cli.json +8 -0
- package/dist/templates/backend/nestjs-api-sqlserver/package.json +107 -0
- package/dist/templates/backend/nestjs-api-sqlserver/prisma/schema.prisma +70 -0
- package/dist/templates/backend/nestjs-api-sqlserver/prisma/seed.ts +215 -0
- package/dist/templates/backend/nestjs-api-sqlserver/prisma.config.ts +12 -0
- package/dist/templates/backend/nestjs-api-sqlserver/scripts/check-docker.js +64 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/app.module.ts +39 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/app.service.ts +8 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/auth/auth.controller.ts +36 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/auth/auth.module.ts +22 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/auth/auth.service.ts +64 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/auth/decorators/roles.decorator.ts +5 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/auth/dto/login-response.dto.ts +23 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/auth/dto/login.dto.ts +27 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/auth/enums/role.enum.ts +5 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/auth/guards/jwt-auth.guard.ts +20 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/auth/guards/roles.guard.ts +23 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/auth/strategies/jwt.strategy.ts +32 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/auth/types.ts +18 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/common/dto/paginated-response.dto.ts +16 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/common/dto/pagination.dto.ts +31 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/common/filters/http-exception.filter.ts +53 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/config/env.validation.ts +41 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/health/health.controller.ts +35 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/health/health.module.ts +7 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/main.ts +87 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/posts/dto/create-post.dto.ts +32 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/posts/dto/post-response.dto.ts +41 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/posts/dto/update-post.dto.ts +31 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/posts/posts.controller.ts +161 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/posts/posts.module.ts +12 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/posts/posts.service.ts +171 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/prisma/prisma.module.ts +9 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/prisma/prisma.service.ts +62 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/users/constants/settings.constants.ts +9 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/users/dto/profile-response.dto.ts +39 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/users/dto/settings-response.dto.ts +18 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/users/dto/update-profile.dto.ts +48 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/users/dto/update-settings.dto.ts +40 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/users/dto/user-response.dto.ts +18 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/users/profile.service.ts +67 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/users/settings.service.ts +77 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/users/users.controller.ts +102 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/users/users.module.ts +14 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/users/users.service.ts +27 -0
- package/dist/templates/backend/nestjs-api-sqlserver/test/README.md +412 -0
- package/dist/templates/backend/nestjs-api-sqlserver/test/e2e/auth.e2e-spec.ts +147 -0
- package/dist/templates/backend/nestjs-api-sqlserver/test/e2e/health.e2e-spec.ts +62 -0
- package/dist/templates/backend/nestjs-api-sqlserver/test/e2e/posts.e2e-spec.ts +407 -0
- package/dist/templates/backend/nestjs-api-sqlserver/test/e2e/users.e2e-spec.ts +287 -0
- package/dist/templates/backend/nestjs-api-sqlserver/test/fixtures/test-data.ts +109 -0
- package/dist/templates/backend/nestjs-api-sqlserver/test/helpers/auth.helper.ts +54 -0
- package/dist/templates/backend/nestjs-api-sqlserver/test/helpers/db.helper.ts +68 -0
- package/dist/templates/backend/nestjs-api-sqlserver/test/jest-e2e.json +12 -0
- package/dist/templates/backend/nestjs-api-sqlserver/test/setup-e2e.ts +8 -0
- package/dist/templates/backend/nestjs-api-sqlserver/test/unit/app.service.spec.ts +24 -0
- package/dist/templates/backend/nestjs-api-sqlserver/test/unit/auth.controller.spec.ts +91 -0
- package/dist/templates/backend/nestjs-api-sqlserver/test/unit/auth.service.spec.ts +161 -0
- package/dist/templates/backend/nestjs-api-sqlserver/test/unit/health.controller.spec.ts +78 -0
- package/dist/templates/backend/nestjs-api-sqlserver/test/unit/http-exception.filter.spec.ts +150 -0
- package/dist/templates/backend/nestjs-api-sqlserver/test/unit/jwt-auth.guard.spec.ts +50 -0
- package/dist/templates/backend/nestjs-api-sqlserver/test/unit/jwt.strategy.spec.ts +41 -0
- package/dist/templates/backend/nestjs-api-sqlserver/test/unit/posts.controller.spec.ts +249 -0
- package/dist/templates/backend/nestjs-api-sqlserver/test/unit/posts.service.spec.ts +328 -0
- package/dist/templates/backend/nestjs-api-sqlserver/test/unit/profile.service.spec.ts +146 -0
- package/dist/templates/backend/nestjs-api-sqlserver/test/unit/settings.service.spec.ts +242 -0
- package/dist/templates/backend/nestjs-api-sqlserver/test/unit/users.controller.spec.ts +178 -0
- package/dist/templates/backend/nestjs-api-sqlserver/test/unit/users.service.spec.ts +96 -0
- package/dist/templates/backend/nestjs-api-sqlserver/tsconfig.build.json +4 -0
- package/dist/templates/backend/nestjs-api-sqlserver/tsconfig.json +28 -0
- package/dist/templates/frontend/angular-base/.cursor/agents/accessibility-reviewer.md +67 -0
- package/dist/templates/frontend/angular-base/.cursor/agents/angular-code-reviewer.md +60 -0
- package/dist/templates/frontend/angular-base/.cursor/agents/qa-test-expert.md +70 -0
- package/dist/templates/frontend/angular-base/.cursor/agents/security-auditor.md +58 -0
- package/dist/templates/frontend/angular-base/.cursor/hooks/auto-format.ts +70 -0
- package/dist/templates/frontend/angular-base/.cursor/hooks/auto-test-on-stop.ts +113 -0
- package/dist/templates/frontend/angular-base/.cursor/hooks/block-dangerous-commands.ts +160 -0
- package/dist/templates/frontend/angular-base/.cursor/hooks/ensure-tests-exist.ts +363 -0
- package/dist/templates/frontend/angular-base/.cursor/hooks/protect-sensitive-files.ts +118 -0
- package/dist/templates/frontend/angular-base/.cursor/hooks/session-context.ts +110 -0
- package/dist/templates/frontend/angular-base/.cursor/hooks.json +41 -0
- package/dist/templates/frontend/angular-nx/.cursor/agents/angular-code-reviewer.md +64 -0
- package/dist/templates/frontend/angular-nx/.cursor/agents/nx-architecture-guardian.md +69 -0
- package/dist/templates/frontend/angular-nx/.cursor/agents/qa-test-expert.md +75 -0
- package/dist/templates/frontend/angular-nx/.cursor/agents/security-auditor.md +61 -0
- package/dist/templates/frontend/angular-nx/.cursor/hooks/auto-format.ts +70 -0
- package/dist/templates/frontend/angular-nx/.cursor/hooks/auto-test-on-stop.ts +115 -0
- package/dist/templates/frontend/angular-nx/.cursor/hooks/block-dangerous-commands.ts +188 -0
- package/dist/templates/frontend/angular-nx/.cursor/hooks/ensure-tests-exist.ts +399 -0
- package/dist/templates/frontend/angular-nx/.cursor/hooks/protect-sensitive-files.ts +128 -0
- package/dist/templates/frontend/angular-nx/.cursor/hooks/session-context.ts +121 -0
- package/dist/templates/frontend/angular-nx/.cursor/hooks.json +41 -0
- package/dist/templates/frontend/react-vite/.cursor/agents/frontend-senior.agent.md +49 -49
- package/dist/templates/frontend/react-vite/.cursor/agents/qa-test-expert.agent.md +126 -49
- package/dist/templates/frontend/react-vite/.cursor/agents/security-expert.agent.md +39 -39
- package/dist/templates/frontend/react-vite/.cursor/agents/ux-ui-expert.agent.md +45 -45
- package/dist/templates/frontend/react-vite/.cursor/hooks/autoTestOnStop.ts +117 -0
- package/dist/templates/frontend/react-vite/.cursor/hooks/blockDangerous.ts +75 -0
- package/dist/templates/frontend/react-vite/.cursor/hooks/ensureTestsExist.ts +306 -220
- package/dist/templates/frontend/react-vite/.cursor/hooks/formatOnEdit.ts +49 -0
- package/dist/templates/frontend/react-vite/.cursor/hooks/protectSecrets.ts +88 -0
- package/dist/templates/frontend/react-vite/.cursor/hooks/sessionInit.ts +77 -0
- package/dist/templates/frontend/react-vite/.cursor/hooks.json +41 -10
- package/dist/templates/frontend/react-vite/.cursor/settings.json +13 -13
- package/dist/templates/frontend/react-vite/.vscode/settings.json +31 -31
- package/dist/templates/frontend/react-vite/README.md +34 -34
- package/dist/templates/frontend/react-vite/package.json +82 -82
- package/dist/templates/frontend/react-vite/pnpm-lock.yaml +6575 -6575
- package/dist/templates/frontend/react-vite/src/__tests__/components/layout/navbar.test.tsx +63 -0
- package/dist/templates/frontend/react-vite/src/__tests__/components/ui/avatar.test.tsx +74 -0
- package/dist/templates/frontend/react-vite/src/__tests__/components/ui/badge.test.tsx +55 -0
- package/dist/templates/frontend/react-vite/src/__tests__/components/ui/breadcrumb.test.tsx +140 -0
- package/dist/templates/frontend/react-vite/src/__tests__/components/ui/button.test.tsx +121 -0
- package/dist/templates/frontend/react-vite/src/__tests__/components/ui/card.test.tsx +144 -0
- package/dist/templates/frontend/react-vite/src/__tests__/components/ui/dialog.test.tsx +121 -0
- package/dist/templates/frontend/react-vite/src/__tests__/components/ui/form.test.tsx +165 -0
- package/dist/templates/frontend/react-vite/src/__tests__/components/ui/input.test.tsx +52 -0
- package/dist/templates/frontend/react-vite/src/__tests__/components/ui/label.test.tsx +40 -0
- package/dist/templates/frontend/react-vite/src/__tests__/components/ui/password-input.test.tsx +59 -0
- package/dist/templates/frontend/react-vite/src/__tests__/components/ui/separator.test.tsx +40 -0
- package/dist/templates/frontend/react-vite/src/__tests__/components/ui/table.test.tsx +254 -0
- package/dist/templates/frontend/react-vite/src/__tests__/components/ui/tabs.test.tsx +82 -0
- package/dist/templates/frontend/react-vite/src/__tests__/components/ui/textarea.test.tsx +47 -0
- package/dist/templates/frontend/react-vite/src/__tests__/helpers/render.tsx +114 -0
- package/dist/templates/frontend/react-vite/src/__tests__/hooks/useLocalStorage.test.ts +95 -0
- package/dist/templates/frontend/react-vite/src/__tests__/lib/queryClient.test.ts +24 -0
- package/dist/templates/frontend/react-vite/src/__tests__/lib/utils.test.ts +43 -0
- package/dist/templates/frontend/react-vite/src/__tests__/routes/index.test.tsx +111 -0
- package/dist/templates/frontend/react-vite/src/__tests__/routes/otra-ruta.test.tsx +126 -0
- package/dist/templates/frontend/react-vite/src/__tests__/routes/root.test.tsx +78 -0
- package/dist/templates/frontend/react-vite/src/__tests__/routes/ui-components.test.tsx +286 -0
- package/dist/templates/frontend/react-vite/src/components/layout/navbar.tsx +38 -38
- package/dist/templates/frontend/react-vite/src/components/ui/avatar.tsx +42 -42
- package/dist/templates/frontend/react-vite/src/components/ui/dialog.tsx +122 -122
- package/dist/templates/frontend/react-vite/src/components/ui/table.tsx +229 -244
- package/dist/templates/frontend/react-vite/src/hooks/useLocalStorage.ts +32 -32
- package/dist/templates/frontend/react-vite/src/routes/__root.tsx +48 -48
- package/dist/templates/frontend/react-vite/src/routes/ui-components.tsx +359 -85
- package/dist/templates/frontend/react-vite/src/test/setup.ts +24 -24
- package/dist/templates/frontend/react-vite/vite.config.ts +2 -2
- package/dist/templates/frontend/react-vite/vitest.config.ts +13 -2
- package/package.json +1 -1
- package/templates/README.md +7 -1
- package/templates/backend/README.md +19 -9
- package/templates/backend/nestjs-api-mysql/.cursor/agents/nestjs-code-reviewer.md +54 -0
- package/templates/backend/nestjs-api-mysql/.cursor/agents/prisma-guardian.md +67 -0
- package/templates/backend/nestjs-api-mysql/.cursor/agents/test-runner.md +57 -0
- package/templates/backend/nestjs-api-mysql/.cursor/hooks/autoTestOnStop.ts +127 -0
- package/templates/backend/nestjs-api-mysql/.cursor/hooks/blockDangerous.ts +98 -0
- package/templates/backend/nestjs-api-mysql/.cursor/hooks/ensureTestsExist.ts +405 -0
- package/templates/backend/nestjs-api-mysql/.cursor/hooks/formatOnEdit.ts +70 -0
- package/templates/backend/nestjs-api-mysql/.cursor/hooks/protectSecrets.ts +101 -0
- package/templates/backend/nestjs-api-mysql/.cursor/hooks/sessionInit.ts +104 -0
- package/templates/backend/nestjs-api-mysql/.cursor/hooks/validatePrisma.ts +121 -0
- package/templates/backend/nestjs-api-mysql/.cursor/hooks.json +46 -0
- package/templates/backend/nestjs-api-mysql/README.md +26 -0
- package/templates/backend/nestjs-api-mysql/dist/tsconfig.build.tsbuildinfo +1 -1
- package/templates/backend/nestjs-api-mysql/eslint.config.mjs +1 -1
- package/templates/backend/nestjs-api-mysql/package.json +7 -7
- package/templates/backend/nestjs-api-postgres/.cursor/agents/nestjs-code-reviewer.md +54 -0
- package/templates/backend/nestjs-api-postgres/.cursor/agents/prisma-guardian.md +62 -0
- package/templates/backend/nestjs-api-postgres/.cursor/agents/security-auditor.md +71 -0
- package/templates/backend/nestjs-api-postgres/.cursor/agents/test-runner.md +58 -0
- package/templates/backend/nestjs-api-postgres/.cursor/hooks/auto-retry.ts +62 -0
- package/templates/backend/nestjs-api-postgres/.cursor/hooks/block-dangerous.ts +202 -0
- package/templates/backend/nestjs-api-postgres/.cursor/hooks/format-and-validate.ts +124 -0
- package/templates/backend/nestjs-api-postgres/.cursor/hooks/protect-secrets.ts +105 -0
- package/templates/backend/nestjs-api-postgres/.cursor/hooks/session-context.ts +130 -0
- package/templates/backend/nestjs-api-postgres/.cursor/hooks.json +36 -0
- package/templates/backend/nestjs-api-postgres/eslint.config.mjs +1 -1
- package/templates/backend/nestjs-api-postgres/package.json +6 -6
- package/templates/backend/nestjs-api-sqlite/.cursor/agents/code-reviewer.md +153 -0
- package/templates/backend/nestjs-api-sqlite/.cursor/agents/nestjs-architect.md +138 -0
- package/templates/backend/nestjs-api-sqlite/.cursor/agents/prisma-analyst.md +164 -0
- package/templates/backend/nestjs-api-sqlite/.cursor/agents/security-auditor.md +150 -0
- package/templates/backend/nestjs-api-sqlite/.cursor/agents/test-engineer.md +290 -0
- package/templates/backend/nestjs-api-sqlite/.cursor/hooks/auto-format.ts +80 -0
- package/templates/backend/nestjs-api-sqlite/.cursor/hooks/block-dangerous-commands.ts +144 -0
- package/templates/backend/nestjs-api-sqlite/.cursor/hooks/prisma-schema-watcher.ts +64 -0
- package/templates/backend/nestjs-api-sqlite/.cursor/hooks/protect-sensitive-files.ts +122 -0
- package/templates/backend/nestjs-api-sqlite/.cursor/hooks/session-context.ts +105 -0
- package/templates/backend/nestjs-api-sqlite/.cursor/hooks.json +18 -0
- package/templates/backend/nestjs-api-sqlite/.cursor/skills/conventional-commits/SKILL.md +318 -0
- package/templates/backend/nestjs-api-sqlite/.cursor/skills/docker/SKILL.md +82 -0
- package/templates/backend/nestjs-api-sqlite/.cursor/skills/jest/SKILL.md +72 -0
- package/templates/backend/nestjs-api-sqlite/.cursor/skills/logging-best-practices/SKILL.md +127 -0
- package/templates/backend/nestjs-api-sqlite/.cursor/skills/prisma-database-setup/SKILL.md +186 -0
- package/templates/backend/nestjs-api-sqlite/.cursor/skills/quality-gates-enforcer/SKILL.md +301 -0
- package/templates/backend/nestjs-api-sqlite/README.md +34 -1
- package/templates/backend/nestjs-api-sqlite/eslint.config.mjs +1 -1
- package/templates/backend/nestjs-api-sqlite/package.json +6 -6
- package/templates/backend/nestjs-api-sqlite/prisma/schema.prisma +1 -0
- package/templates/backend/nestjs-api-sqlite/prisma/seed.ts +2 -2
- package/templates/backend/nestjs-api-sqlite/src/posts/dto/post-response.dto.ts +5 -1
- package/templates/backend/nestjs-api-sqlite/src/users/dto/profile-response.dto.ts +1 -1
- package/templates/backend/nestjs-api-sqlite/src/users/dto/update-profile.dto.ts +1 -1
- package/templates/backend/nestjs-api-sqlite/src/users/dto/user-response.dto.ts +4 -0
- package/templates/backend/nestjs-api-sqlite/src/users/profile.service.ts +24 -8
- package/templates/backend/nestjs-api-sqlite/src/users/users.service.ts +1 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/agents/nestjs-code-reviewer.md +54 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/agents/prisma-guardian.md +67 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/agents/test-runner.md +57 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/commands/new-endpoint.md +209 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/commands/new-model.md +201 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/hooks/autoTestOnStop.ts +127 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/hooks/blockDangerous.ts +98 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/hooks/ensureTestsExist.ts +405 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/hooks/formatOnEdit.ts +70 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/hooks/protectSecrets.ts +101 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/hooks/sessionInit.ts +104 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/hooks/validatePrisma.ts +121 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/hooks.json +46 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/rules/api-rest.mdc +126 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/rules/authentication-security.mdc +86 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/rules/dto-validation.mdc +93 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/rules/general-rules.mdc +126 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/rules/nestjs-architecture.mdc +83 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/rules/prisma-standards.mdc +111 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/rules/swagger-documentation.mdc +90 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/skills/api-security-best-practices/SKILL.md +907 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/skills/docker-expert/SKILL.md +409 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/skills/nestjs-expert/SKILL.md +552 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/skills/nestjs-the-best-practices/AGENTS.md +5958 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/skills/nestjs-the-best-practices/SKILL.md +130 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/skills/nodejs-best-practices/SKILL.md +333 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/skills/prisma-expert/SKILL.md +355 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/skills/sqlserver-table-design/SKILL.md +125 -0
- package/templates/backend/nestjs-api-sqlserver/.dockerignore +50 -0
- package/templates/backend/nestjs-api-sqlserver/.env.example +17 -0
- package/templates/backend/nestjs-api-sqlserver/.env.test +17 -0
- package/templates/backend/nestjs-api-sqlserver/.prettierrc +4 -0
- package/templates/backend/nestjs-api-sqlserver/README.md +587 -0
- package/templates/backend/nestjs-api-sqlserver/docker-compose.yml +24 -0
- package/templates/backend/nestjs-api-sqlserver/eslint.config.mjs +41 -0
- package/templates/backend/nestjs-api-sqlserver/nest-cli.json +8 -0
- package/templates/backend/nestjs-api-sqlserver/package.json +107 -0
- package/templates/backend/nestjs-api-sqlserver/prisma/schema.prisma +70 -0
- package/templates/backend/nestjs-api-sqlserver/prisma/seed.ts +215 -0
- package/templates/backend/nestjs-api-sqlserver/prisma.config.ts +12 -0
- package/templates/backend/nestjs-api-sqlserver/scripts/check-docker.js +64 -0
- package/templates/backend/nestjs-api-sqlserver/src/app.module.ts +39 -0
- package/templates/backend/nestjs-api-sqlserver/src/app.service.ts +8 -0
- package/templates/backend/nestjs-api-sqlserver/src/auth/auth.controller.ts +36 -0
- package/templates/backend/nestjs-api-sqlserver/src/auth/auth.module.ts +22 -0
- package/templates/backend/nestjs-api-sqlserver/src/auth/auth.service.ts +64 -0
- package/templates/backend/nestjs-api-sqlserver/src/auth/decorators/roles.decorator.ts +5 -0
- package/templates/backend/nestjs-api-sqlserver/src/auth/dto/login-response.dto.ts +23 -0
- package/templates/backend/nestjs-api-sqlserver/src/auth/dto/login.dto.ts +27 -0
- package/templates/backend/nestjs-api-sqlserver/src/auth/enums/role.enum.ts +5 -0
- package/templates/backend/nestjs-api-sqlserver/src/auth/guards/jwt-auth.guard.ts +20 -0
- package/templates/backend/nestjs-api-sqlserver/src/auth/guards/roles.guard.ts +23 -0
- package/templates/backend/nestjs-api-sqlserver/src/auth/strategies/jwt.strategy.ts +32 -0
- package/templates/backend/nestjs-api-sqlserver/src/auth/types.ts +18 -0
- package/templates/backend/nestjs-api-sqlserver/src/common/dto/paginated-response.dto.ts +16 -0
- package/templates/backend/nestjs-api-sqlserver/src/common/dto/pagination.dto.ts +31 -0
- package/templates/backend/nestjs-api-sqlserver/src/common/filters/http-exception.filter.ts +53 -0
- package/templates/backend/nestjs-api-sqlserver/src/config/env.validation.ts +41 -0
- package/templates/backend/nestjs-api-sqlserver/src/health/health.controller.ts +35 -0
- package/templates/backend/nestjs-api-sqlserver/src/health/health.module.ts +7 -0
- package/templates/backend/nestjs-api-sqlserver/src/main.ts +87 -0
- package/templates/backend/nestjs-api-sqlserver/src/posts/dto/create-post.dto.ts +32 -0
- package/templates/backend/nestjs-api-sqlserver/src/posts/dto/post-response.dto.ts +41 -0
- package/templates/backend/nestjs-api-sqlserver/src/posts/dto/update-post.dto.ts +31 -0
- package/templates/backend/nestjs-api-sqlserver/src/posts/posts.controller.ts +161 -0
- package/templates/backend/nestjs-api-sqlserver/src/posts/posts.module.ts +12 -0
- package/templates/backend/nestjs-api-sqlserver/src/posts/posts.service.ts +171 -0
- package/templates/backend/nestjs-api-sqlserver/src/prisma/prisma.module.ts +9 -0
- package/templates/backend/nestjs-api-sqlserver/src/prisma/prisma.service.ts +62 -0
- package/templates/backend/nestjs-api-sqlserver/src/users/constants/settings.constants.ts +9 -0
- package/templates/backend/nestjs-api-sqlserver/src/users/dto/profile-response.dto.ts +39 -0
- package/templates/backend/nestjs-api-sqlserver/src/users/dto/settings-response.dto.ts +18 -0
- package/templates/backend/nestjs-api-sqlserver/src/users/dto/update-profile.dto.ts +48 -0
- package/templates/backend/nestjs-api-sqlserver/src/users/dto/update-settings.dto.ts +40 -0
- package/templates/backend/nestjs-api-sqlserver/src/users/dto/user-response.dto.ts +18 -0
- package/templates/backend/nestjs-api-sqlserver/src/users/profile.service.ts +67 -0
- package/templates/backend/nestjs-api-sqlserver/src/users/settings.service.ts +77 -0
- package/templates/backend/nestjs-api-sqlserver/src/users/users.controller.ts +102 -0
- package/templates/backend/nestjs-api-sqlserver/src/users/users.module.ts +14 -0
- package/templates/backend/nestjs-api-sqlserver/src/users/users.service.ts +27 -0
- package/templates/backend/nestjs-api-sqlserver/test/README.md +412 -0
- package/templates/backend/nestjs-api-sqlserver/test/e2e/auth.e2e-spec.ts +147 -0
- package/templates/backend/nestjs-api-sqlserver/test/e2e/health.e2e-spec.ts +62 -0
- package/templates/backend/nestjs-api-sqlserver/test/e2e/posts.e2e-spec.ts +407 -0
- package/templates/backend/nestjs-api-sqlserver/test/e2e/users.e2e-spec.ts +287 -0
- package/templates/backend/nestjs-api-sqlserver/test/fixtures/test-data.ts +109 -0
- package/templates/backend/nestjs-api-sqlserver/test/helpers/auth.helper.ts +54 -0
- package/templates/backend/nestjs-api-sqlserver/test/helpers/db.helper.ts +68 -0
- package/templates/backend/nestjs-api-sqlserver/test/jest-e2e.json +12 -0
- package/templates/backend/nestjs-api-sqlserver/test/setup-e2e.ts +8 -0
- package/templates/backend/nestjs-api-sqlserver/test/unit/app.service.spec.ts +24 -0
- package/templates/backend/nestjs-api-sqlserver/test/unit/auth.controller.spec.ts +91 -0
- package/templates/backend/nestjs-api-sqlserver/test/unit/auth.service.spec.ts +161 -0
- package/templates/backend/nestjs-api-sqlserver/test/unit/health.controller.spec.ts +78 -0
- package/templates/backend/nestjs-api-sqlserver/test/unit/http-exception.filter.spec.ts +150 -0
- package/templates/backend/nestjs-api-sqlserver/test/unit/jwt-auth.guard.spec.ts +50 -0
- package/templates/backend/nestjs-api-sqlserver/test/unit/jwt.strategy.spec.ts +41 -0
- package/templates/backend/nestjs-api-sqlserver/test/unit/posts.controller.spec.ts +249 -0
- package/templates/backend/nestjs-api-sqlserver/test/unit/posts.service.spec.ts +328 -0
- package/templates/backend/nestjs-api-sqlserver/test/unit/profile.service.spec.ts +146 -0
- package/templates/backend/nestjs-api-sqlserver/test/unit/settings.service.spec.ts +242 -0
- package/templates/backend/nestjs-api-sqlserver/test/unit/users.controller.spec.ts +178 -0
- package/templates/backend/nestjs-api-sqlserver/test/unit/users.service.spec.ts +96 -0
- package/templates/backend/nestjs-api-sqlserver/tsconfig.build.json +4 -0
- package/templates/backend/nestjs-api-sqlserver/tsconfig.json +28 -0
- package/templates/frontend/angular-base/.cursor/agents/accessibility-reviewer.md +67 -0
- package/templates/frontend/angular-base/.cursor/agents/angular-code-reviewer.md +60 -0
- package/templates/frontend/angular-base/.cursor/agents/qa-test-expert.md +70 -0
- package/templates/frontend/angular-base/.cursor/agents/security-auditor.md +58 -0
- package/templates/frontend/angular-base/.cursor/hooks/auto-format.ts +70 -0
- package/templates/frontend/angular-base/.cursor/hooks/auto-test-on-stop.ts +113 -0
- package/templates/frontend/angular-base/.cursor/hooks/block-dangerous-commands.ts +160 -0
- package/templates/frontend/angular-base/.cursor/hooks/ensure-tests-exist.ts +363 -0
- package/templates/frontend/angular-base/.cursor/hooks/protect-sensitive-files.ts +118 -0
- package/templates/frontend/angular-base/.cursor/hooks/session-context.ts +110 -0
- package/templates/frontend/angular-base/.cursor/hooks.json +41 -0
- package/templates/frontend/angular-nx/.cursor/agents/angular-code-reviewer.md +64 -0
- package/templates/frontend/angular-nx/.cursor/agents/nx-architecture-guardian.md +69 -0
- package/templates/frontend/angular-nx/.cursor/agents/qa-test-expert.md +75 -0
- package/templates/frontend/angular-nx/.cursor/agents/security-auditor.md +61 -0
- package/templates/frontend/angular-nx/.cursor/hooks/auto-format.ts +70 -0
- package/templates/frontend/angular-nx/.cursor/hooks/auto-test-on-stop.ts +115 -0
- package/templates/frontend/angular-nx/.cursor/hooks/block-dangerous-commands.ts +188 -0
- package/templates/frontend/angular-nx/.cursor/hooks/ensure-tests-exist.ts +399 -0
- package/templates/frontend/angular-nx/.cursor/hooks/protect-sensitive-files.ts +128 -0
- package/templates/frontend/angular-nx/.cursor/hooks/session-context.ts +121 -0
- package/templates/frontend/angular-nx/.cursor/hooks.json +41 -0
- package/templates/frontend/react-vite/.cursor/agents/frontend-senior.agent.md +49 -49
- package/templates/frontend/react-vite/.cursor/agents/qa-test-expert.agent.md +126 -49
- package/templates/frontend/react-vite/.cursor/agents/security-expert.agent.md +39 -39
- package/templates/frontend/react-vite/.cursor/agents/ux-ui-expert.agent.md +45 -45
- package/templates/frontend/react-vite/.cursor/hooks/autoTestOnStop.ts +117 -0
- package/templates/frontend/react-vite/.cursor/hooks/blockDangerous.ts +75 -0
- package/templates/frontend/react-vite/.cursor/hooks/ensureTestsExist.ts +306 -220
- package/templates/frontend/react-vite/.cursor/hooks/formatOnEdit.ts +49 -0
- package/templates/frontend/react-vite/.cursor/hooks/protectSecrets.ts +88 -0
- package/templates/frontend/react-vite/.cursor/hooks/sessionInit.ts +77 -0
- package/templates/frontend/react-vite/.cursor/hooks.json +41 -10
- package/templates/frontend/react-vite/.cursor/settings.json +13 -13
- package/templates/frontend/react-vite/.vscode/settings.json +31 -31
- package/templates/frontend/react-vite/README.md +34 -34
- package/templates/frontend/react-vite/package.json +82 -82
- package/templates/frontend/react-vite/pnpm-lock.yaml +6575 -6575
- package/templates/frontend/react-vite/src/__tests__/components/layout/navbar.test.tsx +63 -0
- package/templates/frontend/react-vite/src/__tests__/components/ui/avatar.test.tsx +74 -0
- package/templates/frontend/react-vite/src/__tests__/components/ui/badge.test.tsx +55 -0
- package/templates/frontend/react-vite/src/__tests__/components/ui/breadcrumb.test.tsx +140 -0
- package/templates/frontend/react-vite/src/__tests__/components/ui/button.test.tsx +121 -0
- package/templates/frontend/react-vite/src/__tests__/components/ui/card.test.tsx +144 -0
- package/templates/frontend/react-vite/src/__tests__/components/ui/dialog.test.tsx +121 -0
- package/templates/frontend/react-vite/src/__tests__/components/ui/form.test.tsx +165 -0
- package/templates/frontend/react-vite/src/__tests__/components/ui/input.test.tsx +52 -0
- package/templates/frontend/react-vite/src/__tests__/components/ui/label.test.tsx +40 -0
- package/templates/frontend/react-vite/src/__tests__/components/ui/password-input.test.tsx +59 -0
- package/templates/frontend/react-vite/src/__tests__/components/ui/separator.test.tsx +40 -0
- package/templates/frontend/react-vite/src/__tests__/components/ui/table.test.tsx +254 -0
- package/templates/frontend/react-vite/src/__tests__/components/ui/tabs.test.tsx +82 -0
- package/templates/frontend/react-vite/src/__tests__/components/ui/textarea.test.tsx +47 -0
- package/templates/frontend/react-vite/src/__tests__/helpers/render.tsx +114 -0
- package/templates/frontend/react-vite/src/__tests__/hooks/useLocalStorage.test.ts +95 -0
- package/templates/frontend/react-vite/src/__tests__/lib/queryClient.test.ts +24 -0
- package/templates/frontend/react-vite/src/__tests__/lib/utils.test.ts +43 -0
- package/templates/frontend/react-vite/src/__tests__/routes/index.test.tsx +111 -0
- package/templates/frontend/react-vite/src/__tests__/routes/otra-ruta.test.tsx +126 -0
- package/templates/frontend/react-vite/src/__tests__/routes/root.test.tsx +78 -0
- package/templates/frontend/react-vite/src/__tests__/routes/ui-components.test.tsx +286 -0
- package/templates/frontend/react-vite/src/components/layout/navbar.tsx +38 -38
- package/templates/frontend/react-vite/src/components/ui/avatar.tsx +42 -42
- package/templates/frontend/react-vite/src/components/ui/dialog.tsx +122 -122
- package/templates/frontend/react-vite/src/components/ui/table.tsx +229 -244
- package/templates/frontend/react-vite/src/hooks/useLocalStorage.ts +32 -32
- package/templates/frontend/react-vite/src/routes/__root.tsx +48 -48
- package/templates/frontend/react-vite/src/routes/ui-components.tsx +359 -85
- package/templates/frontend/react-vite/src/test/setup.ts +24 -24
- package/templates/frontend/react-vite/vite.config.ts +2 -2
- package/templates/frontend/react-vite/vitest.config.ts +13 -2
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { execSync } from 'node:child_process';
|
|
2
|
+
|
|
3
|
+
interface HookInput {
|
|
4
|
+
session_id?: string;
|
|
5
|
+
is_background_agent?: boolean;
|
|
6
|
+
composer_mode?: string;
|
|
7
|
+
[key: string]: unknown;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
interface HookOutput {
|
|
11
|
+
env?: Record<string, string>;
|
|
12
|
+
additional_context?: string;
|
|
13
|
+
continue: boolean;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function readStdin(): Promise<string> {
|
|
17
|
+
return new Promise((resolve) => {
|
|
18
|
+
let data = '';
|
|
19
|
+
process.stdin.setEncoding('utf8');
|
|
20
|
+
process.stdin.on('data', (chunk: string) => {
|
|
21
|
+
data += chunk;
|
|
22
|
+
});
|
|
23
|
+
process.stdin.on('end', () => resolve(data));
|
|
24
|
+
process.stdin.on('error', () => resolve(''));
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function respond(output: HookOutput): void {
|
|
29
|
+
process.stdout.write(JSON.stringify(output) + '\n');
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function safeExec(command: string): string {
|
|
33
|
+
try {
|
|
34
|
+
return execSync(command, {
|
|
35
|
+
encoding: 'utf8',
|
|
36
|
+
timeout: 5_000,
|
|
37
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
38
|
+
}).trim();
|
|
39
|
+
} catch {
|
|
40
|
+
return 'unknown';
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
async function main(): Promise<void> {
|
|
45
|
+
try {
|
|
46
|
+
const raw = await readStdin();
|
|
47
|
+
if (!raw?.trim()) {
|
|
48
|
+
respond({ continue: true });
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
JSON.parse(raw.replace(/^\uFEFF/, '').trim()) as HookInput;
|
|
53
|
+
|
|
54
|
+
const gitBranch = safeExec('git rev-parse --abbrev-ref HEAD');
|
|
55
|
+
const nodeVersion = safeExec('node --version');
|
|
56
|
+
const pnpmVersion = safeExec('pnpm --version');
|
|
57
|
+
const lastCommit = safeExec('git log -1 --format="%h %s"');
|
|
58
|
+
|
|
59
|
+
const context = [
|
|
60
|
+
'== Contexto del proyecto (inyectado por sessionStart hook) ==',
|
|
61
|
+
'',
|
|
62
|
+
`Stack: NestJS 11 + Fastify 5 + Prisma 7 + SQLite (LibSQL) + JWT`,
|
|
63
|
+
`Branch: ${gitBranch} | Node: ${nodeVersion} | pnpm: ${pnpmVersion}`,
|
|
64
|
+
`Ultimo commit: ${lastCommit}`,
|
|
65
|
+
'',
|
|
66
|
+
'Comandos utiles:',
|
|
67
|
+
' pnpm start:dev - Servidor de desarrollo con hot-reload',
|
|
68
|
+
' pnpm test - Ejecutar tests unitarios (Jest)',
|
|
69
|
+
' pnpm test:e2e - Ejecutar tests E2E',
|
|
70
|
+
' pnpm lint - ESLint con autofix',
|
|
71
|
+
' pnpm format - Prettier en todo el proyecto',
|
|
72
|
+
' pnpm prisma:migrate - Crear y aplicar migracion Prisma',
|
|
73
|
+
' pnpm prisma:generate - Regenerar Prisma Client',
|
|
74
|
+
' pnpm prisma:studio - Abrir Prisma Studio (GUI de BD)',
|
|
75
|
+
' pnpm prisma:seed - Ejecutar seed de datos',
|
|
76
|
+
'',
|
|
77
|
+
'Convenciones:',
|
|
78
|
+
' - Los archivos .env NO deben leerse (hook de seguridad activo)',
|
|
79
|
+
' - Usar .env.example como referencia de variables de entorno',
|
|
80
|
+
' - Prisma Client se regenera automaticamente al editar schema.prisma',
|
|
81
|
+
' - Prettier formatea automaticamente despues de cada edicion',
|
|
82
|
+
' - Archivos de test en test/unit/ y test/e2e/ (no en src/)',
|
|
83
|
+
].join('\n');
|
|
84
|
+
|
|
85
|
+
console.error(`[session-context] Branch: ${gitBranch}, Node: ${nodeVersion}`);
|
|
86
|
+
|
|
87
|
+
respond({
|
|
88
|
+
env: {
|
|
89
|
+
GIT_BRANCH: gitBranch,
|
|
90
|
+
NODE_VERSION: nodeVersion,
|
|
91
|
+
PNPM_VERSION: pnpmVersion,
|
|
92
|
+
},
|
|
93
|
+
additional_context: context,
|
|
94
|
+
continue: true,
|
|
95
|
+
});
|
|
96
|
+
} catch (err) {
|
|
97
|
+
console.error(
|
|
98
|
+
'[session-context] Error:',
|
|
99
|
+
err instanceof Error ? err.message : String(err),
|
|
100
|
+
);
|
|
101
|
+
respond({ continue: true });
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
main();
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 1,
|
|
3
|
+
"hooks": {
|
|
4
|
+
"afterFileEdit": [
|
|
5
|
+
{ "command": "npx tsx .cursor/hooks/auto-format.ts", "timeout": 15 },
|
|
6
|
+
{ "command": "npx tsx .cursor/hooks/prisma-schema-watcher.ts", "timeout": 15 }
|
|
7
|
+
],
|
|
8
|
+
"beforeReadFile": [
|
|
9
|
+
{ "command": "npx tsx .cursor/hooks/protect-sensitive-files.ts", "timeout": 10 }
|
|
10
|
+
],
|
|
11
|
+
"beforeShellExecution": [
|
|
12
|
+
{ "command": "npx tsx .cursor/hooks/block-dangerous-commands.ts", "timeout": 10 }
|
|
13
|
+
],
|
|
14
|
+
"sessionStart": [
|
|
15
|
+
{ "command": "npx tsx .cursor/hooks/session-context.ts", "timeout": 15 }
|
|
16
|
+
]
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: conventional-commits
|
|
3
|
+
description: Generates semantic commit messages following the Conventional Commits specification with proper types, scopes, breaking changes, and footers. Use when users request "write commit message", "conventional commit", "semantic commit", or "format commit".
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Conventional Commits
|
|
7
|
+
|
|
8
|
+
Write standardized, semantic commit messages that enable automated versioning and changelog generation.
|
|
9
|
+
|
|
10
|
+
## Core Workflow
|
|
11
|
+
|
|
12
|
+
1. **Analyze changes**: Review staged files and modifications
|
|
13
|
+
2. **Determine type**: Select appropriate commit type (feat, fix, etc.)
|
|
14
|
+
3. **Identify scope**: Optional component/module affected
|
|
15
|
+
4. **Write description**: Concise summary in imperative mood
|
|
16
|
+
5. **Add body**: Optional detailed explanation
|
|
17
|
+
6. **Include footer**: Breaking changes, issue references
|
|
18
|
+
|
|
19
|
+
## Commit Message Format
|
|
20
|
+
|
|
21
|
+
```
|
|
22
|
+
<type>[optional scope]: <description>
|
|
23
|
+
|
|
24
|
+
[optional body]
|
|
25
|
+
|
|
26
|
+
[optional footer(s)]
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Commit Types
|
|
30
|
+
|
|
31
|
+
| Type | Description | Semver | Example |
|
|
32
|
+
|------|-------------|--------|---------|
|
|
33
|
+
| `feat` | New feature | MINOR | `feat: add user authentication` |
|
|
34
|
+
| `fix` | Bug fix | PATCH | `fix: resolve login redirect loop` |
|
|
35
|
+
| `docs` | Documentation only | - | `docs: update API reference` |
|
|
36
|
+
| `style` | Formatting, whitespace | - | `style: fix indentation in utils` |
|
|
37
|
+
| `refactor` | Code change, no feature/fix | - | `refactor: extract validation logic` |
|
|
38
|
+
| `perf` | Performance improvement | PATCH | `perf: optimize database queries` |
|
|
39
|
+
| `test` | Adding/fixing tests | - | `test: add unit tests for auth` |
|
|
40
|
+
| `build` | Build system, dependencies | - | `build: upgrade to Node 20` |
|
|
41
|
+
| `ci` | CI/CD configuration | - | `ci: add GitHub Actions workflow` |
|
|
42
|
+
| `chore` | Maintenance tasks | - | `chore: update .gitignore` |
|
|
43
|
+
| `revert` | Revert previous commit | - | `revert: undo feature flag change` |
|
|
44
|
+
|
|
45
|
+
## Scopes
|
|
46
|
+
|
|
47
|
+
Scopes indicate the area of the codebase affected:
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
# Component/module scopes
|
|
51
|
+
feat(auth): add OAuth2 support
|
|
52
|
+
fix(api): handle timeout errors
|
|
53
|
+
docs(readme): add installation steps
|
|
54
|
+
|
|
55
|
+
# File-based scopes
|
|
56
|
+
style(eslint): update linting rules
|
|
57
|
+
build(docker): optimize image size
|
|
58
|
+
|
|
59
|
+
# Layer scopes
|
|
60
|
+
refactor(service): extract user service
|
|
61
|
+
test(e2e): add checkout flow tests
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Breaking Changes
|
|
65
|
+
|
|
66
|
+
Mark breaking changes with `!` or `BREAKING CHANGE` footer:
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
# Using ! notation
|
|
70
|
+
feat(api)!: change response format to JSON:API
|
|
71
|
+
|
|
72
|
+
# Using footer
|
|
73
|
+
feat(api): change response format
|
|
74
|
+
|
|
75
|
+
BREAKING CHANGE: Response now follows JSON:API specification.
|
|
76
|
+
Clients must update their parsers.
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## Commit Message Examples
|
|
80
|
+
|
|
81
|
+
### Simple Feature
|
|
82
|
+
```
|
|
83
|
+
feat: add dark mode toggle
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### Feature with Scope
|
|
87
|
+
```
|
|
88
|
+
feat(ui): add dark mode toggle to settings page
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### Bug Fix with Issue Reference
|
|
92
|
+
```
|
|
93
|
+
fix(auth): resolve session expiration race condition
|
|
94
|
+
|
|
95
|
+
The session refresh was racing with the expiration check,
|
|
96
|
+
causing intermittent logouts.
|
|
97
|
+
|
|
98
|
+
Fixes #234
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### Breaking Change
|
|
102
|
+
```
|
|
103
|
+
feat(api)!: migrate to v2 response format
|
|
104
|
+
|
|
105
|
+
BREAKING CHANGE: All API responses now use camelCase keys
|
|
106
|
+
instead of snake_case. Update client parsers accordingly.
|
|
107
|
+
|
|
108
|
+
Migration guide: https://docs.example.com/v2-migration
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### Multiple Footers
|
|
112
|
+
```
|
|
113
|
+
fix(payments): correct tax calculation for EU customers
|
|
114
|
+
|
|
115
|
+
Updated tax calculation to use customer's billing country
|
|
116
|
+
instead of shipping country for digital goods.
|
|
117
|
+
|
|
118
|
+
Fixes #456
|
|
119
|
+
Reviewed-by: Alice
|
|
120
|
+
Co-authored-by: Bob <bob@example.com>
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
### Revert Commit
|
|
124
|
+
```
|
|
125
|
+
revert: feat(auth): add OAuth2 support
|
|
126
|
+
|
|
127
|
+
This reverts commit abc123def456.
|
|
128
|
+
|
|
129
|
+
Reason: OAuth provider has rate limiting issues in production.
|
|
130
|
+
Will re-implement with proper caching.
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
## Description Guidelines
|
|
134
|
+
|
|
135
|
+
### Do
|
|
136
|
+
- Use imperative mood: "add" not "added" or "adds"
|
|
137
|
+
- Keep under 72 characters
|
|
138
|
+
- Start with lowercase
|
|
139
|
+
- No period at the end
|
|
140
|
+
- Be specific and concise
|
|
141
|
+
|
|
142
|
+
### Don't
|
|
143
|
+
- "Fixed bug" (too vague)
|
|
144
|
+
- "Updated stuff" (not descriptive)
|
|
145
|
+
- "WIP" (commit when ready)
|
|
146
|
+
- "misc changes" (split into separate commits)
|
|
147
|
+
|
|
148
|
+
### Good Examples
|
|
149
|
+
```bash
|
|
150
|
+
feat: add email verification flow
|
|
151
|
+
fix: prevent duplicate form submissions
|
|
152
|
+
refactor: extract payment processing to service
|
|
153
|
+
perf: cache user preferences in memory
|
|
154
|
+
docs: add API authentication examples
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
### Bad Examples
|
|
158
|
+
```bash
|
|
159
|
+
# Too vague
|
|
160
|
+
fix: fixed it
|
|
161
|
+
update: updates
|
|
162
|
+
|
|
163
|
+
# Wrong tense
|
|
164
|
+
feat: added new feature
|
|
165
|
+
fix: fixes the bug
|
|
166
|
+
|
|
167
|
+
# Too long
|
|
168
|
+
feat: add a new feature that allows users to export their data in multiple formats including CSV, JSON, and XML
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
## Body Guidelines
|
|
172
|
+
|
|
173
|
+
When to include a body:
|
|
174
|
+
- Changes need context or explanation
|
|
175
|
+
- Complex logic that isn't self-evident
|
|
176
|
+
- Breaking changes require migration info
|
|
177
|
+
- Multiple related changes in one commit
|
|
178
|
+
|
|
179
|
+
```
|
|
180
|
+
fix(cache): invalidate user cache on profile update
|
|
181
|
+
|
|
182
|
+
Previously, profile updates were not reflected until cache expiry.
|
|
183
|
+
This caused confusion when users updated their avatar and didn't
|
|
184
|
+
see the change immediately.
|
|
185
|
+
|
|
186
|
+
The fix adds cache invalidation after successful profile updates
|
|
187
|
+
and ensures CDN purge for static assets.
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
## Footer Tokens
|
|
191
|
+
|
|
192
|
+
| Token | Purpose | Example |
|
|
193
|
+
|-------|---------|---------|
|
|
194
|
+
| `Fixes` | Closes issue | `Fixes #123` |
|
|
195
|
+
| `Closes` | Closes issue | `Closes #456` |
|
|
196
|
+
| `Refs` | References issue | `Refs #789` |
|
|
197
|
+
| `BREAKING CHANGE` | Breaking change | `BREAKING CHANGE: description` |
|
|
198
|
+
| `Reviewed-by` | Reviewer credit | `Reviewed-by: Name` |
|
|
199
|
+
| `Co-authored-by` | Co-author credit | `Co-authored-by: Name <email>` |
|
|
200
|
+
|
|
201
|
+
## Integration with Tooling
|
|
202
|
+
|
|
203
|
+
### Commitlint Configuration
|
|
204
|
+
|
|
205
|
+
```javascript
|
|
206
|
+
// commitlint.config.js
|
|
207
|
+
module.exports = {
|
|
208
|
+
extends: ['@commitlint/config-conventional'],
|
|
209
|
+
rules: {
|
|
210
|
+
'type-enum': [
|
|
211
|
+
2,
|
|
212
|
+
'always',
|
|
213
|
+
[
|
|
214
|
+
'feat', 'fix', 'docs', 'style', 'refactor',
|
|
215
|
+
'perf', 'test', 'build', 'ci', 'chore', 'revert'
|
|
216
|
+
]
|
|
217
|
+
],
|
|
218
|
+
'scope-case': [2, 'always', 'kebab-case'],
|
|
219
|
+
'subject-case': [2, 'always', 'lower-case'],
|
|
220
|
+
'subject-max-length': [2, 'always', 72],
|
|
221
|
+
'body-max-line-length': [2, 'always', 100]
|
|
222
|
+
}
|
|
223
|
+
};
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
### Husky Pre-commit Hook
|
|
227
|
+
|
|
228
|
+
```bash
|
|
229
|
+
# .husky/commit-msg
|
|
230
|
+
#!/bin/sh
|
|
231
|
+
. "$(dirname "$0")/_/husky.sh"
|
|
232
|
+
npx --no-install commitlint --edit "$1"
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
### Package.json Setup
|
|
236
|
+
|
|
237
|
+
```json
|
|
238
|
+
{
|
|
239
|
+
"devDependencies": {
|
|
240
|
+
"@commitlint/cli": "^18.0.0",
|
|
241
|
+
"@commitlint/config-conventional": "^18.0.0",
|
|
242
|
+
"husky": "^8.0.0"
|
|
243
|
+
},
|
|
244
|
+
"scripts": {
|
|
245
|
+
"prepare": "husky install"
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
## Semantic Release Integration
|
|
251
|
+
|
|
252
|
+
Conventional commits enable automated versioning:
|
|
253
|
+
|
|
254
|
+
```yaml
|
|
255
|
+
# .releaserc.yml
|
|
256
|
+
branches:
|
|
257
|
+
- main
|
|
258
|
+
plugins:
|
|
259
|
+
- "@semantic-release/commit-analyzer"
|
|
260
|
+
- "@semantic-release/release-notes-generator"
|
|
261
|
+
- "@semantic-release/changelog"
|
|
262
|
+
- "@semantic-release/npm"
|
|
263
|
+
- "@semantic-release/git"
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
### Version Bumping Rules
|
|
267
|
+
|
|
268
|
+
| Commit Type | Version Bump | Example |
|
|
269
|
+
|-------------|--------------|---------|
|
|
270
|
+
| `feat` | Minor (0.X.0) | 1.2.0 -> 1.3.0 |
|
|
271
|
+
| `fix` | Patch (0.0.X) | 1.2.0 -> 1.2.1 |
|
|
272
|
+
| `perf` | Patch (0.0.X) | 1.2.0 -> 1.2.1 |
|
|
273
|
+
| `BREAKING CHANGE` | Major (X.0.0) | 1.2.0 -> 2.0.0 |
|
|
274
|
+
| Others | No bump | 1.2.0 -> 1.2.0 |
|
|
275
|
+
|
|
276
|
+
## Commit Message Generator
|
|
277
|
+
|
|
278
|
+
When analyzing changes, generate a commit message:
|
|
279
|
+
|
|
280
|
+
```bash
|
|
281
|
+
# 1. Check staged changes
|
|
282
|
+
git diff --cached --name-only
|
|
283
|
+
|
|
284
|
+
# 2. Analyze change type
|
|
285
|
+
# - New files = likely feat
|
|
286
|
+
# - Modified test files = test
|
|
287
|
+
# - Modified docs = docs
|
|
288
|
+
# - Bug-related keywords = fix
|
|
289
|
+
|
|
290
|
+
# 3. Identify scope from path
|
|
291
|
+
# src/components/Button.tsx -> components or ui
|
|
292
|
+
# src/services/auth.ts -> auth or services
|
|
293
|
+
|
|
294
|
+
# 4. Generate message
|
|
295
|
+
feat(ui): add loading state to Button component
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
## Best Practices
|
|
299
|
+
|
|
300
|
+
1. **One logical change per commit**: Don't mix features with fixes
|
|
301
|
+
2. **Commit early, commit often**: Small, focused commits
|
|
302
|
+
3. **Write for reviewers**: Messages should explain why, not just what
|
|
303
|
+
4. **Reference issues**: Link to tickets/issues when applicable
|
|
304
|
+
5. **Use scopes consistently**: Establish team conventions
|
|
305
|
+
6. **Review before committing**: `git diff --cached` to verify changes
|
|
306
|
+
|
|
307
|
+
## Output Checklist
|
|
308
|
+
|
|
309
|
+
Every commit message should:
|
|
310
|
+
|
|
311
|
+
- [ ] Start with valid type (feat, fix, docs, etc.)
|
|
312
|
+
- [ ] Use imperative mood in description
|
|
313
|
+
- [ ] Keep description under 72 characters
|
|
314
|
+
- [ ] Include scope when applicable
|
|
315
|
+
- [ ] Mark breaking changes with `!` or footer
|
|
316
|
+
- [ ] Reference related issues in footer
|
|
317
|
+
- [ ] Provide body for complex changes
|
|
318
|
+
- [ ] Follow team's scope conventions
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: docker
|
|
3
|
+
description: Docker containerization best practices for building, securing, and deploying containers.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Docker Development
|
|
7
|
+
|
|
8
|
+
You are an expert in Docker containerization, image building, and container orchestration.
|
|
9
|
+
|
|
10
|
+
## Core Principles
|
|
11
|
+
|
|
12
|
+
- Build minimal, secure container images
|
|
13
|
+
- Follow the principle of one process per container
|
|
14
|
+
- Use official base images when possible
|
|
15
|
+
- Implement proper layer caching strategies
|
|
16
|
+
- Never store secrets in images
|
|
17
|
+
|
|
18
|
+
## Dockerfile Best Practices
|
|
19
|
+
|
|
20
|
+
### Multi-Stage Builds
|
|
21
|
+
- Use multi-stage builds to reduce image size
|
|
22
|
+
- Separate build and runtime stages
|
|
23
|
+
- Copy only necessary artifacts to final image
|
|
24
|
+
|
|
25
|
+
### Layer Optimization
|
|
26
|
+
- Order instructions from least to most frequently changing
|
|
27
|
+
- Combine RUN commands to reduce layers
|
|
28
|
+
- Use .dockerignore to exclude unnecessary files
|
|
29
|
+
- Clean up package manager caches in same layer
|
|
30
|
+
|
|
31
|
+
### Base Images
|
|
32
|
+
- Use specific version tags, not `latest`
|
|
33
|
+
- Prefer slim or alpine variants for smaller size
|
|
34
|
+
- Scan base images for vulnerabilities
|
|
35
|
+
- Consider distroless images for production
|
|
36
|
+
|
|
37
|
+
## Security Best Practices
|
|
38
|
+
|
|
39
|
+
- Run containers as non-root user
|
|
40
|
+
- Use read-only file systems where possible
|
|
41
|
+
- Implement health checks
|
|
42
|
+
- Scan images for vulnerabilities regularly
|
|
43
|
+
- Use secrets management, not environment variables for sensitive data
|
|
44
|
+
- Implement resource limits (CPU, memory)
|
|
45
|
+
|
|
46
|
+
## Docker Compose
|
|
47
|
+
|
|
48
|
+
### Configuration
|
|
49
|
+
- Use version 3+ compose files
|
|
50
|
+
- Define networks explicitly
|
|
51
|
+
- Use volumes for persistent data
|
|
52
|
+
- Implement depends_on with health checks
|
|
53
|
+
- Use environment files for configuration
|
|
54
|
+
|
|
55
|
+
### Development Workflow
|
|
56
|
+
- Mount source code for hot reloading
|
|
57
|
+
- Use override files for environment-specific config
|
|
58
|
+
- Implement proper logging drivers
|
|
59
|
+
- Use build args for build-time variables
|
|
60
|
+
|
|
61
|
+
## CI/CD Integration
|
|
62
|
+
|
|
63
|
+
- Build images in CI pipelines
|
|
64
|
+
- Tag images with git commit SHA
|
|
65
|
+
- Push to secure container registries
|
|
66
|
+
- Implement automated vulnerability scanning
|
|
67
|
+
- Use image signing for verification
|
|
68
|
+
|
|
69
|
+
## Networking
|
|
70
|
+
|
|
71
|
+
- Use user-defined bridge networks
|
|
72
|
+
- Implement service discovery via DNS
|
|
73
|
+
- Expose only necessary ports
|
|
74
|
+
- Use network aliases for service communication
|
|
75
|
+
|
|
76
|
+
## Logging and Monitoring
|
|
77
|
+
|
|
78
|
+
- Use appropriate logging drivers
|
|
79
|
+
- Implement structured logging
|
|
80
|
+
- Forward logs to centralized system
|
|
81
|
+
- Monitor container metrics
|
|
82
|
+
- Implement proper health checks
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: jest
|
|
3
|
+
description: Jest testing best practices for JavaScript and TypeScript applications, covering test structure, mocking, and assertion patterns.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Jest Testing Best Practices
|
|
7
|
+
|
|
8
|
+
You are an expert in JavaScript, TypeScript, and Jest testing.
|
|
9
|
+
|
|
10
|
+
## Core Principles
|
|
11
|
+
|
|
12
|
+
### Test Structure
|
|
13
|
+
- Use descriptive test names that clearly explain expected behavior
|
|
14
|
+
- Organize tests using `describe` blocks for logical grouping
|
|
15
|
+
- Follow the Arrange-Act-Assert (AAA) pattern in each test
|
|
16
|
+
- Keep tests focused on a single behavior or outcome
|
|
17
|
+
|
|
18
|
+
### Setup and Teardown
|
|
19
|
+
- Use `beforeEach` and `afterEach` for test isolation
|
|
20
|
+
- Use `beforeAll` and `afterAll` for expensive setup that can be shared
|
|
21
|
+
- Clean up any side effects in teardown hooks
|
|
22
|
+
|
|
23
|
+
### Mocking
|
|
24
|
+
- Use `jest.mock()` for module mocking
|
|
25
|
+
- Use `jest.fn()` for function mocks
|
|
26
|
+
- Use `jest.spyOn()` when you need to track calls but keep implementation
|
|
27
|
+
- Clear mocks between tests with `jest.clearAllMocks()`
|
|
28
|
+
- Avoid over-mocking: test real behavior when feasible
|
|
29
|
+
|
|
30
|
+
### Assertions
|
|
31
|
+
- Use the most specific matcher available
|
|
32
|
+
- Prefer `toEqual` for object comparison, `toBe` for primitives
|
|
33
|
+
- Use `toMatchSnapshot` sparingly and with meaningful names
|
|
34
|
+
- Include negative test cases (what should NOT happen)
|
|
35
|
+
|
|
36
|
+
### Async Testing
|
|
37
|
+
- Always return promises or use async/await in async tests
|
|
38
|
+
- Use `waitFor` from testing libraries for async assertions
|
|
39
|
+
- Set appropriate timeouts for long-running tests
|
|
40
|
+
|
|
41
|
+
### Coverage
|
|
42
|
+
- Aim for meaningful coverage, not just high percentages
|
|
43
|
+
- Test edge cases and error conditions
|
|
44
|
+
- Use `--coverage` flag to track coverage metrics
|
|
45
|
+
|
|
46
|
+
### Best Practices
|
|
47
|
+
- Keep tests DRY but readable (prefer clarity over brevity)
|
|
48
|
+
- Test behavior, not implementation details
|
|
49
|
+
- Make tests deterministic (no random data without seeding)
|
|
50
|
+
- Use factories or builders for test data creation
|
|
51
|
+
|
|
52
|
+
## Example Patterns
|
|
53
|
+
|
|
54
|
+
```javascript
|
|
55
|
+
describe('fetchUser', () => {
|
|
56
|
+
it('should return user data when API call succeeds', async () => {
|
|
57
|
+
const mockUser = { id: 1, name: 'John' };
|
|
58
|
+
jest.spyOn(api, 'get').mockResolvedValue(mockUser);
|
|
59
|
+
|
|
60
|
+
const result = await fetchUser(1);
|
|
61
|
+
|
|
62
|
+
expect(result).toEqual(mockUser);
|
|
63
|
+
expect(api.get).toHaveBeenCalledWith('/users/1');
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it('should throw error when API call fails', async () => {
|
|
67
|
+
jest.spyOn(api, 'get').mockRejectedValue(new Error('Not found'));
|
|
68
|
+
|
|
69
|
+
await expect(fetchUser(999)).rejects.toThrow('Not found');
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
```
|