Make synthetic browser checks independent of private files and timing (#45)
Checks / web (push) Successful in 2m0s

This commit is contained in:
kawa committed 2026-10-03 18:20:30 +02:00
1 parent ad68ca87ce
commit a33ffa3a15
2 files changed
+26 -12

No files matched your search

+3 -7
View File
@@ -90,11 +90,9 @@ test("actual WASM executes an original cartridge, reads input and round-trips st
const emulator = new BinjgbEmulator((error) => {
throw error;
});
const wait = () => new Promise((resolve) => setTimeout(resolve, 180));
await emulator.load(new Uint8Array(bytes), canvas);
emulator.play();
await wait();
emulator.pause();
// Advance emulated frames independently of the CI browser's animation rate.
emulator.advanceFrames(12);
const before = emulator.exportBattery();
const state = emulator.captureState();
const pixels = canvas.getContext("2d")!.getImageData(0, 0, 160, 144).data;
@@ -102,9 +100,7 @@ test("actual WASM executes an original cartridge, reads input and round-trips st
for (let i = 0; i < pixels.length; i += 4)
colors.add(`${pixels[i]},${pixels[i + 1]},${pixels[i + 2]}`);
emulator.setButton("a", true);
emulator.play();
await wait();
emulator.pause();
emulator.advanceFrames(12);
const pressed = emulator.exportBattery()[0];
emulator.restoreState(state);
const restored = emulator.exportBattery()[0];
+23 -5
View File
@@ -1,7 +1,14 @@
import { test, expect } from "@playwright/test";
import { existsSync, readFileSync, writeFileSync } from "node:fs";
import {
existsSync,
mkdirSync,
mkdtempSync,
readFileSync,
rmSync,
writeFileSync,
} from "node:fs";
import { createHash } from "node:crypto";
import { resolve } from "node:path";
import { basename, join, resolve } from "node:path";
import { CrystalAssets } from "../src/game/rom/assets";
import { generatePartyMon } from "../src/game/party/pokemon";
import { GameWorld } from "../src/game/world/world";
@@ -420,12 +427,23 @@ test("walks from New Bark Town onto Route 29 after receiving a starter", async (
test("development server does not serve ROMs or the private reference checkout", async ({
request,
}) => {
// Missing paths can return Vite's HTML fallback. Exercise real files using
// disposable synthetic content, without depending on a private checkout.
const directory = mkdtempSync(resolve(".ci-private-"));
try {
mkdirSync(join(directory, ".reference"));
for (const file of ["fixture.gbc", ".reference/README.md"]) {
writeFileSync(join(directory, file), "Synthetic private-file test fixture");
for (const path of [
"/Pokemon%20-%20Crystal%20Version%20(UE)%20(V1.1)%20%5BC%5D%5B!%5D.gbc",
"/.reference/pokecrystal/README.md",
`/${basename(directory)}/${file}`,
`/@fs/${join(directory, file)}`,
]) {
const response = await request.get(path);
expect([403, 404]).toContain(response.status());
expect(response.status(), path).toBe(403);
}
}
} finally {
rmSync(directory, { recursive: true, force: true });
}
});