-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathtest14PhaserArlo.js
More file actions
101 lines (85 loc) · 3.69 KB
/
Copy pathtest14PhaserArlo.js
File metadata and controls
101 lines (85 loc) · 3.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import { spawn } from 'child_process';
import net from 'net';
const port = await getFreePort();
const child = spawn(process.execPath, ['09-phaser-arlo/server.js'], {
cwd: process.cwd(),
env: {
...process.env,
PHASER_ARLO_PORT: String(port),
PHASER_ARLO_REALTIME_CACHE_URL: `http://127.0.0.1:${port + 1000}`
},
stdio: ['ignore', 'pipe', 'pipe']
});
const logs = [];
child.stdout.on('data', (chunk) => logs.push(chunk.toString()));
child.stderr.on('data', (chunk) => logs.push(chunk.toString()));
try {
await waitFor(() => fetchJson(`http://127.0.0.1:${port}/health`), 'arlo health');
const health = await fetchJson(`http://127.0.0.1:${port}/health`);
assert(health.ok === true && health.service === 'phaser-arlo', 'health payload mismatch');
pass('health_ready', `port=${port}`);
const html = await fetchText(`http://127.0.0.1:${port}/`);
assert(html.includes('rtms-arlo-root') && html.includes('RTMS Arlo Workshop') && html.includes('Stress 150'), 'missing app shell');
pass('single_page_loaded');
const js = await fetchText(`http://127.0.0.1:${port}/src/main.js`);
assert(js.includes('new PIXI.Application') && js.includes('DummyRealtimeFeed') && js.includes('powerPreference'), 'missing Pixi dummy code');
assert(js.includes('Webhook Police Station') && js.includes('Reconnect Hospital') && js.includes('failReconnect'), 'missing rejected/reconnect map areas');
assert(js.includes('highDensityMode') && js.includes('seedStress') && js.includes('drawBulkActors'), 'missing high-density stress support');
assert(js.includes('prisonTextureKey') && js.includes('REJECTED_GATE_PROGRESS'), 'missing prison stripe rejected-webhook state');
pass('pixi_script_loaded');
const pixi = await fetchText(`http://127.0.0.1:${port}/vendor/pixi.min.js`);
assert(pixi.includes('PIXI'), 'Pixi runtime was not served');
pass('pixi_runtime_served');
const asset = await fetch(`http://127.0.0.1:${port}/assets/arlo-sprite.jpg`);
assert(asset.ok && Number(asset.headers.get('content-length') || 0) > 1000, 'sprite asset missing');
pass('arlo_sprite_served');
const streams = await fetchJson(`http://127.0.0.1:${port}/api/cache/streams`);
assert(Array.isArray(streams.streams), 'cache streams fallback did not return an array');
assert(streams.unavailable === true, 'cache fallback should mark unavailable when upstream is absent');
pass('cache_proxy_fallback');
console.log('14 Pixi Arlo tester passed');
} finally {
child.kill('SIGTERM');
}
function getFreePort() {
return new Promise((resolve, reject) => {
const server = net.createServer();
server.on('error', reject);
server.listen(0, '127.0.0.1', () => {
const address = server.address();
server.close(() => resolve(address.port));
});
});
}
async function waitFor(operation, label, timeoutMs = 5000) {
const start = Date.now();
let lastError = null;
while (Date.now() - start < timeoutMs) {
try {
return await operation();
} catch (error) {
lastError = error;
await delay(100);
}
}
throw new Error(`Timed out waiting for ${label}: ${lastError?.message || logs.join('')}`);
}
async function fetchJson(url) {
const response = await fetch(url);
if (!response.ok) throw new Error(`${url} returned ${response.status}`);
return response.json();
}
async function fetchText(url) {
const response = await fetch(url);
if (!response.ok) throw new Error(`${url} returned ${response.status}`);
return response.text();
}
function delay(ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
function assert(condition, message) {
if (!condition) throw new Error(message);
}
function pass(name, reason = '') {
console.log(`PASS ${name}${reason ? ` reason=${reason}` : ''}`);
}