ReviewOS

stacks/ts-images

Rewrite skipped tests without sharp (analyze, core, favicon, og, processor, responsive, sprite-generator, watermark)

#1947
Closed glennmichael123 opened this 8 days ago ·
8 days ago

Context

8 test files were stubbed out in 7326372 because they imported sharp and the sharp dep is no longer installed (and per project rule, won't be reintroduced):

  • test/analyze.test.ts
  • test/core.test.ts
  • test/favicon.test.ts
  • test/og.test.ts
  • test/processor.test.ts
  • test/responsive.test.ts
  • test/sprite-generator.test.ts
  • test/watermark.test.ts

Each is now a describe.skip(...) placeholder. Original bodies are recoverable from git history (git show 918ac9d:packages/ts-images/test/<file>).

What sharp was used for

Two distinct patterns across the 30+ call sites:

  1. Fixture generation: sharp({ create: { width, height, channels, background } }).png().toFile(...) — synthesizing solid-color test images on the fly
  2. Metadata assertions: await sharp(path).metadata() — reading width/height/format from output files to verify ts-images produced the right thing

Proposal

  • Metadata reads → dogfood: replace sharp(x).metadata() with getMetadata(await Bun.file(x).bytes()) from src/codecs/index.ts (already exported as ImageMetadata)
  • Fixture generation: pre-commit small synthetic fixtures (PNG/JPEG/WebP at a few sizes) to test/fixtures/ instead of generating at runtime. Saves test time too.
  • Restore each test file from history once metadata + fixture path is sorted, swapping sharp calls for the replacements above
  • Drop the it.skip('placeholder') and the describe.skip once each file is back to real coverage

Out of scope

  • Reintroducing sharp as a dep — explicitly ruled out

Why this matters

  • Restores test coverage for the core processing functions (currently 8 of ~16 test files are skipped)
  • Forces ts-images to expose metadata reads as a first-class API (it already has getMetadata in codecs — this just exercises it)
8 days ago

Resolved in 8c6b50d — restored all 8 test files with sharp calls rewritten against a new dogfooding helper (test/utils/test-helpers.ts) using ts-images' own createImageData + encode for fixtures and getMetadata for assertions. 37 tests pass.

Sign in to comment on this issue.