import { spawn } from 'node:child_process'; import assert from 'node:assert/strict'; const child = spawn(process.execPath, ['dist/server.js'], { stdio: ['ignore', 'pipe', 'pipe'] }); let errors = ''; child.stderr.on('data', chunk => { errors += chunk; }); try { await new Promise((resolve, reject) => { child.stdout.once('data', resolve); child.once('error', reject); child.once('exit', code => reject(new Error(`Server exited ${code}: ${errors}`))); setTimeout(() => reject(new Error('Startup timeout')), 5000).unref(); }); for (const [path, status] of [['/health',200], ['/guide?at=1793478000000&count=48',200], ['/guide?count=999',400], ['/missing',404]]) { const response = await fetch(`http://127.0.0.1:4317${path}`); assert.equal(response.status, status); const body = await response.json(); if(path.includes('count=48')) { assert.equal(body.channels.length,3); assert.equal(body.channels[0].programmes.length,48); } console.log(`${status} ${path}`); } assert.equal((await fetch('http://127.0.0.1:4317/guide', {method:'POST'})).status,405); console.log('405 POST /guide'); } finally { child.kill('SIGTERM'); }