alunduil / alunduil/blog.alunduil.com

Vitest runs unit tests for TypeScript utilities in CI

Aperta
#353 1 commento 0 reazioni 0 assegnatari Vedi su GitHub
enhancement javascript
Lingua principale
Astro
Stelle
1
Fork
1
Merge medio
6h 34m
PR unite (30g)
118

Descrizione

## Summary

Add Vitest as the repo's first JavaScript/TypeScript test runner and
wire it into CI, seeded with a regression test for the webmention
pagination loop.

## Motivation

`src/utils/getWebmentions.ts` now paginates the webmention.io jf2 API
via keyset cursor (#217, PR #351). The loop — accumulate batches,
advancing `since_id`, and stop on an empty batch — is project logic
worth locking down, but the repo has no JS/TS test runner: `bats.yml`
only covers the bash in `.claude/skills`, so a `.test.ts` file would
never execute. Bootstrapping Vitest gives this and future util logic
(`slugify`, OG-image helpers, etc.) a home for regression tests.

## Scope

- Add `vitest` devDependency and a minimal `vitest.config.ts` (jsdom not
needed for pure utils).
- Add a `test` script to `package.json`.
- Run it in CI — a step in `astro.yml` or a dedicated `vitest.yml`.
- First test, `src/utils/getWebmentions.test.ts`, mocking `global.fetch`:
- batches of `[100, 100, 30, []]` -> 230 entries across 4 fetch calls
(termination stops on the empty batch, not the short one).
- a single batch then empty `[30, []]` -> 30 entries, 2 fetch calls.
- `since_id` advances to the max `wm-id` of the prior batch on each
follow-up request (assert on the fetched URLs), and the returned
children are sorted newest-first by `wm-id`.
- stubbing `PUBLIC_WEBMENTION_IO_USERNAME` (astro:env) for the guard.

## Acceptance criteria

- [ ] `pnpm test` runs Vitest locally and passes.
- [ ] CI fails when a test fails.
- [ ] The getWebmentions test fails if pagination regresses to a single
fixed page, stops advancing `since_id`, or terminates on a short
batch instead of an empty one.

## Additional context

Follow-up from #217 / PR #351. Test-framework bootstrap deliberately
split out so the fix PR stays scoped to the one function.

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.