fuzzyworld

explodorama / files / test / sprites.test.ts

sprites.test.ts

Blame: the commit that last changed each line · file · history

52d68b59 2026-10-24 Pavel Safronov1import { readdirSync, readFileSync } from 'node:fs'
2import { join } from 'node:path'
3import { describe, expect, it } from 'vitest'
4
5/** A PNG's width and height, from its IHDR chunk. */
6function pngSize(file: string): string {
7 const png = readFileSync(file)
8 return `${png.readUInt32BE(16)} × ${png.readUInt32BE(20)}`
9}
10
11describe('board sprites', () => {
12 // LittleJS cuts a 128 × 128 tile out of each board texture (render/sprites.ts). A 100 px file
13 // gave an invalid tile, which crashed the game when a Freeze drop was drawn (2026-10-23).
14 for (const dir of ['assets/kenney', 'assets/composed']) {
15 it(`every PNG in ${dir} is 128 × 128`, () => {
16 const wrong = readdirSync(dir)
17 .filter((f) => f.endsWith('.png'))
18 .map((f) => `${f}: ${pngSize(join(dir, f))}`)
19 .filter((line) => !line.endsWith('128 × 128'))
20 expect(wrong).toEqual([])
21 })
22 }
23})