Files
xenia-pos-local/tests/e2e/lib/env.mjs
T
bonaminandClaude Opus 5.5 584dd1e510 test: end-to-end suites (install.sh, licensing, browser, Android emulator) + runner
tests/e2e (see its README):
- install.mjs: real install.sh in a Debian container - VPN-safe HOST_IP
  detection on simulated hosts, fresh/upgrade/re-run, and the proxy config
  byte-identical to nginx-proxy/nginx.conf (guards rule CS-5)
- license_e2e.py: real cloud + site processes with a throwaway signing key -
  400 days offline, tampered file, clock rollback, expiry deferred to workday
  close, renewal, remote lock
- browser.mjs: web delivery modes (same-origin, plain HTTP by LAN IP, venue
  mode) and the install dialog on Android/iPhone/desktop/no-APK
- android.mjs basics|rediscovery|stacks: pairing, venues, camera, back
  button, restart; IP change / server down / cold start; TLS pinning
  (wrong-key QR, impostor, upgrade, renewal, rediscovery) and UI bundles
  (apply, staged, tampered, APK too old, rollback, two venues) on isolated
  compose stacks built from the repo
- lib/: env (paths, LAN IP autodetect, settings), proc (seeded throwaway
  DBs via demo_seed.py, backends, nginx, Vite, compose stacks), android
  (adb + WebView DevTools, boots the AVD), cdp
- run-all.mjs runs everything fastest-first with a summary
Nothing machine-specific is hard-coded; developer stacks/DBs are never touched.
Results on this machine: install 9/9, license 17/17, browser 22/22,
android basics 19/19, rediscovery 10/10, stacks 21/21.

Pack README: Testing section + rule CS-11 (tests follow the code; run
run-all before a release).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-28 23:38:18 +03:00

72 lines
2.9 KiB
JavaScript

// Shared settings for the end-to-end suites. Everything is derived from the repo
// layout or the environment — no machine-specific paths or IPs are hard-coded.
import { mkdirSync } from 'node:fs'
import os from 'node:os'
import path from 'node:path'
import { fileURLToPath } from 'node:url'
const here = path.dirname(fileURLToPath(import.meta.url))
export const E2E = path.resolve(here, '..') // client-services/tests/e2e
export const CS = path.resolve(E2E, '..', '..') // client-services
export const REPO = path.resolve(CS, '..') // xenia-pos (parent)
export const BACKEND = path.join(CS, 'local_backend')
export const WAITER = path.join(CS, 'waiter_pwa')
export const CLOUD = process.env.CLOUD_DIR || path.join(REPO, 'cloud-service', 'cloud_backend')
export const OUT = path.join(E2E, 'out') // screenshots, logs, temp data (gitignored)
mkdirSync(OUT, { recursive: true })
export const PYTHON = process.env.PYTHON || (process.platform === 'win32' ? 'python' : 'python3')
// Playwright browser: system Edge by default; BROWSER_CHANNEL= (empty) uses Playwright's own Chromium
export const BROWSER_CHANNEL = process.env.BROWSER_CHANNEL ?? 'msedge'
// Break-glass login the test backends are started with (never a real account)
export const MASTER = { username: 'e2e', password: 'e2e-pass-123' }
// The Android emulator reaches the host machine at this address
export const EMULATOR_HOST = '10.0.2.2'
/**
* This machine's LAN IPv4 — for "plain HTTP by LAN IP" browser tests.
* LAN_IP wins; otherwise the first address on a non-virtual, non-VPN adapter.
*/
export function lanIp() {
if (process.env.LAN_IP) return process.env.LAN_IP
const skip = /vEthernet|WSL|docker|br-|veth|virtual|vmware|vbox|hyper-v|wireguard|wg\d|tailscale|zerotier|vpn|loopback/i
for (const [name, addrs] of Object.entries(os.networkInterfaces())) {
if (skip.test(name)) continue
const a = (addrs || []).find(x => x.family === 'IPv4' && !x.internal && !x.address.startsWith('169.254.'))
if (a) return a.address
}
throw new Error('Could not detect this machine\'s LAN IP — set LAN_IP=<ip>')
}
/** Tiny PASS/FAIL reporter shared by the suites. */
export function reporter(suite) {
let failures = 0
console.log(`\n── ${suite}`)
return {
check(name, ok, extra = '') {
if (!ok) failures++
console.log(`${ok ? 'PASS' : 'FAIL'} ${name}${extra ? ' ' + extra : ''}`)
},
done() {
console.log(failures ? `✗ ${suite}: ${failures} failure(s)` : `✓ ${suite}: all passed`)
return failures
},
}
}
export const sleep = ms => new Promise(r => setTimeout(r, ms))
export async function waitFor(fn, timeoutMs, stepMs = 1000) {
const t0 = Date.now()
while (Date.now() - t0 < timeoutMs) {
try {
const r = await fn()
if (r) return r
} catch {
// not yet
}
await sleep(stepMs)
}
return null
}