This guide explains how to add JSDoc to new/changed code, instrument logging with Pino, and write Jest tests in this pnpm/TypeScript monorepo.
JSDoc: document your public surface
-
When to add JSDoc
- Add JSDoc for exported functions, classes, public types, and any non-trivial logic.
- Keep it concise; explain the “why” and parameters/return types.
- Basic pattern (TypeScript)
-
Inline types vs TSDoc tags
- Prefer TypeScript types in signatures. Use JSDoc tags like
@example,@deprecated,@remarksfor extra context.
- Prefer TypeScript types in signatures. Use JSDoc tags like
-
Tips
- Keep examples small and copy‑pastable.
- Update JSDoc when behavior or parameters change.
Logging with Pino: structured, fast logs
-
Goals
- Use structured logs (JSON in production, pretty in dev).
- Add context: module name, request id, user id when available.
-
Install (per package/app that needs logging)
- Devs should add locally in the target workspace:
- Create a logger utility
- Create
logger.ts(or reuse an existing shared logger inpackages/observability/when available) with environment‑aware transports.
- Create
- Use in modules
- HTTP request logging (optional)
- For Node/Express/Fastify services, consider
pino-httpfor request‑scoped logs and request IDs.
- For Node/Express/Fastify services, consider
Testing with Jest: unit and integration
-
What to test
- Public functions, components, and critical branches (errors, edge cases).
- For React/Next.js, use
@testing-library/reactfor behavior tests.
- Install (per package/app)
- Minimal config (TypeScript)
- Create
jest.config.tsnext topackage.jsonof the target workspace:
- Create
- Example unit test
- Scripts
- Add to the package/app
package.json:
- Add to the package/app
- Next.js notes
- Use
testEnvironment: "jsdom"for component tests. - Mock Next/router and server modules as needed.
- Use
Pull request checklist
- JSDoc: Public APIs documented; examples updated.
- Logs: Key paths log
debugand success/error with context. No secrets in logs. - Tests: Unit tests covering main behavior and error paths; added
testscripts. - Consistency: Filenames, import paths, and configs follow the existing package conventions.
Where to put things in this repo
- Per‑package tooling: Install Jest/Pino in the specific
apps/*orpackages/*workspace that needs it. - Shared utilities: If a common logger module exists in
packages/observability/, prefer importing that to avoid duplication. - Docs: Update this page if conventions evolve.