Provides testing strategies and logging patterns for Node.js/TypeScript and React applications, covering structured logging with pino, unit/integration testing with Vitest, and React component testing with Testing Library. Use when writing tests, setting up logging, or establishing testing patterns.
import pino from "pino"
export const logger = pino({
level: process.env.LOG_LEVEL || "info",
transport:
process.env.NODE_ENV === "development"
? { target: "pino-pretty" }
: undefined,
})
// Usage
logger.info({ port: 3000, env: "production" }, "Server started")
logger.error({ error, context: "riskyOperation" }, "Operation failed")
| Level | When to Use |
|---|---|
error | Errors needing immediate attention |
warn | Potential issues, deprecated usage |
info | High-level application flow |
debug | Detailed diagnostic information |
| Layer | Percentage | What to Test |
|---|---|---|
| Unit (70%) | ms | Pure functions, validators, business logic |
| Integration (20%) | seconds | API endpoints, database ops, service layer |
| E2E (10%) | minutes | Critical user journeys only |
import { describe, expect, it } from "vitest"
describe("formatDate", () => {
it("formats ISO date to readable string", () => {
expect(formatDate("2025-01-22T10:00:00Z")).toBe("January 22, 2025")
})
})
import { render, screen } from "@testing-library/react"
import userEvent from "@testing-library/user-event"
it("calls onClick when clicked", async () => {
const onClick = vi.fn()
render(<Button onClick={onClick}>Click</Button>)
await userEvent.click(screen.getByRole("button"))
expect(onClick).toHaveBeenCalledOnce()
})
getByRole — Accessible name (best)getByLabelText — Form labelsgetByText — Text contentgetByTestId — Last resortpnpm test # All tests
pnpm test:watch # Watch mode
pnpm test:coverage # With coverage