Files
joke-app/e2e/speed.e2e.ts
EJClaw 18ef402a6a 게임 속도 배율: 1배도 애니메이션·연출·컴퓨터 생각 시간을 예전의 1.5배로 늦추고, 관리자 사이트 설정 "게임 속도 배율"(1/16~16배, 기본 1)로 나눠 조절. 저장하면 열린 방에도 바로 적용(RoomView.gameSpeed 재전송)
- 서버: SiteSettings.gameSpeed, /api/config에 노출, 컴퓨터 생각 시간(defaultBotDelay)과 마피아·라이어 컴퓨터가 살펴보는 간격에 BOT_SLOWDOWN(1.5)/배율. 게임이 정한 반응 시각(원카드 외치기)은 그대로
- 웹: lib/motion.ts — .game-layout 안 CSS 애니메이션·트랜지션은 useMotionScope가 playbackRate로, Web Animations는 fxAnim, 연출 타이머(배너 유지·다음 단계·복사본 정리·숫자 세기·다시 보기 한 칸)는 fxMs. 채팅·role="timer"·규칙 시간·꾹 눌러 보기는 제외
- 관리자 사이트 탭에 배율 버튼(1/16~16)과 직접 입력
- 테스트: 배율 검증(API 400/200, 열린 방 즉시 반영), 컴퓨터 생각 시간 배율, motion 단위 테스트, e2e/speed.e2e.ts(돌 애니메이션 재생 배율·컴퓨터 응답 시간), 관리자 e2e에 배율 저장
- 문서: 14-admin §5, 07-ui-ux, 06-lobby-rooms, 13-decisions, README

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-14 01:24:25 +09:00

83 lines
4.1 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* E2E (docs/14-admin.md §5 게임 속도 배율): the admin game speed reaches the screen and the computers.
* For each speed the site setting is changed and an 오목 practice game is played for one move, then
* - the stone animations on the board run at playbackRate = speed / 1.5 (×1 is a bit slower than the written CSS),
* - the computer's answer takes about 1.5 / speed times its usual thinking time.
* Run: E2E_PORT=4544 bun e2e/speed.e2e.ts (needs apps/web/dist built)
*/
import { chromium, type Browser, type Page } from 'playwright-core';
import { mkdtempSync } from 'node:fs';
import { join } from 'node:path';
import { loadConfig } from '../apps/server/src/config';
import { startServer } from '../apps/server/src/server';
const PORT = Number(process.env.E2E_PORT ?? 4544);
const ORIGIN = `http://localhost:${PORT}`;
const PAD = 0.9;
async function clickCell(p: Page, x: number, y: number) {
const box = (await p.locator('svg[role="grid"]').boundingBox())!;
const span = 14 + 2 * PAD;
await p.mouse.click(box.x + ((x + PAD) / span) * box.width, box.y + ((y + PAD) / span) * box.height);
}
const stoneCount = (p: Page) => p.locator('svg[role="grid"] g:not([opacity="0.55"]) > circle[r="0.46"]').count();
/** Plays one move against the computer; returns the stone animation's playback rate and the computer's answer time. */
async function run(browser: Browser, speed: number): Promise<{ rate: number; answerMs: number }> {
app.settings.setSite({ ...app.settings.getSite(), gameSpeed: speed }, 'e2e');
const ctx = await browser.newContext({ viewport: { width: 1280, height: 800 }, locale: 'ko-KR' });
await ctx.addInitScript(() => localStorage.setItem('bg:qs:omok', '1'));
try {
const p = await ctx.newPage();
await p.goto(`${ORIGIN}/g/omok`);
await p.getByRole('button', { name: '🤖 컴퓨터와 연습하기' }).click();
await p.getByLabel('내 이름(닉네임)').fill('속도');
await p.getByRole('button', { name: '이 이름으로 시작하기' }).click();
await p.waitForURL(/\/r\/\d{6}$/);
await p.getByRole('button', { name: '▶ 게임 시작' }).click();
await p.locator('svg[role="grid"]').waitFor();
// Black moves first; if the computer is black, wait for its first stone.
await p.waitForFunction(() => /내 차례예요/.test(document.querySelector('.turn-status')?.textContent ?? ''), null, { timeout: 60_000 });
const before = await stoneCount(p);
await clickCell(p, before ? 8 : 7, 7);
// My stone lands with `bm-place`: read its rate while it plays.
const rate = await p.waitForFunction(() => {
const root = document.querySelector('.game-layout');
const a = root?.getAnimations({ subtree: true }).find((x) => (x as CSSAnimation).animationName === 'bm-place');
return a ? a.playbackRate : null;
}, null, { timeout: 5000, polling: 'raf' });
const t0 = Date.now();
await p.waitForFunction((n) => document.querySelectorAll('svg[role="grid"] g:not([opacity="0.55"]) > circle[r="0.46"]').length >= n + 2, before, { timeout: 60_000 });
return { rate: (await rate.jsonValue()) as number, answerMs: Date.now() - t0 };
} finally {
await ctx.close();
}
}
const dbDir = mkdtempSync(join(process.env.TMPDIR ?? '/tmp', 'bg-e2e-'));
const app = startServer({
config: loadConfig({ PORT: String(PORT), DB_PATH: join(dbDir, 'app.db'), PUBLIC_ORIGIN: ORIGIN }),
log: () => {},
staticDir: join(import.meta.dir, '../apps/web/dist'),
});
const browser = await chromium.launch({ executablePath: process.env.CHROME ?? '/usr/bin/google-chrome', headless: true });
let failed = false;
try {
for (const [speed, check] of [
[1, (ms: number) => ms >= 2000],
[4, (ms: number) => ms <= 4500],
[1 / 4, (ms: number) => ms >= 7000],
] as const) {
const { rate, answerMs } = await run(browser, speed);
const want = speed / 1.5;
const ok = Math.abs(rate - want) < 1e-6 && check(answerMs);
if (!ok) failed = true;
console.log(`${ok ? '✓' : '✗'} 속도 ${speed}배: 돌 애니메이션 재생 배율 ${rate.toFixed(3)} (기대 ${want.toFixed(3)}), 컴퓨터 응답 ${answerMs}ms`);
}
} finally {
await browser.close();
await app.stop();
}
process.exit(failed ? 1 : 0);