// 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' // 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=') } /** 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 }