Files
gibbz/test.js
T
mats 5757156843
Build and Publish / Metadata (push) Successful in 1s
Build and Publish / BuildAndDeployAmd64 (push) Successful in 18s
feat: migrate voice app, add otel/rum, dockerfile, k8s deployment with ingress
2026-09-22 09:43:47 +02:00

77 lines
2.6 KiB
JavaScript

const test = require('node:test');
const assert = require('node:assert');
const http = require('node:http');
test('server module syntax and exports', () => {
assert.ok(true);
});
test('static files exist', () => {
const fs = require('fs');
assert.ok(fs.existsSync('./public/index.html'), 'index.html exists');
assert.ok(fs.existsSync('./public/app.js'), 'app.js exists');
assert.ok(fs.existsSync('./public/style.css'), 'style.css exists');
});
test('server HTTP and WebSocket signaling endpoints', async (t) => {
const { server, wss, interval, startServer } = require('./server');
await startServer(0, '127.0.0.1');
const port = server.address().port;
t.after(() => {
clearInterval(interval);
wss.close();
server.close();
});
// test /api/ice endpoint
const resIce = await fetch(`http://127.0.0.1:${port}/api/ice`);
assert.strictEqual(resIce.status, 200);
const ice = await resIce.json();
assert.ok(Array.isArray(ice.iceServers), 'iceServers array returned');
const stunUrls = ice.iceServers.flatMap((s) => (Array.isArray(s.urls) ? s.urls : [s.urls]));
assert.ok(stunUrls.some((u) => u.includes('turn.k6n.net')), 'cluster stun/turn included');
// test /healthz
const resHealth = await fetch(`http://127.0.0.1:${port}/healthz`);
assert.strictEqual(resHealth.status, 200);
const healthText = await resHealth.text();
assert.strictEqual(healthText, 'ok');
// test WebSocket signaling /ws
const { WebSocket } = require('ws');
const ws = new WebSocket(`ws://127.0.0.1:${port}/ws?room=testroom&name=tester`);
const helloPromise = new Promise((resolve, reject) => {
ws.on('message', (raw) => {
try {
const msg = JSON.parse(raw.toString());
resolve(msg);
} catch (err) {
reject(err);
}
});
ws.on('error', reject);
});
const msg = await helloPromise;
ws.close();
assert.strictEqual(msg.type, 'hello');
assert.strictEqual(msg.room, 'testroom');
assert.ok(msg.id, 'client id assigned');
});
test('TURN credentials generation with TURN_SECRET', () => {
const { iceConfig } = require('./server');
process.env.TURN_SECRET = 'secret123';
try {
const config = iceConfig();
const turnServer = config.iceServers.find((s) => s.urls && (Array.isArray(s.urls) ? s.urls : [s.urls]).some((u) => u.startsWith('turn')));
assert.ok(turnServer, 'turnServer configured');
assert.ok(turnServer.username.endsWith(':gibbz'), 'ephemeral username generated');
assert.ok(turnServer.credential.length > 0, 'HMAC credential generated');
} finally {
delete process.env.TURN_SECRET;
}
});