- server/: Node (ws) static server + authoritative co-op rooms; dual-stack listen, proxy-aware client IP and Origin check, keep-alive pings, per-socket rate limits, graceful shutdown; 59 node:test tests - docs/DEPLOY.md + deploy/netwall.service: Debian 13 LXC, systemd, nginx Proxy Manager walk-through, path prefix, troubleshooting - e2e/: Playwright suite (smoke, touch, end flow, two-browser co-op incl. reconnect, 14-size layout matrix); npm run e2e - Music: tracks.json now points at the uploaded theme/battle/boss/win/lose files; stingers fade out when a new game starts - PAUSED indicator, refreshed icon Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Tb8pW2KAN4oFkh1aK1BfD8
78 lines
5.1 KiB
JavaScript
78 lines
5.1 KiB
JavaScript
const assert = (c, m) => { if (!c) throw new Error('ASSERT: ' + m); console.log('ok -', m); };
|
|
module.exports = async function ({ browser, url: URL, out: OUT }) {
|
|
const errors = [];
|
|
for (const [name, opts] of [['portrait', { viewport: { width: 390, height: 844 } }], ['landscape', { viewport: { width: 844, height: 390 } }]]) {
|
|
console.log('=== ' + name);
|
|
const ctx = await browser.newContext({ ...opts, deviceScaleFactor: 2, isMobile: true, hasTouch: true });
|
|
const page = await ctx.newPage();
|
|
page.on('pageerror', e => errors.push(`[${name}] pageerror: ${e.message}`));
|
|
page.on('console', m => { if (m.type() === 'error') errors.push(`[${name}] console.error: ${m.text()}`); });
|
|
const cdp = await ctx.newCDPSession(page);
|
|
const touch = (type, pts) => cdp.send('Input.dispatchTouchEvent', { type, touchPoints: pts.map((p, i) => ({ x: p.x, y: p.y, id: i + 1 })) });
|
|
await page.goto(URL); await page.waitForTimeout(400);
|
|
await page.tap('#btnSolo'); await page.waitForTimeout(300);
|
|
await page.tap('#btnHelpClose'); await page.waitForTimeout(200);
|
|
const box = await page.locator('#board').boundingBox();
|
|
const cellPt = async (cx, cy) => { const r = await page.evaluate(([a, b]) => NW.app.renderer.cellToScreen(a, b), [cx, cy]); return { x: box.x + r.x, y: box.y + r.y }; };
|
|
const state = () => page.evaluate(() => { const a = NW.app, v = a.ctrl.view; return { towers: v.towers.length, gold: v.gold, pending: a.pending, selType: a.selType, zoom: a.renderer.zoom, rot: a.renderer.rot, confirmHidden: document.getElementById('confirm').hidden, marks: a.renderer.marks.length, hint: document.getElementById('hint').textContent }; });
|
|
|
|
// 1) drag-paint walls with one finger
|
|
await page.tap('.tbtn[data-type="wall"]');
|
|
const a = await cellPt(8, 5), b = await cellPt(8, 11);
|
|
await touch('touchStart', [a]);
|
|
for (let i = 1; i <= 12; i++) await touch('touchMove', [{ x: a.x + (b.x - a.x) * i / 12, y: a.y + (b.y - a.y) * i / 12 }]);
|
|
await touch('touchEnd', []);
|
|
let s = await state();
|
|
assert(s.towers >= 7, `drag painted a wall line (${s.towers} walls)`);
|
|
|
|
// 2) turret: first tap previews (no build), confirm bar appears, tapping the check builds it
|
|
await page.tap('.tbtn[data-type="filter"]');
|
|
const t1 = await cellPt(10, 8);
|
|
await page.touchscreen.tap(t1.x, t1.y); await page.waitForTimeout(150);
|
|
let s2 = await state();
|
|
assert(s2.towers === s.towers && s2.pending && s2.pending.x === 10 && s2.pending.y === 8, 'first tap only previews');
|
|
assert(!s2.confirmHidden, 'confirm bar is visible');
|
|
assert(/Route|Need|✕/.test(s2.hint), 'hint shows route info: ' + s2.hint);
|
|
await page.screenshot({ path: OUT + `touch-${name}-1-preview.png` });
|
|
await page.tap('#btnConfirmBuild'); await page.waitForTimeout(150);
|
|
let s3 = await state();
|
|
assert(s3.towers === s.towers + 1, 'confirm builds the tower');
|
|
// tap-again-to-build
|
|
const t2 = await cellPt(10, 10);
|
|
await page.touchscreen.tap(t2.x, t2.y); await page.waitForTimeout(120);
|
|
await page.touchscreen.tap(t2.x, t2.y); await page.waitForTimeout(150);
|
|
let s4 = await state();
|
|
assert(s4.towers === s.towers + 2, 'tapping the previewed cell again builds');
|
|
|
|
// 3) tapping an existing tower selects it (even with a build type active)
|
|
await page.touchscreen.tap(t1.x, t1.y); await page.waitForTimeout(150);
|
|
const sel = await page.evaluate(() => ({ t: NW.app.selTower, type: NW.app.selType, info: document.getElementById('info').innerText.slice(0, 60) }));
|
|
assert(sel.t && !sel.type, 'tap on tower selects it: ' + JSON.stringify(sel.info));
|
|
await page.screenshot({ path: OUT + `touch-${name}-2-selected.png` });
|
|
await page.tap('#info [data-act="up"]'); await page.waitForTimeout(150);
|
|
const lv = await page.evaluate(() => NW.app.ctrl.view.towers.find(t => t.id === NW.app.selTower).level);
|
|
assert(lv === 2, 'upgrade via info panel');
|
|
|
|
// 4) pinch zoom with two fingers, then reset
|
|
const c = await cellPt(13, 8);
|
|
await touch('touchStart', [{ x: c.x - 30, y: c.y }, { x: c.x + 30, y: c.y }]);
|
|
for (let i = 1; i <= 10; i++) await touch('touchMove', [{ x: c.x - 30 - i * 8, y: c.y }, { x: c.x + 30 + i * 8, y: c.y }]);
|
|
await touch('touchEnd', []);
|
|
const z = (await state()).zoom;
|
|
assert(z > 1.8, 'pinch zoomed in (zoom ' + z.toFixed(2) + ')');
|
|
assert(!(await page.locator('#btnFit').isHidden()), 'fit button visible when zoomed');
|
|
await page.screenshot({ path: OUT + `touch-${name}-3-zoomed.png` });
|
|
await page.tap('#btnFit'); await page.waitForTimeout(100);
|
|
assert((await state()).zoom === 1, 'fit resets zoom');
|
|
|
|
// 5) long-press pings the map
|
|
await page.evaluate(() => { NW.app.selType = null; NW.app.selTower = 0; });
|
|
const lp = await cellPt(15, 4);
|
|
await touch('touchStart', [lp]); await page.waitForTimeout(650); await touch('touchEnd', []);
|
|
assert((await state()).marks >= 1, 'long-press creates a map ping');
|
|
console.log('rotation', (await state()).rot);
|
|
await ctx.close();
|
|
}
|
|
if (errors.length) throw new Error('console errors:\n' + errors.join('\n'));
|
|
console.log('no console errors');
|
|
};
|