karawaci.kode

2026-04-01 · 6 min

Test strategy untuk Astro static site — apa yang worth test, apa yang tidak

Tidak semua project butuh test pyramid yang sama. Astro static site (blog, marketing site, dokumentasi) punya surface area yang berbeda dari aplikasi SaaS — sebagian besar code adalah configuration + content, bukan business logic.

Setelah 2 tahun maintain ~10 Astro project dengan setup test berbeda, saya develop opinion tentang apa yang worth invest dan apa yang waste of time untuk static site.

Worth invest (4 layer)

1. Build verification di CI

Apa: run bun run build di GitHub Actions atau Cloudflare Pages preview ke setiap PR.

Kenapa: Catch type errors, content schema violations, broken imports sebelum merge. Sebagian besar bug di static site adalah build-time error, bukan runtime.

Cost: ~30s per PR di GHA. Negligible.

ROI: sangat tinggi. Saya catch ~10 bug per bulan dari ini saja.

Apa: automated check bahwa semua internal link di rendered HTML pointing ke valid URL.

Tools: linkinator atau custom script.

Kenapa: Static site sering punya 100+ internal links. Refactor URL structure = mudah lupa update beberapa link. Broken link = bad SEO + bad UX.

Cost: ~1min per build untuk check 200 links. Run mingguan di scheduled job, atau setiap deploy.

ROI: tinggi. Saya pernah temukan 7 broken link di refactor URL structure, semuanya dari link checker.

3. Smoke test rendered HTML

Apa: simple Playwright atau Puppeteer script yang load 5-10 page penting, check page render tanpa JS error di console, check critical elements exist (h1, main content).

Kenapa: Catch rendering issue yang tidak detected oleh build (e.g., View Transitions misconfig, missing image alt, schema markup invalid).

Cost: Setup ~2 jam, ongoing ~2min per PR.

ROI: medium-high. Sangat berguna setelah animation atau interactive features.

4. Content schema validation

Apa: rely pada Astro Content Collections Zod schema validation di build time. Jangan bypass.

Kenapa: Schema yang strict catch data entry error (missing field, wrong type) sebelum publish. Saya rules: setiap field optional perlu justifikasi.

Cost: Setup time saat define schema. Ongoing zero.

ROI: sangat tinggi. Schema strict = content quality consistent across team.

Tidak worth invest (3 layer)

1. Unit test untuk component Astro

Apa yang sering dilakukan: test bahwa component render specific HTML output.

Kenapa skip: Astro component sebagian besar adalah template — output = input + style. Test “given props X, render HTML Y” sebenarnya test compiler, bukan logic. Brittle (break setiap UI tweak).

Alternative: Smoke test (layer 3 above) lebih effective per investment.

2. E2E test untuk semua flow

Apa yang sering dilakukan: Playwright suite yang test “user opens page, click button, sees X.”

Kenapa skip: Static site tidak punya user flow yang complex. Single page → read content → maybe click external link. Tidak ada state, tidak ada form submission yang complex.

Alternative: Smoke test untuk critical paths (5-10 pages), tidak lebih.

3. Visual regression test

Apa yang sering dilakukan: Percy, Chromatic, atau Playwright screenshot comparison.

Kenapa skip: Untuk most static site project, design changes lebih sering daripada code changes. Visual regression test = false positive overload (setiap design tweak = test failure).

Alternative: Manual review di preview deployment per PR. Mata manusia masih lebih efektif untuk subtle design issue.

Setup yang saya pakai

.github/workflows/ci.yml per project:

name: CI
on: [pull_request]
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: oven-sh/setup-bun@v2
        with: { bun-version: 1.3.11 }
      - run: bun install
      - run: bun run build
      - name: Link check
        run: bunx linkinator dist --silent --concurrency 10
      - name: Smoke test
        run: bun run test:smoke

Total CI time: ~2-3 min per PR. Catch ~80% of issue yang saya care about.

Pengecualian

Setup di atas asumsi static-mostly site (blog, dokumentasi, marketing). Kalau Astro project Anda punya:

  • Heavy interactive island (React/Vue/Svelte component dengan complex state) — tambah unit test untuk component itu specifically
  • Server endpoint (Astro SSR atau API routes) — tambah integration test untuk endpoint
  • A/B testing infrastructure — tambah E2E test untuk verifikasi variant rendering

Tetapi untuk most static site, build + link check + smoke test + content schema = sufficient coverage.

Bottom line

Test untuk static site harus optimize untuk catch bug at minimum cost. Setiap layer test yang Anda tambah punya ongoing maintenance burden — keep it minimal.


Setup ini stabil di 10 Astro project saya selama 2 tahun. Mileage may vary untuk project dengan SSR atau heavy interactivity.