import assert from 'node:assert/strict'; import test from 'node:test'; import { createRequestGate } from '../src/utils/requestGate.js'; test('only the newest request may update the page', () => { const gate = createRequestGate(); const oldRequest = gate.begin(); const newRequest = gate.begin(); assert.equal(gate.isCurrent(oldRequest), false); assert.equal(gate.isCurrent(newRequest), true); }); test('sync invalidates every request that started before cache clearing', () => { const gate = createRequestGate(); const beforeSync = gate.begin(); gate.invalidate(); assert.equal(gate.isCurrent(beforeSync), false); const freshSnapshot = gate.begin(); assert.equal(gate.isCurrent(freshSnapshot), true); });