Repository navigation
QA: desktop and mobile browser playability smoke checks #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
16feab2
test(experiments): verify both games render and respond to real Chrom…
dragosandreibobu 138859a
ci(games): exercise both game loops in headless Chromium on desktop a…
dragosandreibobu ff41126
test(browser): avoid conflicting canvas context probes and fix wait o…
dragosandreibobu 8baad3f
test(games): detect fatal browser classic-script versus ESM import mi…
dragosandreibobu aadc654
test(browser): avoid unrelated favicon 404 from failing gameplay smoke
dragosandreibobu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| name: Real browser playability smoke | ||
| on: | ||
| pull_request: | ||
| branches: [main] | ||
| paths: | ||
| - 'experiments/**' | ||
| - '.github/workflows/browser-smoke.yml' | ||
| push: | ||
| branches: [main] | ||
| paths: | ||
| - 'experiments/**' | ||
| - '.github/workflows/browser-smoke.yml' | ||
| permissions: | ||
| contents: read | ||
| jobs: | ||
| chromium-smoke: | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 15 | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| - uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: '22' | ||
| - name: Install browser test dependency | ||
| run: npm install --no-save --no-package-lock [email protected] | ||
| - name: Install headless Chromium | ||
| run: npx playwright install --with-deps chromium | ||
| - name: Launch and exercise both games on desktop and mobile | ||
| run: node experiments/tests/browser-smoke.mjs | ||
| - name: Upload screenshots for debugging | ||
| if: always() | ||
| uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: game-browser-screenshots | ||
| path: experiments/browser-artifacts/ | ||
| if-no-files-found: warn | ||
| retention-days: 3 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| // Actual Chromium runtime smoke tests, separate from Node syntax checks. | ||
| // Run with: npm install --no-save playwright && npx playwright install chromium && node experiments/tests/browser-smoke.mjs | ||
| import { chromium } from 'playwright'; | ||
| import { createServer } from 'node:http'; | ||
| import { readFile, mkdir } from 'node:fs/promises'; | ||
| import { extname, resolve, relative, sep, join } from 'node:path'; | ||
| import { once } from 'node:events'; | ||
|
|
||
| const root = resolve('.'); | ||
| const screenshots = resolve('experiments', 'browser-artifacts'); | ||
| await mkdir(screenshots, { recursive: true }); | ||
| const types = { '.html': 'text/html; charset=utf-8', '.css': 'text/css; charset=utf-8', '.js': 'text/javascript; charset=utf-8', '.mjs': 'text/javascript; charset=utf-8', '.json': 'application/json' }; | ||
| const server = createServer(async (req, res) => { | ||
| try { | ||
| const url = new URL(req.url || '/', 'http://localhost'); | ||
| const pathname = decodeURIComponent(url.pathname); | ||
| if (pathname === '/favicon.ico') { res.writeHead(204).end(); return; } | ||
| const path = resolve(root, '.' + pathname, pathname.endsWith('/') ? 'index.html' : ''); | ||
| const rel = relative(root, path); | ||
| if (rel === '..' || rel.startsWith('..' + sep) || path === root) { res.writeHead(403).end('Forbidden'); return; } | ||
| const bytes = await readFile(path); | ||
| res.writeHead(200, { 'content-type': types[extname(path)] || 'application/octet-stream', 'cache-control': 'no-store' }).end(bytes); | ||
| } catch (e) { res.writeHead(404).end('Not found'); } | ||
| }); | ||
| server.listen(0, '127.0.0.1'); | ||
| await once(server, 'listening'); | ||
| const origin = 'http://127.0.0.1:' + server.address().port; | ||
| let browser; | ||
| const results = []; | ||
| try { | ||
| browser = await chromium.launch({ | ||
| headless: true, | ||
| args: ['--enable-webgl', '--use-gl=angle', '--use-angle=swiftshader', '--ignore-gpu-blocklist', '--disable-dev-shm-usage'] | ||
| }); | ||
| for (const game of ['voxel-frontier', 'neon-streets']) { | ||
| for (const mode of ['desktop', 'mobile']) { | ||
| const mobile = mode === 'mobile'; | ||
| const context = await browser.newContext({ | ||
| viewport: mobile ? { width: 390, height: 844 } : { width: 1280, height: 800 }, | ||
| isMobile: mobile, | ||
| hasTouch: mobile, | ||
| deviceScaleFactor: 1 | ||
| }); | ||
| const page = await context.newPage(); | ||
| const errors = []; | ||
| page.on('pageerror', e => errors.push('Uncaught: ' + e.message)); | ||
| page.on('console', m => { if (m.type() === 'error') errors.push('Console: ' + m.text()); }); | ||
| page.on('requestfailed', req => errors.push('Network: ' + req.url() + ' ' + (req.failure()?.errorText || 'failed'))); | ||
| try { | ||
| const response = await page.goto(origin + '/experiments/' + game + '/', { waitUntil: 'domcontentloaded', timeout: 30000 }); | ||
| if (!response?.ok()) throw new Error('Entrypoint returned ' + response?.status()); | ||
| const canvas = page.locator(game === 'voxel-frontier' ? '#game canvas' : '#canvas'); | ||
| await canvas.waitFor({ state: 'visible', timeout: 30000 }); | ||
| await page.waitForTimeout(game === 'voxel-frontier' ? 1800 : 350); | ||
| const state = await canvas.evaluate(c => { | ||
| const rect = c.getBoundingClientRect(); | ||
| const isVoxel = Boolean(c.closest('#game')); | ||
| const gl = isVoxel ? c.getContext('webgl2') : null; | ||
| const ctx = isVoxel ? null : c.getContext('2d'); | ||
| return { width: rect.width, height: rect.height, backingWidth: c.width, backingHeight: c.height, | ||
| webgl: Boolean(gl && !gl.isContextLost()), canvas2d: Boolean(ctx), | ||
| pixel: ctx ? Array.from(ctx.getImageData(Math.floor(c.width / 2), Math.floor(c.height / 2), 1, 1).data) : null }; | ||
| }); | ||
| if (state.width < 200 || state.height < 200 || state.backingWidth < 200 || state.backingHeight < 200) { | ||
| throw new Error('Canvas missing or incorrectly sized: ' + JSON.stringify(state)); | ||
| } | ||
| if (game === 'voxel-frontier' && !state.webgl) throw new Error('Three.js did not establish a live WebGL2 context'); | ||
| if (game === 'neon-streets' && (!state.canvas2d || !state.pixel || state.pixel[3] === 0)) throw new Error('Canvas 2D did not draw'); | ||
| if (mobile) await page.locator('#play').tap(); | ||
| else await page.locator('#play').click(); | ||
| await page.waitForFunction(() => document.querySelector('#start')?.classList.contains('hidden'), null, { timeout: 5000 }); | ||
| if (game === 'neon-streets') { | ||
| if (mobile) { | ||
| const button = page.locator('[data-key="ArrowUp"]'); | ||
| await button.dispatchEvent('pointerdown', { pointerId: 1, bubbles: true }); | ||
| await page.waitForTimeout(700); | ||
| await button.dispatchEvent('pointerup', { pointerId: 1, bubbles: true }); | ||
| } else { | ||
| await page.keyboard.down('ArrowUp'); | ||
| await page.waitForTimeout(700); | ||
| await page.keyboard.up('ArrowUp'); | ||
| } | ||
| const speed = Number((await page.locator('#speed').innerText()).match(/\d+/)?.[0] || 0); | ||
| if (speed < 1) throw new Error('Throttle input did not accelerate vehicle'); | ||
| } else if (!mobile) { | ||
| await page.keyboard.press('Digit2'); | ||
| const selected = await page.locator('#hotbar button.active').getAttribute('data-block'); | ||
| if (selected !== 'stone') throw new Error('Hotbar selection did not respond to keyboard'); | ||
| } | ||
| await page.waitForTimeout(300); | ||
| await page.screenshot({ path: join(screenshots, game + '-' + mode + '.png') }); | ||
| if (errors.length) throw new Error(errors.join('\n').slice(0, 2000)); | ||
| results.push({ game, mode, status: 'PASS', ...state }); | ||
| } catch (e) { | ||
| try { await page.screenshot({ path: join(screenshots, game + '-' + mode + '-FAILED.png') }); } catch {} | ||
| results.push({ game, mode, status: 'FAIL', error: String(e) }); | ||
| process.exitCode = 1; | ||
| } finally { | ||
| await context.close(); | ||
| } | ||
| } | ||
| } | ||
| } finally { | ||
| await browser?.close(); | ||
| await new Promise(resolve => server.close(resolve)); | ||
| } | ||
| for (const result of results) console.log(JSON.stringify(result)); | ||
| if (process.exitCode) console.error('Browser smoke FAILED: see screenshots and errors above.'); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| import test from 'node:test'; | ||
| import assert from 'node:assert/strict'; | ||
| import { existsSync, readFileSync } from 'node:fs'; | ||
| import { dirname, resolve } from 'node:path'; | ||
| import { fileURLToPath } from 'node:url'; | ||
|
|
||
| const root = resolve(dirname(fileURLToPath(import.meta.url)), '..'); | ||
| for (const game of ['voxel-frontier', 'neon-streets']) { | ||
| test(game + ': HTML script mode matches JavaScript import syntax', () => { | ||
| const dir = resolve(root, game); | ||
| const html = readFileSync(resolve(dir, 'index.html'), 'utf8'); | ||
| const js = readFileSync(resolve(dir, 'game.js'), 'utf8'); | ||
| const script = [...html.matchAll(/<script\b([^>]*)><\/script>/g)].find(match => /\bsrc=["']\.\/game\.js["']/.test(match[1])); | ||
| assert.ok(script, 'game.js must be loaded by a script tag'); | ||
| const moduleScript = /\btype=["']module["']/.test(script[1]); | ||
| const staticImports = /^\s*import\s+(?:[\s\S]*?\s+from\s+)?['"][^'"]+['"]\s*;?/m.test(js); | ||
| assert.ok(!staticImports || moduleScript, 'game.js has static imports but index.html uses a classic script: browser SyntaxError'); | ||
| for (const match of js.matchAll(/(?:from\s*|import\s*\(\s*)['"](\.[^'"]+)['"]/g)) { | ||
| assert.ok(existsSync(resolve(dir, match[1])), 'Missing local import: ' + match[1]); | ||
| } | ||
| }); | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the mobile Neon Streets run,
dispatchEventcreates a synthetic DOM event but does not registerpointerId: 1as an active browser pointer. The game'spointerdownhandler consequently throwsNotFoundErrorwhen it callssetPointerCapture(1); thepageerrorlistener records that exception and the check at the end marks every mobile run as failed even if acceleration succeeds. Drive this with a real Playwright pointer/touch action, or otherwise avoid triggering pointer capture with an inactive synthetic pointer.Useful? React with 👍 / 👎.