Files
ytplayer/tests/fixtures/party-server.mjs

17 lines
992 B
JavaScript

// Isolated integration harness: real party relay and frontend chunk; deterministic player.
import { createPartyHub } from '../../server/party.js';
import { join } from 'node:path';
const root = new URL('../../frontend/', import.meta.url).pathname;
const hub = createPartyHub();
const server = Bun.serve({ hostname: '127.0.0.1', port: Number(process.env.PARTY_TEST_PORT || 0),
async fetch(req, srv) {
const path = new URL(req.url).pathname;
if (path === '/ws/party') return hub.upgrade(req, srv, '127.0.0.1');
if (path === '/') return new Response(await Bun.file(new URL('party.html', import.meta.url)).text(), { headers: { 'Content-Type': 'text/html' } });
if (path === '/party-fixture.js') return new Response(Bun.file(new URL('party-fixture.js', import.meta.url)));
if (path.includes('..')) return new Response('', {status: 400});
return new Response(Bun.file(join(root, path)));
}, websocket: hub.websocket,
});
console.log(`http://127.0.0.1:${server.port}`);