A practical reference for building a meaningful test suite in a PERN stack application — from unit tests to end-to-end coverage.
Most guides about testing fall into one of two traps: they either cover the theory without showing how it applies to the stack you are actually using, or they show you how to write one type of test without explaining where it fits in the bigger picture.
This guide does neither. It covers the full testing strategy for a PERN stack application — PostgreSQL, Express, React, Node.js — with TypeScript throughout. It explains why each layer of testing exists, what it is responsible for, and how to implement it with the tools that are standard in this ecosystem: Vitest, Supertest, Playwright, and Testing Library.
Every section includes real code. The code is structured to work with the project layout described in the PERN Stack Architecture Guide, but the testing principles apply regardless of your specific folder structure.
| Audience | How to use this |
|---|---|
| Developers who have never written tests for a full-stack application | Read Sections 1 through 4 in order — they build on each other |
| Developers who write some tests but do not have a coherent strategy | Section 2 on the test pyramid explains where each type of test belongs and why |
| Teams setting up a test suite from scratch | Sections 3 through 6 are the implementation reference with setup code and real examples |
| Developers who have slow or flaky tests and want to fix them | Section 9 on test quality covers the most common causes |
| # | Section | Summary |
|---|---|---|
| 1 | Why Testing | The actual cost of not testing, and what tests are really for |
| 2 | The Test Pyramid | Unit, integration, and E2E — what each layer is responsible for |
| 3 | Vitest Setup | Configuring Vitest for a Node.js backend and a React frontend |
| 4 | Unit Testing the Backend | Testing service layer business logic with mocks and pure functions |
| 5 | Integration Testing with Supertest | Testing API endpoints against a real test database |
| 6 | Testing the React Frontend | Component tests and hook tests with Testing Library |
| 7 | End-to-End Testing with Playwright | Critical user journeys tested in a real browser |
| 8 | Coverage Targets | What coverage means, what to measure, and what targets make sense |
| 9 | Test Quality | Writing tests that actually catch bugs — avoiding test theater |
| 10 | CI Integration | Running the full test suite in GitHub Actions on every pull request |
| 11 | Reference Library | All books and resources cited throughout this guide |
If you are setting up testing from scratch, start with Section 2 to understand the overall strategy, then work through Sections 3 to 7 in order. Each section builds on the setup from the previous one.
If you have tests but they are not giving you confidence, Section 9 on test quality is the most useful starting point. Most "testing problems" are actually problems with what is being tested and how, not with the tools.
If you want to add a CI pipeline for your tests, Section 10 has a complete GitHub Actions configuration ready to use.
This guide is part of a series on engineering and product development:
- Product Development Playbook — The complete 17-phase guide from idea to launch
- PERN Stack Architecture Guide — Clean architecture, layering, and project structure for PERN apps
- API Design Playbook — REST best practices, OpenAPI, pagination, versioning, and idempotency
- Database Design Guide — PostgreSQL schema design, indexing, migrations, and Prisma
- System Design for Web Developers — Architecture decisions from a web developer's perspective
- Auth Implementation Guide — Authentication and authorization for web applications
This guide draws from:
- Books: Unit Testing: Principles, Practices, and Patterns (Khorikov), Growing Object-Oriented Software, Guided by Tests (Freeman & Pryce), The Pragmatic Programmer (Hunt & Thomas) — all cited inline
- Engineering resources: Kent C. Dodds on testing philosophy, Google Testing Blog, Martin Fowler on test doubles
The full list is in Section 11 — Reference Library.
See CONTRIBUTING.md for guidelines on fixing errors, adding references, or suggesting new sections.
MIT License — free to use, adapt, and distribute. See LICENSE.
If this guide helped you, consider giving it a ⭐ — it helps others find it too.