game-qa by opusgamelabs/game-creator
npx skills add https://github.com/opusgamelabs/game-creator --skill game-qa您是一位浏览器游戏质量保证专家。您使用 Playwright 编写自动化测试,以验证视觉正确性、游戏玩法行为、性能和可访问性。
详细参考请参阅本目录中的配套文件:
test-patterns.md — 自定义夹具代码、启动测试、游戏玩法验证测试、得分测试gameplay-invariants.md — 所有 7 个核心游戏玩法不变模式(得分、死亡、按钮、render_game_to_text、设计意图、实体审计、静音)visual-regression.md — 截图比较测试、屏蔽动态元素、性能/FPS 测试、可访问性测试、确定性测试模式clock-control.md — 用于帧精确测试的 Playwright Clock API 模式playwright-mcp.md — MCP 服务器设置、何时使用 MCP 与脚本测试、检查流程iterate-client.md — 独立迭代客户端使用、操作 JSON 格式、输出解释广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
mobile-tests.md — 移动输入模拟和响应式布局测试模式@playwright/test)toHaveScreenshot()@axe-core/playwrightwebServer 配置的 Vite 开发服务器将 Playwright 添加到游戏项目时:
npm install -D @playwright/test @axe-core/playwright
npx playwright install chromium
添加到 package.json 脚本:
{
"scripts": {
"test": "npx playwright test",
"test:ui": "npx playwright test --ui",
"test:headed": "npx playwright test --headed",
"test:update-snapshots": "npx playwright test --update-snapshots"
}
}
tests/
├── e2e/
│ ├── game.spec.js # 核心游戏测试(启动、场景、输入、得分)
│ ├── visual.spec.js # 视觉回归截图
│ └── perf.spec.js # 性能和 FPS 测试
├── fixtures/
│ ├── game-test.js # 包含游戏辅助函数的自定义测试夹具
│ └── screenshot.css # 用于视觉测试中屏蔽动态元素的 CSS
├── helpers/
│ └── seed-random.js # 用于确定性游戏行为的种子伪随机数生成器
playwright.config.js
import { defineConfig, devices } from '@playwright/test';
export default defineConfig({
testDir: './tests',
fullyParallel: true,
forbidOnly: !!process.env.CI,
retries: process.env.CI ? 2 : 0,
workers: process.env.CI ? 1 : undefined,
reporter: [['html', { open: 'never' }], ['list']],
use: {
baseURL: 'http://localhost:3000',
trace: 'on-first-retry',
screenshot: 'only-on-failure',
video: 'retain-on-failure',
},
expect: {
toHaveScreenshot: {
maxDiffPixels: 200,
threshold: 0.3,
},
},
projects: [
{ name: 'chromium', use: { ...devices['Desktop Chrome'] } },
{ name: 'mobile-chrome', use: { ...devices['Pixel 5'] } },
],
webServer: {
command: 'npm run dev',
url: 'http://localhost:3000',
reuseExistingServer: !process.env.CI,
timeout: 30000,
},
});
关键点:
webServer 在测试前自动启动 VitereuseExistingServer 在本地重用正在运行的开发服务器baseURL 与 vite.config.js 中配置的 Vite 端口匹配为了让 Playwright 检查游戏状态,游戏必须在 main.js 中的 window 上暴露以下全局变量:
// 为 Playwright QA 暴露
window.__GAME__ = game;
window.__GAME_STATE__ = gameState;
window.__EVENT_BUS__ = eventBus;
window.__EVENTS__ = Events;
render_game_to_text()(必需)返回当前游戏状态的简洁 JSON 字符串,供 AI 代理在不解释像素的情况下推理游戏状态。必须包含坐标系、游戏模式、得分和玩家状态。
window.render_game_to_text = () => {
if (!game || !gameState) return JSON.stringify({ error: 'not_ready' });
const activeScenes = game.scene.getScenes(true).map(s => s.scene.key);
const payload = {
coords: 'origin:top-left x:right y:down', // 坐标系
mode: gameState.gameOver ? 'game_over' : 'playing',
scene: activeScenes[0] || null,
score: gameState.score,
bestScore: gameState.bestScore,
};
// 在游戏进行中添加玩家信息
const gameScene = game.scene.getScene('GameScene');
if (gameState.started && gameScene?.player?.sprite) {
const s = gameScene.player.sprite;
const body = s.body;
payload.player = {
x: Math.round(s.x), y: Math.round(s.y),
vx: Math.round(body.velocity.x), vy: Math.round(body.velocity.y),
onGround: body.blocked.down,
};
}
// 随着添加可见实体进行扩展:
// payload.entities = obstacles.map(o => ({ x: o.x, y: o.y, type: o.type }));
return JSON.stringify(payload);
};
render_game_to_text() 的指南:
advanceTime(ms)(必需)允许测试脚本精确推进游戏时间。游戏循环通过 RAF 正常运行;此函数等待真实时间流逝。
window.advanceTime = (ms) => {
return new Promise((resolve) => {
const start = performance.now();
function step() {
if (performance.now() - start >= ms) return resolve();
requestAnimationFrame(step);
}
requestAnimationFrame(step);
});
};
对于 @playwright/test 中的帧精确控制,优先使用 page.clock.install() + page.clock.runFor()。advanceTime 钩子主要由独立的迭代客户端 (scripts/iterate-client.js) 使用。
对于 Three.js 游戏,类似地暴露 Game 编排器实例。
有关自定义夹具代码、启动测试、游戏玩法验证测试和得分测试,请参阅 test-patterns.md。
有关所有 7 个核心游戏玩法不变模式(得分、死亡、按钮、render_game_to_text、设计意图、实体审计、静音),请参阅 gameplay-invariants.md。
npm install -D @playwright/test @axe-core/playwright && npx playwright install chromiumplaywright.config.jsmain.js 中暴露 window.__GAME__、window.__GAME_STATE__、window.__EVENT_BUS__gamePage 夹具创建 tests/fixtures/game-test.jstests/helpers/seed-random.jstests/e2e/ 中编写测试:
game.spec.js — 启动、场景流程、输入、得分、游戏结束visual.spec.js — 每个场景的截图回归perf.spec.js — 加载时间、FPS 预算test、test:ui、test:headed、test:update-snapshotsnpm run test:update-snapshotspage.route() 模拟)每周安装次数
107
仓库
GitHub 星标数
32
首次出现
2026年2月21日
安全审计
安装于
claude-code90
opencode56
kimi-cli54
gemini-cli54
amp54
github-copilot54
You are an expert QA engineer for browser games. You use Playwright to write automated tests that verify visual correctness, gameplay behavior, performance, and accessibility.
For detailed reference, see companion files in this directory:
test-patterns.md — Custom fixture code, boot tests, gameplay verification tests, scoring testsgameplay-invariants.md — All 7 core gameplay invariant patterns (scoring, death, buttons, render_game_to_text, design intent, entity audit, mute)visual-regression.md — Screenshot comparison tests, masking dynamic elements, performance/FPS tests, accessibility tests, deterministic testing patternsclock-control.md — Playwright Clock API patterns for frame-precise testingplaywright-mcp.md — MCP server setup, when to use MCP vs scripted tests, inspection flowiterate-client.md — Standalone iterate client usage, action JSON format, output interpretationmobile-tests.md — Mobile input simulation and responsive layout test patterns@playwright/test)toHaveScreenshot()@axe-core/playwrightwebServer configWhen adding Playwright to a game project:
npm install -D @playwright/test @axe-core/playwright
npx playwright install chromium
Add to package.json scripts:
{
"scripts": {
"test": "npx playwright test",
"test:ui": "npx playwright test --ui",
"test:headed": "npx playwright test --headed",
"test:update-snapshots": "npx playwright test --update-snapshots"
}
}
tests/
├── e2e/
│ ├── game.spec.js # Core game tests (boot, scenes, input, score)
│ ├── visual.spec.js # Visual regression screenshots
│ └── perf.spec.js # Performance and FPS tests
├── fixtures/
│ ├── game-test.js # Custom test fixture with game helpers
│ └── screenshot.css # CSS to mask dynamic elements for visual tests
├── helpers/
│ └── seed-random.js # Seeded PRNG for deterministic game behavior
playwright.config.js
import { defineConfig, devices } from '@playwright/test';
export default defineConfig({
testDir: './tests',
fullyParallel: true,
forbidOnly: !!process.env.CI,
retries: process.env.CI ? 2 : 0,
workers: process.env.CI ? 1 : undefined,
reporter: [['html', { open: 'never' }], ['list']],
use: {
baseURL: 'http://localhost:3000',
trace: 'on-first-retry',
screenshot: 'only-on-failure',
video: 'retain-on-failure',
},
expect: {
toHaveScreenshot: {
maxDiffPixels: 200,
threshold: 0.3,
},
},
projects: [
{ name: 'chromium', use: { ...devices['Desktop Chrome'] } },
{ name: 'mobile-chrome', use: { ...devices['Pixel 5'] } },
],
webServer: {
command: 'npm run dev',
url: 'http://localhost:3000',
reuseExistingServer: !process.env.CI,
timeout: 30000,
},
});
Key points:
webServer auto-starts Vite before testsreuseExistingServer reuses a running dev server locallybaseURL matches the Vite port configured in vite.config.jsFor Playwright to inspect game state, the game MUST expose these globals on window in main.js:
// Expose for Playwright QA
window.__GAME__ = game;
window.__GAME_STATE__ = gameState;
window.__EVENT_BUS__ = eventBus;
window.__EVENTS__ = Events;
render_game_to_text() (required)Returns a concise JSON string of the current game state for AI agents to reason about the game without interpreting pixels. Must include coordinate system, game mode, score, and player state.
window.render_game_to_text = () => {
if (!game || !gameState) return JSON.stringify({ error: 'not_ready' });
const activeScenes = game.scene.getScenes(true).map(s => s.scene.key);
const payload = {
coords: 'origin:top-left x:right y:down', // coordinate system
mode: gameState.gameOver ? 'game_over' : 'playing',
scene: activeScenes[0] || null,
score: gameState.score,
bestScore: gameState.bestScore,
};
// Add player info when in gameplay
const gameScene = game.scene.getScene('GameScene');
if (gameState.started && gameScene?.player?.sprite) {
const s = gameScene.player.sprite;
const body = s.body;
payload.player = {
x: Math.round(s.x), y: Math.round(s.y),
vx: Math.round(body.velocity.x), vy: Math.round(body.velocity.y),
onGround: body.blocked.down,
};
}
// Extend with visible entities as you add them:
// payload.entities = obstacles.map(o => ({ x: o.x, y: o.y, type: o.type }));
return JSON.stringify(payload);
};
Guidelines for render_game_to_text():
advanceTime(ms) (required)Lets test scripts advance the game by a precise duration. The game loop runs normally via RAF; this waits for real time to elapse.
window.advanceTime = (ms) => {
return new Promise((resolve) => {
const start = performance.now();
function step() {
if (performance.now() - start >= ms) return resolve();
requestAnimationFrame(step);
}
requestAnimationFrame(step);
});
};
For frame-precise control in @playwright/test, prefer page.clock.install() + page.clock.runFor(). The advanceTime hook is primarily used by the standalone iterate client (scripts/iterate-client.js).
For Three.js games, expose the Game orchestrator instance similarly.
See test-patterns.md for custom fixture code, boot tests, gameplay verification tests, and scoring tests.
See gameplay-invariants.md for all 7 core gameplay invariant patterns (scoring, death, buttons, render_game_to_text, design intent, entity audit, mute).
npm install -D @playwright/test @axe-core/playwright && npx playwright install chromiumplaywright.config.js with the game's dev server portwindow.__GAME__, window.__GAME_STATE__, window.__EVENT_BUS__ in main.jstests/fixtures/game-test.js with the gamePage fixturetests/helpers/seed-random.js for deterministic behaviortests/e2e/:
page.route())Weekly Installs
107
Repository
GitHub Stars
32
First Seen
Feb 21, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykWarn
Installed on
claude-code90
opencode56
kimi-cli54
gemini-cli54
amp54
github-copilot54
Skills CLI 使用指南:AI Agent 技能包管理器安装与管理教程
44,900 周安装
Binance币本位合约API开发指南 - 衍生品交易接口与数据查询
990 周安装
coding-agent 编码代理使用指南:Bash优先的AI编程助手配置与优化
995 周安装
Binance算法交易API指南:TWAP、VP订单、期货与现货交易接口详解
1,000 周安装
Apple Reminders CLI (remindctl) - 终端管理苹果提醒事项,同步iPhone/iPad
1,000 周安装
代码库入门引导:AI辅助快速理解项目架构与代码规范
1,000 周安装
Claude Hookify 规则编写指南:创建自定义监控与安全规则 | YAML 配置教程
1,000 周安装
game.spec.js — boot, scene flow, input, scoring, game overvisual.spec.js — screenshot regression for each sceneperf.spec.js — load time, FPS budgettest, test:ui, test:headed, test:update-snapshotsnpm run test:update-snapshots