Repository Public
1// Records a real, read-only API answer as a test fixture: { recordedAt, url, status, body }.2// node packages/swap/test/fixtures/record.mjs <provider-dir> <name> <url>3// Nothing here signs or sends anything; it is one GET.4import { mkdirSync, writeFileSync } from 'node:fs';5import { dirname, join } from 'node:path';6import { fileURLToPath } from 'node:url';78const [dir, name, url] = process.argv.slice(2);9if (!dir || !name || !url) { console.error('usage: record.mjs <provider-dir> <name> <url>'); process.exit(2); }10const t0 = Date.now();11const r = await fetch(url, { headers: { accept: 'application/json', 'x-client-id': 'sp-wallet' }, redirect: 'error', signal: AbortSignal.timeout(25_000) });12const text = await r.text();13let body; try { body = JSON.parse(text); } catch { body = text; }14const out = join(dirname(fileURLToPath(import.meta.url)), dir, `${name}.json`);15mkdirSync(dirname(out), { recursive: true });16writeFileSync(out, JSON.stringify({ recordedAt: new Date().toISOString(), url, status: r.status, body }, null, 2) + '\n');17console.log(`${r.status} ${Date.now() - t0}ms ${name} ${typeof body === 'string' ? body.slice(0, 200) : JSON.stringify(body).slice(0, 700)}`);18