import http from 'node:http'; import {pathToFileURL} from 'node:url'; export const cases={ '/before/removed':[200,'Page not found'], '/after/removed':[404,'Page not found'], '/after/moved':[301,'Moved','/after/replacement'], '/after/replacement':[200,'Product guide'], '/after/live':[200,'Shipping guide'], }; export function createFixture(port=8080){ return http.createServer((request,response)=>{ const [status,title,location]=cases[request.url]??[404,'Page not found']; response.writeHead(status,{'Content-Type':'text/html; charset=utf-8',...(location?{Location:location}:{})}); response.end(''+title+'

'+title+'

'); }).listen(port,'127.0.0.1'); } if (process.argv[1] && import.meta.url===pathToFileURL(process.argv[1]).href) { const server=createFixture(); server.on('listening',()=>console.log('Fixture: http://127.0.0.1:8080')); }