explodorama / files / test / sprites.test.ts
sprites.test.ts
| 1 | import { readdirSync, readFileSync } from 'node:fs' |
| 2 | import { join } from 'node:path' |
| 3 | import { describe, expect, it } from 'vitest' |
| 4 | |
| 5 | /** A PNG's width and height, from its IHDR chunk. */ |
| 6 | function pngSize(file: string): string { |
| 7 | const png = readFileSync(file) |
| 8 | return `${png.readUInt32BE(16)} × ${png.readUInt32BE(20)}` |
| 9 | } |
| 10 | |
| 11 | describe('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 | }) |