gitoria

jukebox

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit0bb027da0bb027daconductor: caramboleyo is the user, not owner/creatorApollo0bb027da/plugins/fetch/tests/try-fetch.mjs

2.8 KB

  1. import http from 'node:http';
  2. import net from 'node:net';
  3. import { spawn } from 'node:child_process';
  4. import { mkdir, writeFile, copyFile } from 'node:fs/promises';
  5. import path from 'node:path';
  6. import { fileURLToPath } from 'node:url';
  7. const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../../..');
  8. const bin = process.env.HL_BIN || path.join(root, 'native/zig-out/bin/hybriel');
  9. const work = process.env.TMPDIR;
  10. if (!work) throw new Error('set TMPDIR to scratch');
  11. const sockets = new Set();
  12. const web = http.createServer((req, res) => {
  13. const code = Number(req.url.slice(1));
  14. res.writeHead(code, { 'content-type': 'application/json', date: 'fixed', connection: 'close' });
  15. res.end(JSON.stringify({ code }));
  16. });
  17. const slow = net.createServer(s => { sockets.add(s); s.on('close', () => sockets.delete(s)); });
  18. function listen(s, port) { return new Promise((r, j) => { s.once('error', j); s.listen(port, '127.0.0.1', r); }); }
  19. function run(args) {
  20. return new Promise((resolve, reject) => {
  21. const p = spawn(args[0], args.slice(1), { cwd: root, env: process.env });
  22. let out = '', err = '';
  23. p.stdout.on('data', s => out += s); p.stderr.on('data', s => err += s);
  24. p.on('error', reject); p.on('close', code => code ? reject(new Error(`${args.join(' ')} exit ${code}\n${out}${err}`)) : resolve(out));
  25. });
  26. }
  27. try {
  28. const probe = net.createServer(); await listen(probe, 32262); await new Promise(r => probe.close(r));
  29. await listen(web, 32260); await listen(slow, 32261);
  30. const fixture = path.join(root, 'plugins/fetch/tests/try_fetch.hl');
  31. const native = await run([bin, fixture]);
  32. await run([bin, '--native', fixture, '-o', path.join(work, 'try-fetch')]);
  33. const compiled = await run([path.join(work, 'try-fetch')]);
  34. const jsdir = path.join(work, 'try-fetch-js'); await mkdir(jsdir, { recursive: true });
  35. await writeFile(path.join(jsdir, 'package.json'), '{"type":"module"}');
  36. await run([bin, '--js', '--entry', fixture, '-o', path.join(jsdir, 'probe.mjs')]);
  37. await writeFile(path.join(jsdir, 'hl-runtime.js'), await run([bin, '--js-runtime']));
  38. await mkdir(path.join(jsdir, 'hl-modules'), { recursive: true });
  39. await copyFile(path.join(root, 'plugins/fetch/server.js'), path.join(jsdir, 'hl-modules/fetch.js'));
  40. const js = await run(['node', path.join(jsdir, 'probe.mjs')]);
  41. if (native !== compiled || native !== js) throw new Error(`different answers\nrun:${native}\nnative:${compiled}\njs:${js}`);
  42. if (!native.includes('connection refused') || !native.includes('timed out') || !native.includes('true true true true true true {"code":200} 200') || !native.includes('true true true true true true {"code":404} 404')) throw new Error(native);
  43. console.log('PASS 4 scenarios, identical run/native/JS answers\n' + native);
  44. } finally {
  45. for (const s of sockets) s.destroy();
  46. await Promise.all([web, slow].map(s => new Promise(r => s.listening ? s.close(r) : r())));
  47. }

Branches

Latest commits

  • 0bb027daconductor: caramboleyo is the user, not owner/creatorApollo
  • 04f5d9d5Merge branch 'day41' into mainJukebox
  • 8ed6da45|||PR README: media-player pin df9e7dfmre
  • d5d45fc3|||PR media-player df9e7df (repeat-one fix), sync pin and SOURCEmre
  • 89cdabb1Vendor Hybriel day41 (57054d9e): plugin dirs, set .somre
  • 1fecd6a7Merge branch 'records-day39' into mainJukebox
  • d6b3e068|||PR Records: day39 live (PR #2), mission 011 PR step, statusmre
  • 5fa19e89Merge branch 'day39' into mainJukebox
  • cfe95440|||PR day39 re-vendor: Hybriel 51e921d7 (bin 6b481aa7), ids kebab-case since hybriel#256: quoted state rule and tests use jb-shuffle / jb-repeatmre
  • f3614c9bRe-vendor to Hybriel day39 (51e921d7, bin 6b481aa7)mre
  • 9f5c6532Merge branch 'status-22-pr' into mainJukebox
  • 5838d6c7|||PR STATUS: #22 pending decision, PR-only rulemre
  • 29d2029cRecords: PR-only rule (Kunibert)mre
  • adacb0abRecords: neutral ticket rule, #22 decision recordedmre
  • b2d6f121Records: #308 hold liftedmre
  • 7ab67533Records: day39 on hold (hybriel#308)mre
  • 22f21739Records: note rebase before mergemre
  • f7368ea3Records: mission 011 day39, waits for lisbethmre
  • 9515d2cdRecords: jb20 livemre
  • 019f6601ui gate: comment names the open bug components#27 (workaround, not fixed)mre