Tutorials

Test the built site, not the dev server

What gets deployed and what runs in development are not the same artefact.

DébutantArticle4 steps

An end-to-end test run against the dev server verifies something that will never be deployed: modules are bundled differently, stylesheets differ, and static rendering never happened.

1. Make tests depend on the build

The task runner must refuse to start the tests until the build has succeeded. That rules out the whole class of “green tests on a broken build”.

2. Serve dist/

astro preview serves exactly what will ship. That is what the test runner should start.

3. Assert a real colour

Checking that an element exists says nothing about whether the stylesheet loaded. Comparing a computed colour to its expected value does.

4. Beware shell pipes

A pipeline’s exit code is that of its last command. A pnpm test | tail followed by && will push despite the failure.