Public: anyone can read this; the crew can change it.

Migrated from github.com/amirmushichge/pixel-plays

Keep the full `bun test` well inside the deploy's 600 s limit as the catalogue grows #233

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

mason/pixel-plays:mason/227-keep-the-full-bun-test-well-inside-the-d → main 2 commits fork

  • Merged. mason/227-keep-the-full-bun-test-well-inside-the-d was merged into main as 3cf6063.

Review

Sign in to review this change.
4 files changed +45 −19
README.md +1 −1

Diff not shown — a line 2,117 characters wide (limit 2,000). +1 −1

View file
playtest.mjs +3
@@ -110,6 +110,9 @@ export function boot(id, { seed = 1 } = {}) {
110110 },
111111 // number of distinct colours painted: a blank frame has one
112112 colours() { return image ? new Set(new Uint32Array(image.data.buffer)).size : 0; },
113 // from now on the page's own `draw` is left out, which is most of what a frame costs: for a twin that is
114 // only stepped on and read for its text (a game without a `draw` function is unaffected)
115 stopDrawing() { try { evaluate('typeof draw === "function" && (draw = () => {})'); } catch (e) { errors.push(e); } },
113116 // advance by `seconds` of play
114117 frames: 0,
115118 run(seconds) { api.step(Math.round(seconds * 25)); }, // 25 fps: the games cap a step at 1/25 s, so none runs slower than real time
playtest.test.mjs +36 −15
@@ -30,23 +30,35 @@ test('every game has a scripted round, and every script has a game', () => {
3030
3131 test('the games folder is not empty', () => { expect(GAMES.length).toBeGreaterThanOrEqual(19); });
3232
33 // What one game's playtests may cost together, in milliseconds: a slow page fails in its own pull,
34 // by name, rather than as the whole suite running out of time. A scripted round plays the game for
35 // as long as the game lasts (twice, with its untouched twin), so each second of it adds a little.
36 const GAME_BUDGET = 15_000, PER_ROUND_SECOND = 300;
37 const budgetOf = seconds => GAME_BUDGET + PER_ROUND_SECOND * seconds;
38 const spent = {}, roundSeconds = {};
39 const timed = (id, fn) => () => { const t = performance.now(); try { return fn(); } finally { spent[id] = (spent[id] ?? 0) + performance.now() - t; } };
40
3341 for (const id of GAMES) {
34 test(`${id}: boots, paints a picture and says what to do`, () => {
35 const g = boot(id);
42 // the first two tests only read this boot, so they share it: the second carries on from the first
43 let shared;
44 const idler = () => (shared ??= boot(id));
45
46 test(`${id}: boots, paints a picture and says what to do`, timed(id, () => {
47 const g = idler();
3648 g.run(2);
3749 expect(g.errors.map(e => e.message)).toEqual([]);
3850 expect(g.colours()).toBeGreaterThan(40);
3951 expect(g.text().length).toBeGreaterThan(10);
40 });
52 }));
4153
42 test(`${id}: untouched, it idles for four seconds without failing`, () => {
43 const g = boot(id);
44 g.run(4);
54 test(`${id}: untouched, it idles for four seconds without failing`, timed(id, () => {
55 const g = idler();
56 g.run(2); // two seconds on from the first test: four in all
4557 expect(g.errors.map(e => e.message)).toEqual([]);
4658 expect(g.colours()).toBeGreaterThan(40);
47 });
59 }));
4860
49 test(`${id}: pointer play throws nothing, and the picture and the HUD text differ from an untouched twin`, () => {
61 test(`${id}: pointer play throws nothing, and the picture and the HUD text differ from an untouched twin`, timed(id, () => {
5062 // same seed, same frame count: only the player's input tells the two apart
5163 const idle = boot(id, { seed: 7 }), g = boot(id, { seed: 7 }), r = rand(11);
5264 let picture = false, words = false;
@@ -60,9 +72,9 @@ for (const id of GAMES) {
6072 expect(picture).toBe(true);
6173 expect(words).toBe(true);
6274 expect(g.colours()).toBeGreaterThan(40);
63 });
75 }));
6476
65 test(`${id}: the keyboard alone changes the game compared with leaving it be`, () => {
77 test(`${id}: the keyboard alone changes the game compared with leaving it be`, timed(id, () => {
6678 const idle = boot(id, { seed: 3 }), played = boot(id, { seed: 3 }), r = rand(5);
6779 let parted = false;
6880 for (let i = 0; i < 20 && !parted; i++) {
@@ -73,17 +85,26 @@ for (const id of GAMES) {
7385 }
7486 expect(played.errors.map(e => e.message)).toEqual([]);
7587 expect(parted).toBe(true);
76 });
88 }));
7789
78 test(`${id}: a scripted round reaches its end and the HUD names the outcome`, () => {
90 test(`${id}: a scripted round reaches its end and the HUD names the outcome`, timed(id, () => {
7991 const { ended, seconds, errors } = playRound(id);
8092 expect(errors.map(e => e.message)).toEqual([]);
8193 expect(ended).not.toBeNull();
8294 expect(ended).toMatch(ROUNDS[id].outcome); // the win or the loss, with its number
8395 expect(seconds).toBeLessThan(ROUNDS[id].limit ?? 100);
8496 // an untouched game does not reach that outcome in the same time (it may still end, by failing)
85 const idle = boot(id);
86 idle.run(seconds);
97 roundSeconds[id] = seconds;
98 // the untouched boot of the first two tests, carried on to the same moment (a fresh one if the round ended sooner than they ran)
99 const idle = idler().frames <= seconds * 25 ? idler() : boot(id);
100 idle.stopDrawing(); // only its text is read at the end
101 idle.step(seconds * 25 - idle.frames);
87102 expect(idle.text()).not.toMatch(ROUNDS[id].outcome);
88 }, ROUNDS[id].budget ?? 120_000); // a timed round (wood-split's 60 s) is played twice in the engine's software renderer
103 }), ROUNDS[id].budget ?? 120_000); // a timed round (wood-split's 60 s) is played twice in the engine's software renderer
104
105 test(`${id}: its playtests together stay within ${GAME_BUDGET / 1000} s and ${PER_ROUND_SECOND} ms per second of the round`, () => {
106 expect(roundSeconds[id]).toBeDefined(); // the game's other tests ran first: run alone, there is nothing to weigh
107 const ms = Math.round(spent[id]), budget = budgetOf(roundSeconds[id] ?? 0);
108 expect(`${id} took ${Math.min(ms, budget)} ms`).toBe(`${id} took ${ms} ms`); // names the game and its time when over
109 });
89110 }
serve.test.mjs +5 −3
@@ -240,10 +240,12 @@ test('every game and the home page carry share-card tags and a served PNG card',
240240 test('every committed card is what the games render now, and capture is deterministic', async () => {
241241 const { games, capture, card, collage } = await import('./scripts/og.mjs');
242242 const { readFileSync } = await import('node:fs');
243 const frames = [];
244 for (const g of games()) {
243 const frames = [], all = games();
244 // determinism is checked on the first, middle and last game: a second capture of each costs as much as the first
245 const again = new Set([0, Math.floor(all.length / 2), all.length - 1]);
246 for (const [i, g] of all.entries()) {
245247 const frame = capture(g.id);
246 expect(Buffer.from(capture(g.id)).equals(Buffer.from(frame))).toBe(true);
248 if (again.has(i)) expect(Buffer.from(capture(g.id)).equals(Buffer.from(frame))).toBe(true);
247249 frames.push(frame);
248250 expect(card(frame).equals(readFileSync(new URL(`./og/${g.id}.png`, import.meta.url)))).toBe(true);
249251 }

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs