TETERI
How TETERI is built
Testing a Game Without Opening a Browser
Keeping the rules engine free of DOM references means the whole ruleset is testable from a terminal.
Games are notoriously hard to test, mostly because game logic tends to be tangled with rendering. Separating them makes a large amount of testing straightforward.
The separation
The rules engine, the versus maths, the gesture recogniser and the CPU opponent contain no reference to the DOM, canvas, audio or window. They are plain JavaScript modules operating on plain data.
The engine communicates outward by calling an event function it was handed. It does not know whether anything is drawn.
What that enables
The whole ruleset can be exercised from Node with no browser, no headless harness and no framework. node --test runs it in under a second.
The suite covers rotation states and kick tables, the seven-bag's distribution over thousands of draws, every path through the scoring table, T-spin detection including the mini and last-kick cases, lock delay, garbage insertion and cancelling, snapshot round-tripping, match orchestration, and the CPU's board evaluation.
The tests that found real bugs
A negative-zero in the kick table. The I-piece table is written in a y-up convention and negated at read time, which turned a zero offset into negative zero. It made no arithmetic difference and failed a deep equality assertion. Fixed at the source rather than by loosening the test.
A score of NaN. Clearing more than four rows at once ran off the end of the scoring array. Unreachable from a single piece in normal play, reachable from injected or networked state, and unrecoverable once it happened.
A double move per touch tap. Found by driving real pointer events and counting the resulting calls.
What still needs a browser
Layout, rendering, input plumbing, audio, the service worker and the WebRTC handshake. Those are covered by scripted browser sessions rather than unit tests.
The general lesson
The value of the separation is not purity. It is that the parts most likely to contain subtle logic bugs — scoring edge cases, rotation tables, garbage maths — became the parts that are cheapest to test exhaustively.
Read next
- The Soundtrack Is a Sequencer, Not a FileA four-bar progression with drums, bass, arpeggio and a lead, whose tempo and arrangement climb with your level.
- Online Play With No Server At AllWebRTC connects the two browsers directly; a public relay handles only the introduction.
- Seeded Randomness: Why Both Players Get the Same PiecesA small deterministic generator, one shared number, and two identical bags on different machines.
- How the CPU Opponent SearchesEnumerate every placement, score the resulting board on four weighted features, take the best.
- Score Chasing, Speedrunning and Community RecordsA game with no ending produces a different competitive culture to one with a finish line.
- The Lawsuit Over Who Could Publish ItTwo versions on the same console, one of them recalled, and a ruling that turned on what had actually been licensed.