import { test } from 'node:test'; import assert from 'node:assert/strict'; import { dedupeInFlight } from './inFlight'; test('dedupeInFlight: one request per key while pending, a new one after (#318)', async () => { const once = dedupeInFlight(); let calls = 0; let release!: () => void; const gate = new Promise((r) => { release = r; }); const run = async () => { calls += 1; await gate; return calls; }; const a = once('d1', run); const b = once('d1', run); const c = once('d2', run); assert.equal(a, b); release(); assert.deepEqual(await Promise.all([a, b, c]), [2, 2, 2]); assert.equal(calls, 2); await once('d1', run); assert.equal(calls, 3, 'settled requests are not reused'); }); test('dedupeInFlight: a rejection clears the key', async () => { const once = dedupeInFlight(); await assert.rejects(once('k', () => Promise.reject(new Error('boom')))); await once('k', () => Promise.resolve()); });