Adding tests to an app that has none: where to start
A practical order for adding tests and CI to an untested Next.js or Node.js codebase, starting with the paths that cost money when they break.
Samed Škulj
· 3 min read
Many apps reach real customers with zero tests, especially ones built quickly with AI tools. Then every change becomes risky, deploys get scary, and the team slows down. Trying to reach high coverage across the whole app at once doesn't work. Here's the order I add tests in, so the first week already makes deploys safer.
Step 0: make the build fail on obvious mistakes
Before writing a single test, turn on the free checks:
- TypeScript in strict mode, and
tsc --noEmitin CI. If strict mode produces hundreds of errors, enable it per folder and fix incrementally. - Lint with rules that catch real bugs: unused variables, missing
await, React hook rules. - A production build in CI. If it doesn't build, it doesn't merge.
These catch a surprising share of bugs for almost no effort.
Step 1: smoke tests on the paths that touch money
List the three to five flows that would cost you customers or revenue if they broke. For most SaaS apps:
- Sign up and log in.
- The core action users pay for (create a booking, generate a report, send an invoice).
- Checkout and upgrade.
- Access control: a user can't see another organization's data.
Write one end-to-end test per flow with Playwright, running against a real build with a test database. Keep them coarse: "user signs up, creates a booking, sees it in the list". These tests are slow, so keep them few, but they catch the breakages that matter.
Step 2: tests for access rules
Access bugs are the most expensive and the easiest to reintroduce. For each important table or API route, add a test that:
- signs in as a user in organization A,
- tries to read and change a record from organization B,
- expects a denial.
If you're on Supabase, this is how you keep RLS policies from regressing.
Step 3: unit tests where logic is dense
Look for code with real logic: pricing calculations, date handling, permission checks, data transformations, parsing. Pull it into plain functions if it's buried in components or route handlers, and test those functions with Vitest or Jest. They are fast and give precise failures.
Don't start with unit tests for UI components that only render props. They rarely catch real bugs.
Step 4: a test for every bug you fix
From now on, every bug fix comes with a test that fails before the fix and passes after. This grows coverage exactly where the app has proven fragile.
Step 5: CI that runs on every pull request
A minimal pipeline:
name: ci
on: [pull_request]
jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with: { node-version: 20, cache: npm }
- run: npm ci
- run: npx tsc --noEmit
- run: npm run lint
- run: npm test
- run: npm run build
Add the end-to-end suite as a second job, against a preview deployment or a service container database. Protect the main branch so nothing merges with a red pipeline.
Step 6: preview deploys and easy rollbacks
Tests catch a lot, but not everything. Preview deployments per pull request let someone click through the change before it ships, and one-click rollbacks make the remaining mistakes short-lived.
What not to do
- Don't aim for a coverage percentage. Aim for coverage of what matters.
- Don't write tests that mirror the implementation line by line. They break on every refactor and catch nothing.
- Don't let flaky tests stay. A test that fails randomly teaches the team to ignore failures.
A week of this work typically turns "we're scared to deploy" into "we deploy daily". It's a standard part of an AI-built app rescue, and it's what makes the next step, rescue or rewrite, much safer either way.

Written by Samed Škulj
Senior Full-Stack Engineer since 2021. I have shipped with teams at Deel, HTEC Group (for Zoox), Ministry of Programming, and now help SaaS teams add AI features and get AI-built apps ready for production. LinkedIn