- 회귀 테스트: 서버 2개(수정 전 코드에서 실패 확인), e2e 1단계 추가 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
260 lines
14 KiB
TypeScript
260 lines
14 KiB
TypeScript
/**
|
||
* Stage 4 E2E (docs/10 4단계): three guests in real browsers.
|
||
* Room from the home page, join from the open-room list, host settings reach everyone at once with the song count,
|
||
* ready reset, waiting-room chat, password room (🔒 in the list), kick, server restart notice, phone and dark screens.
|
||
* Run: bun run build && bun e2e/rooms.e2e.ts (needs /usr/bin/google-chrome)
|
||
*/
|
||
import { chromium, type Browser, type Page } from 'playwright-core';
|
||
import { mkdirSync, mkdtempSync } from 'node:fs';
|
||
import { join } from 'node:path';
|
||
import { loadConfig } from '../apps/server/src/config';
|
||
import { startServer } from '../apps/server/src/server';
|
||
import { Catalog } from '../apps/server/src/collector/catalog';
|
||
|
||
const PORT = Number(process.env.E2E_PORT ?? 4619);
|
||
const ORIGIN = `http://localhost:${PORT}`;
|
||
const SHOTS = process.env.E2E_SHOTS ?? join(import.meta.dir, '../test-results');
|
||
mkdirSync(SHOTS, { recursive: true });
|
||
|
||
const config = loadConfig({
|
||
PORT: String(PORT),
|
||
DB_PATH: join(mkdtempSync(join(process.env.TMPDIR ?? '/tmp', 'mq-e2e-')), 'app.db'),
|
||
PUBLIC_ORIGIN: ORIGIN,
|
||
SUPERADMIN_DISCORD_IDS: '900000000000000001',
|
||
});
|
||
const boot = () => startServer({ config, log: () => {}, staticDir: join(import.meta.dir, '../apps/web/dist'), stopWaitMs: 200 });
|
||
let app = boot();
|
||
|
||
// Catalog: 국내 발라드 3단계 4곡(1곡은 원곡 확인 중), 댄스 3단계 2곡, 발라드 5단계 1곡.
|
||
{
|
||
const c = new Catalog(app.db);
|
||
const add = (title: string, genres: string[], year: number, level: number, matched = true) => {
|
||
const [id] = c.upsert({ title, artists: [{ name: `가수${title}` }], year, genres, source: 'e2e', ref: title });
|
||
c.autoLevel(id!, 'all', level);
|
||
if (matched) app.db.query("UPDATE songs SET youtube_status = 'matched', embeddable = 1, youtube_id = 'VO88htcm09E' WHERE id = ?").run(id!);
|
||
};
|
||
add('발라드1', ['kpop', 'ballad'], 2005, 3);
|
||
add('발라드2', ['kpop', 'ballad'], 2007, 3);
|
||
add('발라드3', ['kpop', 'ballad'], 2012, 3);
|
||
add('발라드확인중', ['kpop', 'ballad'], 2010, 3, false);
|
||
add('댄스1', ['kpop', 'dance'], 2009, 3);
|
||
add('댄스2', ['kpop', 'dance'], 2015, 3);
|
||
add('어려운발라드', ['kpop', 'ballad'], 2001, 5);
|
||
}
|
||
|
||
const browser: Browser = await chromium.launch({ executablePath: process.env.CHROME ?? '/usr/bin/google-chrome', headless: true });
|
||
const errors: string[] = [];
|
||
const step = async (name: string, fn: () => Promise<void>) => {
|
||
const t0 = performance.now();
|
||
try {
|
||
await fn();
|
||
console.log(`✓ ${name} (${Math.round(performance.now() - t0)}ms)`);
|
||
} catch (e) {
|
||
console.log(`✗ ${name}: ${(e as Error).message.split('\n')[0]}`);
|
||
throw e;
|
||
}
|
||
};
|
||
const expect = (ok: unknown, msg: string) => {
|
||
if (!ok) throw new Error(msg);
|
||
};
|
||
|
||
async function guestPage(name: string, opts: { width?: number; height?: number; dark?: boolean; mobile?: boolean } = {}): Promise<Page> {
|
||
const ctx = await browser.newContext({
|
||
viewport: { width: opts.width ?? 1440, height: opts.height ?? 900 },
|
||
locale: 'ko-KR',
|
||
colorScheme: opts.dark ? 'dark' : 'light',
|
||
isMobile: opts.mobile,
|
||
hasTouch: opts.mobile,
|
||
});
|
||
const p = await ctx.newPage();
|
||
p.on('pageerror', (e) => errors.push(`${name}: ${e.message}`));
|
||
await p.goto(ORIGIN + '/');
|
||
await p.getByLabel('게스트 닉네임 (2~12자)').fill(name);
|
||
await p.getByRole('button', { name: '게스트로 시작' }).click();
|
||
await p.getByRole('button', { name: `내 계정: ${name}` }).waitFor();
|
||
return p;
|
||
}
|
||
|
||
const waitPool = (p: Page, n: number) => p.locator('.pool-banner h2', { hasText: `조건에 맞는 곡 ${n}곡` }).waitFor({ timeout: 5000 });
|
||
|
||
let failed = false;
|
||
let code = '';
|
||
try {
|
||
const a = await guestPage('방장님');
|
||
const b = await guestPage('철수');
|
||
|
||
await step('게스트가 첫 화면에서 방 만들기 → 대기실, 기본 설정(공개·★3·30문제), 조건에 맞는 곡과 원곡 확인 중 곡 수', async () => {
|
||
await a.getByRole('button', { name: '+ 방 만들기' }).click();
|
||
await a.waitForURL(/\/r\/\d{6}$/);
|
||
code = a.url().slice(-6);
|
||
await a.getByRole('heading', { name: '방장님님의 방' }).waitFor();
|
||
await a.getByRole('heading', { name: '방 설정' }).waitFor();
|
||
await a.getByText('바꾸면 바로 모두에게 보여요').waitFor();
|
||
// 기본 ★3 전체 장르: 발라드1~3 + 댄스1~2 = 5곡, 원곡 확인 중 1곡
|
||
await waitPool(a, 5);
|
||
await a.getByText('원곡 확인 중인 곡 1곡은 확인이 끝나면 나와요').waitFor();
|
||
expect((await a.getByRole('radiogroup', { name: '방 공개' }).getByRole('radio', { checked: true }).innerText()) === '공개', '기본 공개가 아님');
|
||
expect(await a.getByRole('radio', { name: /^3단계/ }).getAttribute('aria-checked') === 'true', '기본 3단계 아님');
|
||
});
|
||
|
||
await step('다른 게스트: 열린 방 목록(전체/대기 중)에서 보고 들어가기, 서로 보임, 설정은 읽기 전용', async () => {
|
||
await b.goto(ORIGIN + '/');
|
||
const card = b.locator('.room-card', { hasText: '방장님님의 방' });
|
||
await card.waitFor({ timeout: 8000 });
|
||
await b.getByRole('button', { name: '진행 중 (중간 참여 가능)' }).click();
|
||
await card.waitFor({ state: 'detached' });
|
||
await b.getByRole('button', { name: '대기 중' }).click();
|
||
await card.getByRole('button', { name: '들어가기' }).click();
|
||
await b.waitForURL(`**/r/${code}`);
|
||
await b.getByText('방장만 바꿀 수 있어요').waitFor();
|
||
await a.locator('.pl', { hasText: '철수' }).waitFor();
|
||
await b.locator('.pl.host', { hasText: '방장님' }).waitFor();
|
||
expect(await b.getByRole('radio', { name: /^5단계/ }).isDisabled(), '손님이 난이도를 바꿀 수 있음');
|
||
});
|
||
|
||
await step('방장이 장르·난이도를 바꾸면 손님 화면에 바로 반영, 곡 수도 다시 셈(같은 묶음 또는·다른 묶음 그리고)', async () => {
|
||
const t0 = performance.now();
|
||
await a.locator('.chip', { hasText: '발라드' }).click();
|
||
await waitPool(b, 3); // ★3 발라드: 발라드1~3
|
||
const ms = Math.round(performance.now() - t0);
|
||
expect(await b.locator('.chip[aria-pressed="true"]', { hasText: '발라드' }).isVisible(), '손님 화면에 발라드 선택 안 보임');
|
||
await a.locator('.chip', { hasText: '댄스' }).click();
|
||
await waitPool(b, 5); // 발라드 또는 댄스
|
||
await a.getByRole('radio', { name: /^5단계/ }).click();
|
||
await waitPool(b, 1); // ★5: 어려운발라드
|
||
await b.getByText('5단계 · 장르 팬 필수곡').waitFor();
|
||
await a.getByRole('radio', { name: /^3단계/ }).click();
|
||
await waitPool(b, 5);
|
||
console.log(` 설정 반영 → 손님 화면 ${ms}ms`);
|
||
});
|
||
|
||
await step('손님 준비 → 방장 화면에 준비, 방장이 설정을 바꾸면 준비가 풀림', async () => {
|
||
await b.getByRole('button', { name: '준비', exact: true }).click();
|
||
await a.locator('.pl', { hasText: '철수' }).getByText('준비', { exact: true }).waitFor();
|
||
await b.getByRole('button', { name: '준비 완료 ✓' }).waitFor();
|
||
await a.getByRole('radiogroup', { name: '문제 수' }).getByRole('radio', { name: '50' }).click();
|
||
await b.getByRole('button', { name: '준비', exact: true }).waitFor();
|
||
await a.locator('.pl', { hasText: '철수' }).getByText('대기', { exact: true }).waitFor();
|
||
await b.getByText('문제 수보다 곡이 적어서 5문제만 나와요.').waitFor();
|
||
});
|
||
|
||
await step('대기실 채팅: 입장 안내, 서로 보낸 말이 바로 보임, 내 줄 표시', async () => {
|
||
await a.getByText('— 철수님이 들어왔어요 —').waitFor();
|
||
await b.getByLabel('채팅 입력').fill('안녕하세요 2000년대 발라드 ㄱㄱ');
|
||
await b.getByLabel('채팅 입력').press('Enter');
|
||
await a.locator('.chat-line', { hasText: '안녕하세요 2000년대 발라드 ㄱㄱ' }).waitFor();
|
||
await b.locator('.chat-line.me:not(.pending)', { hasText: '안녕하세요 2000년대 발라드 ㄱㄱ' }).waitFor();
|
||
await a.getByLabel('채팅 입력').fill('좋아요');
|
||
await a.getByRole('button', { name: '보내기' }).click();
|
||
await b.locator('.chat-line', { hasText: '좋아요' }).waitFor();
|
||
expect((await a.getByLabel('채팅 입력').inputValue()) === '', '보낸 뒤 입력창이 비지 않음');
|
||
});
|
||
|
||
await step('도배 방지를 켜면 거절된 말은 "보내는 중"으로 남지 않고 안내만 뜸', async () => {
|
||
const site = app.settings.getSite();
|
||
app.settings.setSite({ ...site, chatFloodGuard: true, chatRatePerSec: 1, chatBurst: 2 }, 'e2e');
|
||
const box = b.getByLabel('채팅 입력');
|
||
for (let i = 0; i < 5; i++) {
|
||
await box.fill(`빠른말${i}`);
|
||
await box.press('Enter');
|
||
}
|
||
await b.getByText('채팅을 너무 빨리 보내고 있어요. 잠깐 쉬었다 보내 주세요.').first().waitFor();
|
||
await a.locator('.chat-line', { hasText: '빠른말1' }).waitFor();
|
||
await b.waitForFunction(() => document.querySelectorAll('.chat-line.pending').length === 0, null, { timeout: 3000 });
|
||
const shown = await a.locator('.chat-line', { hasText: '빠른말' }).count();
|
||
expect(shown === 2, `받은 쪽에 ${shown}줄`);
|
||
expect((await b.locator('.chat-line', { hasText: '빠른말' }).count()) === 2, '거절된 말이 보낸 쪽 화면에 남음');
|
||
app.settings.setSite({ ...site, chatFloodGuard: false }, 'e2e');
|
||
});
|
||
|
||
await step('비밀번호 방: 목록에 🔒, 들어갈 때 비밀번호(틀리면 안내), 맞으면 입장하고 지난 채팅이 보임', async () => {
|
||
await a.getByRole('radiogroup', { name: '방 공개' }).getByRole('radio', { name: '비밀번호' }).click();
|
||
await a.getByText('비밀번호를 정해야 잠겨요').waitFor();
|
||
await a.getByLabel('방 비밀번호').fill('4321');
|
||
await a.getByRole('button', { name: '정하기' }).click();
|
||
await a.getByText('비밀번호 있음').waitFor();
|
||
const c = await guestPage('영희');
|
||
const card = c.locator('.room-card', { hasText: '방장님님의 방' });
|
||
await card.getByText('🔒 비밀번호').waitFor({ timeout: 8000 });
|
||
await card.getByRole('button', { name: '들어가기' }).click();
|
||
await c.getByRole('heading', { name: '비밀번호가 필요한 방이에요' }).waitFor();
|
||
await c.getByLabel('방 비밀번호').fill('0000');
|
||
await c.getByRole('button', { name: '들어가기' }).click();
|
||
await c.getByText('비밀번호가 틀렸어요.').waitFor();
|
||
await c.getByLabel('방 비밀번호').fill('4321');
|
||
await c.getByRole('button', { name: '들어가기' }).click();
|
||
await c.getByRole('heading', { name: '방장님님의 방' }).waitFor();
|
||
await c.locator('.chat-line', { hasText: '안녕하세요 2000년대 발라드 ㄱㄱ' }).waitFor();
|
||
await a.screenshot({ path: join(SHOTS, 'stage4-room-host.png'), fullPage: true });
|
||
await c.screenshot({ path: join(SHOTS, 'stage4-room-guest.png'), fullPage: true });
|
||
|
||
await step('방장이 내보내기 → 첫 화면으로 돌아가며 안내', async () => {
|
||
const row = a.locator('.pl', { hasText: '영희' });
|
||
await row.hover();
|
||
await row.getByRole('button', { name: '영희 내보내기' }).click();
|
||
await c.waitForURL(`${ORIGIN}/`);
|
||
await c.getByText('방장이 방에서 내보냈어요.').waitFor();
|
||
await b.getByText('— 영희님이 내보내졌어요 —').waitFor();
|
||
await c.context().close();
|
||
});
|
||
});
|
||
|
||
await step('방장 넘기기 → 손님이 방장이 되어 설정을 바꿀 수 있음', async () => {
|
||
const row = a.locator('.pl', { hasText: '철수' });
|
||
await row.hover();
|
||
await row.getByRole('button', { name: '철수에게 방장 넘기기' }).click();
|
||
await b.getByText('바꾸면 바로 모두에게 보여요').waitFor();
|
||
await b.getByText('— 방장이 철수님으로 바뀌었어요 —').waitFor();
|
||
await b.getByRole('radio', { name: /^4단계/ }).click();
|
||
await a.getByText('4단계 · 가끔 들어도 아는 곡').waitFor();
|
||
});
|
||
|
||
await step('휴대폰(390px)·다크 화면: 대기실이 가로로 넘치지 않음', async () => {
|
||
const m = await guestPage('폰손님', { width: 390, height: 844, mobile: true });
|
||
await m.goto(`${ORIGIN}/r/${code}`);
|
||
await m.getByRole('heading', { name: '비밀번호가 필요한 방이에요' }).waitFor();
|
||
await m.getByLabel('방 비밀번호').fill('4321');
|
||
await m.getByRole('button', { name: '들어가기' }).click();
|
||
await m.getByRole('heading', { name: '방 설정' }).waitFor();
|
||
const overflow = await m.evaluate(() => document.documentElement.scrollWidth - window.innerWidth);
|
||
expect(overflow <= 0, `휴대폰 가로 넘침 ${overflow}px`);
|
||
await m.screenshot({ path: join(SHOTS, 'stage4-room-mobile.png'), fullPage: true });
|
||
const d = await guestPage('밤손님', { dark: true });
|
||
await d.goto(`${ORIGIN}/r/${code}`);
|
||
await d.getByLabel('방 비밀번호').fill('4321');
|
||
await d.getByRole('button', { name: '들어가기' }).click();
|
||
await d.locator('.chat-line', { hasText: '좋아요' }).waitFor();
|
||
await d.screenshot({ path: join(SHOTS, 'stage4-room-dark.png'), fullPage: true });
|
||
await m.context().close();
|
||
await d.context().close();
|
||
});
|
||
|
||
await step('서버를 다시 켜면(업데이트) 방이 사라졌다고 안내 — 다시 연결한 화면과 새로고침한 화면 모두', async () => {
|
||
await app.stop();
|
||
app = boot();
|
||
await a.getByText('서버가 업데이트되면서 방이 닫혔어요. 방을 새로 만들어 주세요.').waitFor({ timeout: 15000 });
|
||
await b.reload();
|
||
await b.getByText('서버가 업데이트되면서 방이 닫혔어요. 방을 새로 만들어 주세요.').waitFor({ timeout: 15000 });
|
||
// 다른 사람이 없는 코드로 들어오면 원래 안내
|
||
const fresh = await browser.newContext({ locale: 'ko-KR' });
|
||
const f = await fresh.newPage();
|
||
await f.goto(ORIGIN + '/');
|
||
await f.getByLabel('게스트 닉네임 (2~12자)').fill('새손님');
|
||
await f.getByRole('button', { name: '게스트로 시작' }).click();
|
||
await f.getByRole('button', { name: '내 계정: 새손님' }).waitFor();
|
||
await f.goto(`${ORIGIN}/r/${code}`);
|
||
await f.getByText('방을 찾을 수 없어요. 코드를 다시 확인해 주세요.').waitFor();
|
||
await fresh.close();
|
||
});
|
||
|
||
expect(errors.length === 0, `페이지 오류: ${errors.join(' | ')}`);
|
||
} catch (e) {
|
||
if (!(e instanceof Error && e.message)) console.log(e);
|
||
failed = true;
|
||
} finally {
|
||
await browser.close();
|
||
await app.stop();
|
||
}
|
||
console.log(failed ? 'E2E FAILED' : 'E2E PASSED');
|
||
process.exit(failed ? 1 : 0);
|