Merge pull request 'fix(e2e): cycle gate resets games in place (no 240 page reloads)' (#103) from fix/cycle-gate-newgame into master
This commit was merged in pull request #103.
This commit is contained in:
@@ -142,10 +142,32 @@ async function main() {
|
|||||||
const page = await context.newPage();
|
const page = await context.newPage();
|
||||||
const results = [];
|
const results = [];
|
||||||
|
|
||||||
|
// Load the page once, then reset each game in place via the bridge's
|
||||||
|
// newGame(). A fresh page.goto() per game (hundreds of navigations in a
|
||||||
|
// single browser context) accumulates resources and eventually makes
|
||||||
|
// waitForFunction time out around game ~100. One load stays fast.
|
||||||
|
await page.goto(`${baseUrl}/${route}`, { waitUntil: "domcontentloaded" });
|
||||||
|
if (route === "play-classic") {
|
||||||
|
const resumeVisible = await page
|
||||||
|
.locator("#resume-overlay:not(.hidden)")
|
||||||
|
.isVisible()
|
||||||
|
.catch(() => false);
|
||||||
|
if (resumeVisible) {
|
||||||
|
await page.evaluate(() => localStorage.removeItem("fs_game_save"));
|
||||||
|
await page.reload({ waitUntil: "domcontentloaded" });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
await page.waitForFunction(
|
||||||
|
() =>
|
||||||
|
typeof window.__FERROUS_DEBUG__ === "object" &&
|
||||||
|
typeof window.__FERROUS_DEBUG__.newGame === "function",
|
||||||
|
null,
|
||||||
|
{ timeout: 30_000 }
|
||||||
|
);
|
||||||
|
|
||||||
for (let i = 0; i < games; i++) {
|
for (let i = 0; i < games; i++) {
|
||||||
const seed = i;
|
const seed = i;
|
||||||
const draw3 = i % 2 === 1;
|
const draw3 = i % 2 === 1;
|
||||||
const suffix = draw3 ? "&draw3=" : "";
|
|
||||||
|
|
||||||
const pageErrors = [];
|
const pageErrors = [];
|
||||||
const consoleErrors = [];
|
const consoleErrors = [];
|
||||||
@@ -158,27 +180,10 @@ async function main() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
await page.goto(`${baseUrl}/${route}?seed=${seed}${suffix}`, {
|
// Reset to a fresh seeded game without navigating.
|
||||||
waitUntil: "domcontentloaded",
|
await page.evaluate(
|
||||||
});
|
({ seed, draw3 }) => window.__FERROUS_DEBUG__.newGame(seed, draw3),
|
||||||
|
{ seed, draw3 }
|
||||||
if (route === "play-classic") {
|
|
||||||
const resumeVisible = await page
|
|
||||||
.locator("#resume-overlay:not(.hidden)")
|
|
||||||
.isVisible()
|
|
||||||
.catch(() => false);
|
|
||||||
if (resumeVisible) {
|
|
||||||
await page.evaluate(() => localStorage.removeItem("fs_game_save"));
|
|
||||||
await page.reload({ waitUntil: "domcontentloaded" });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
await page.waitForFunction(
|
|
||||||
() =>
|
|
||||||
typeof window.__FERROUS_DEBUG__ === "object" &&
|
|
||||||
window.__FERROUS_DEBUG__.seed() !== null,
|
|
||||||
null,
|
|
||||||
{ timeout: 30_000 }
|
|
||||||
);
|
);
|
||||||
|
|
||||||
const run = await page.evaluate(({ stepCap, policyName, maxVisits }) => {
|
const run = await page.evaluate(({ stepCap, policyName, maxVisits }) => {
|
||||||
|
|||||||
@@ -994,6 +994,14 @@ window.__FERROUS_DEBUG__ = {
|
|||||||
serialize() {
|
serialize() {
|
||||||
return game ? game.serialize() : null;
|
return game ? game.serialize() : null;
|
||||||
},
|
},
|
||||||
|
// Reset to a fresh seeded game in place (no page reload). Lets the cycle
|
||||||
|
// regression harness reuse one page across hundreds of games instead of
|
||||||
|
// navigating per game.
|
||||||
|
newGame(seed, drawThreeMode) {
|
||||||
|
drawThree = !!drawThreeMode;
|
||||||
|
startGame(seed ?? randomSeed());
|
||||||
|
return game ? game.state() : null;
|
||||||
|
},
|
||||||
applyLegalMove(index) {
|
applyLegalMove(index) {
|
||||||
if (!game) return { ok: false, error: "game_not_ready" };
|
if (!game) return { ok: false, error: "game_not_ready" };
|
||||||
const result = game.debug_apply_legal_move(index);
|
const result = game.debug_apply_legal_move(index);
|
||||||
|
|||||||
Reference in New Issue
Block a user