Who this is for: Every student who wants to solidify their knowledge. Watching tutorials is passive; writing tests against a complex codebase is active learning.
The Challenge: A Production-Ready Testing Suite
In this final module, you will not be writing an application from scratch. Instead, you will be handed a fully functioning, undocumented, untested full-stack application.
Your mission is to wrap this application in a bulletproof testing net, ensuring that future developers can refactor it without fear.
The Application: SecureAuth Pro
SecureAuth Pro is a Next.js (frontend) and Express.js (backend) application backed by PostgreSQL. It features user registration, JWT-based login, password resets, and a protected dashboard.
Project Deliverables
You must implement the entire Testing Pyramid and automate it.
Phase 1: Unit & Integration Testing (Jest & Supertest)
You will focus on the Node.js backend.
Middleware Testing: Write unit tests for the JWT authentication middleware. Mock the jsonwebtoken library. Ensure it returns 401 Unauthorized for expired tokens.
Database Mocking: Write unit tests for the UserRepository. Mock the Prisma/Sequelize database driver to test successful user creation and constraint violations (duplicate emails).
API Integration: Use Supertest to spin up the Express app in-memory. Write a test suite for POST /api/auth/login. Assert the response contains a valid token structure when correct credentials are provided.
Form Validation: Render the <RegistrationForm />. Use RTL to fill the inputs. Assert that clicking submit with an invalid email format renders an error boundary on the screen.
API Mocking: Render the <Dashboard /> component. Mock the global fetch API to simulate a successful data retrieval. Assert that the user's data renders correctly on the screen after the loading state resolves.
Phase 3: End-to-End Testing (Playwright)
You will test the system exactly as a real user would.
The Golden Path: Write a Playwright script that navigates to the homepage, clicks "Sign Up", fills the form, submits, logs in, and verifies the dashboard loads.
Auth Bypass: Implement a global-setup.js script to save the login state. Write a second test that navigates directly to /dashboard utilizing the saved state, proving it bypasses the login screen.
Network Interception: Intercept the backend API call on the login page. Force it to return a 500 Internal Server Error. Assert that the UI gracefully displays a toast notification to the user rather than crashing.
Phase 4: Automation (GitHub Actions)
You will protect the main branch.
CI Pipeline: Create a .github/workflows/main.yml file. Configure it to run the Jest suite and the Playwright suite on every pull request.
Coverage Gates: Configure Jest to fail the pipeline if branch coverage drops below 80%.
The Ultimate Goal
When you complete this capstone, you will have a portfolio-quality project demonstrating true full-stack testing capabilities.
More importantly, you will possess the engineering mindset required to join a production team, audit their testing architecture, and drastically improve their software reliability.
Key Takeaways
Real-world testing requires balancing different tools (Jest, RTL, Supertest, Playwright) across the full stack.
E2E tests are powerful but should be used sparingly for critical user journeys (like Auth).
Database mocking speeds up unit tests, but real integration tests are needed for full confidence.
A fully automated CI/CD pipeline is the ultimate deliverable of a strong testing strategy.
Knowledge Check
In Phase 1 of the Capstone project, you are instructed to use Jest to unit test the JWT authentication middleware. Why is unit testing (with a mocked jsonwebtoken library) the correct strategy here, rather than relying solely on Supertest integration tests?
In Phase 3, you write a Playwright E2E test that intercepts the network request to /api/auth/login and forces it to return a 500 Internal Server Error. What is the primary architectural value of this specific test?
Phase 4 of the Capstone requires configuring GitHub Actions to run the test suite and enforce a coverage gate on every Pull Request. Which foundational principle of the "Testing Pyramid" strategy does this automation enforce?
Test your knowledge with more question sets
Sign in to access a wider variety of questions and get notified when new practice sets are added to this module.