344 tests, 46 per cent of them about money, and the only components we ever render in a test are two pricing cards
I had never counted what our tests are for. They pass, the suite is fast, and that was enough. This week I ran everything and sorted it, because I wanted to know what PubTrivia would catch if I broke it tomorrow.
The setup is plain. Vitest 4, environment: 'node', no jsdom, no browser, no mock server. The config includes **/__tests__/**/*.test.ts and one setup file that loads .env.local.
I left out one file, an integration test that needs a live database. Everything else ran.
The totals
Test Files 23 passed Tests 344 passed The slowest file took 282 ms. From the first file starting to the last finishing, the suite took about 1.2 seconds. The tests are 4,208 lines in total, against 59,214 lines of TypeScript that are not tests: 7.1 per cent.
What the 344 are about
I read each file's name and its first describe block, then put every test in one of six buckets.
| Area | Tests | Share |
|---|---|---|
| Pricing and display currency | 71 | 20.6% |
| Billing: checkout, webhooks, managed payments | 88 | 25.6% |
| In-game helpers and rules (several files) | 106 | 30.8% |
| Content registry and page metadata | 24 | 7.0% |
| The free tools | 24 | 7.0% |
| Infra: routes, maintenance mode, IndexNow, auth origin | 31 | 9.0% |
Money is 159 of 344, which is 46.2 per cent. It is the biggest block by a distance and it was not planned that way. It just happens that every time a price or a checkout bug cost us something, a test followed.
The shape is useful. The code that can charge someone the wrong amount has two and a half times as many tests as the code that decides what a visitor reads on our comparison pages, and that matches where a mistake would cost the most.
The part that surprised me: components
We have 18,004 lines of TypeScript under components/, and 27,646 under app/. Across all the test files, the imports from either directory are these:
- two pricing components, rendered to a string
- two small pure modules that happen to live in
components/ - three route handlers
- one server action
That is the whole list. No test renders the header, the footer, the host screen, the sign-up form, the tools or any page.
The two pricing renders deserve a mention because they show how far you can get with no browser. renderToStaticMarkup from react-dom/server turns a component into a string. The test renders the cards six times, once per currency, strips the tags and asserts on the text: the right figure is there, no pound sign shows up in a euro render, and none of a list of hedging words ("approximately", "converted", "exchange rate") appears. Twenty-eight tests, 147 ms. You can see the thing it protects on the pricing page: the price you are shown is the price at checkout, in your own currency, which is why the test is so strict about wording.
If you want to see it change, use a VPN exit in another country and reload that page.
The glob that decides what counts
include: ['**/__tests__/**/*.test.ts'] Only .test.ts. A file called Header.test.tsx would be silently ignored: no failure, no warning, zero tests found for that file. I searched the repo and there are no .test.tsx files, so nothing is being skipped today. But the day someone writes the first component test with JSX in it, the obvious filename is the wrong one, and the suite goes on passing.
The ws-server directory is its own TypeScript project, 2,290 lines, and it has no __tests__ folder. Its only connection to this suite is one file that reads two of its constants as text and checks they match the app's copies.
Four test files read source code as text
page-metadata.test.ts, price-copy.test.ts, session-health.test.ts and shared-constants.test.ts call readFileSync. The reason is the same each time: importing the module under test would boot a database client or an auth client, so the test reads the file and matches with a regular expression instead.
I have a mixed view of this. It is fast and it needs no mocks. It also means the test is checking that a string appears in a file, which is not quite the same as checking behaviour. The page metadata test is three tests that loop over about a hundred route files; that is cheap coverage and I would keep it. I would not extend the pattern to anything with logic in it.
What the suite cannot tell me
- Whether any page renders. A page that throws on a null would pass every test here.
- Whether the layout is right. Nothing opens a browser. I find layout bugs by looking, which is how the previous batch of posts found them.
- How much of the code is exercised. I did not run coverage for this post. The numbers above count tests by topic, not lines executed, and a topic with many tests can still miss its edges.
- The excluded file. I did not run the database integration test. I am reporting 344, not 345 or more, because that is what ran.
What I will change
- Widen the glob to
*.test.{ts,tsx}so the first component test is not ignored. - Add one render test for the footer and one for the header navigation, using the same
renderToStaticMarkupapproach, since those appear on every one of the 117 URLs in the sitemap. - Leave the money tests alone. They are the best thing in the suite.
If you want to see what the pages those tests do not render look like, the product is at pub-trivia.app. The free plan needs no card.