import { chromium } from "playwright";
import { preview } from "vite";
const server = await preview({ preview: { port: 5194 } });
const browser = await chromium.launch();
const page = await browser.newPage({ viewport: { width: 1280, height: 720 } });
const errors = [];
page.on("console", m => { if (m.type() === "error") errors.push(m.text()); });
page.on("pageerror", e => errors.push(e.message));
await page.goto("http://localhost:5194/");
await page.waitForTimeout(2500);
await page.fill("#name-input", "");
await page.press("#name-input", "Enter");
await page.waitForTimeout(2000);
const name = await page.evaluate(() => window.__director.playerName);
const scene = await page.evaluate(() => window.__director.currentScene);
await page.screenshot({ path: process.env.SHOT_DIR + "/dist_house.png" });
console.log("name(默认):", name, "| scene:", scene, "| ERRORS:", errors.length);
errors.forEach(e => console.log(" -", e));
await browser.close();
server.httpServer.close();
process.exit(errors.length || name !== "小满" || scene !== "house" ? 1 : 0);
