import { test, expect, type Page } from "@playwright/test"; import { existsSync } from "node:fs"; import { resolve } from "node:path"; const romPath = resolve( process.env.CRYSTAL_ROM_PATH ?? "Pokemon - Crystal Version (UE) (V1.1) [C][!].gbc", ); test.beforeEach(() => test.skip(!existsSync(romPath), "Requires the local user ROM.")); async function start(page: Page) { await page.route("**/src/game/runtime.ts", async (route) => { const response = await route.fetch(), source = await response.text(); const needle = "const world = new GameWorld(assets);"; expect(source).toContain(needle); // Fixture worlds stand in for a saved session, so no introduction runs. expect(source).toContain("this.world?.beginIntro();"); await route.fulfill({ response, body: source.replace("this.world?.beginIntro();", "").replace( needle, `const { pokedexFixtureWorld } = await import('/tests/pokedex-fixture.ts'); const world = pokedexFixtureWorld(assets);`, ), }); }); await page.clock.install({ time: new Date("2026-09-22T12:00:00") }); await page.goto("/"); await page.locator("#rom-file").setInputFiles(romPath); await expect(page.locator("#status")).toContainText("verified"); await page.clock.pauseAt(new Date("2026-09-22T12:05:00")); await page.locator("#play").click(); } test("the Map tab shows the Johto atlas with the player and open areas", async ({ page }) => { const errors: string[] = []; page.on("pageerror", (error) => errors.push(error.message)); await start(page); await page.locator("#tab-map").click(); const atlas = page.locator("#atlas"); await expect(atlas).toBeVisible(); await expect(page.locator("#atlas-title")).toHaveText("Johto"); await expect(page.locator("#atlas-regions button")).toHaveCount(0); await expect(page.locator("#atlas-here")).toHaveText("You are in NEW BARK TOWN."); await expect(page.locator("#atlas-map")).toHaveAttribute("aria-label", "Johto map, you are in NEW BARK TOWN"); const open = page.locator("#atlas-open li"); await expect(open.first()).toHaveText("NEW BARK TOWN"); await expect(page.locator("#atlas-open")).toContainText("VIOLET CITY"); await expect(page.locator("#atlas-open")).toContainText("AZALEA TOWN"); await expect(page.locator("#atlas-open")).toContainText("BLACKTHORN CITY"); // Mt. Silver's cave is on Johto's map, opened with Kanto's postgame. await expect(page.locator("#atlas-open")).toContainText("SILVER CAVE"); expect(errors).toEqual([]); });