import { test } from 'node:test'; import assert from 'node:assert/strict'; import { cancelDebounce, debounce, debounceMs, revertMs } from './timing.ts'; // No document under `node --test`, so every duration reads its fallback, which // is the crate's current value. This is the pin: `makeover-timing` moving a // number and this file not following is a failing test rather than a page that // quietly disagrees with the stylesheet beside it. test('the fallbacks are makeover-timing 0.1.1', () => { assert.equal(revertMs(), 1500); assert.equal(debounceMs(), 150); }); test('a key runs once however many times it is called', async () => { let runs = 0; debounce('k', () => (runs += 1), 5); debounce('k', () => (runs += 1), 5); debounce('k', () => (runs += 1), 5); await new Promise((done) => setTimeout(done, 30)); assert.equal(runs, 1); }); test('two keys are two calls', async () => { const ran: string[] = []; debounce('a', () => ran.push('a'), 5); debounce('b', () => ran.push('b'), 5); await new Promise((done) => setTimeout(done, 30)); assert.deepEqual(ran.sort(), ['a', 'b']); }); test('cancelling drops the call that was waiting', async () => { let ran = false; debounce('c', () => (ran = true), 5); cancelDebounce('c'); await new Promise((done) => setTimeout(done, 30)); assert.equal(ran, false); });