Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified src/subpaths/throttle.ts
Binary file not shown.
22 changes: 22 additions & 0 deletions tests/52_throttle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,19 @@ describe("throttle (M4.7)", () => {
expect(metaOf(logs[1]).repeated).toBe(1);
});

test("different nested dates pass through while equal timestamps collapse", () => {
const clock = fakeClock();
const { logger, logs } = createTestLogger();
logger.use(throttle({ windowMs: 1000, now: clock.now }));

logger.info({ at: new Date(1234) }, "completed");
logger.info({ at: new Date(1234) }, "completed");
logger.info({ at: new Date(5678) }, "completed");

expect(logs).toHaveLength(2);
expect(metaOf(logs[1]).repeated).toBe(1);
});

test("off by default — no throttle middleware means no effect", () => {
const { logger, logs } = createTestLogger();

Expand Down Expand Up @@ -239,6 +252,15 @@ describe("throttle (M4.7)", () => {
expect(keyFor({ x: null })).not.toBe(keyFor({ x: 0 }));
});

test("dates inside nested arrays retain their timestamp and type", () => {
const key = keyFor({ nested: [new Date(1234)] });
expect(key).toBe(keyFor({ nested: [new Date(1234)] }));
expect(key).not.toBe(keyFor({ nested: [new Date(5678)] }));
expect(key).not.toBe(keyFor({ nested: [1234] }));
expect(key).not.toBe(keyFor({ nested: ["d:1234"] }));
expect(key).not.toBe(keyFor({ nested: [{}] }));
});

test("depth beyond the cap collapses to an ellipsis placeholder", () => {
// Build a chain 8 levels deep; past depth 6 the digest stops recursing and emits "…".
const deep = (n: number): unknown => (n === 0 ? "leaf" : { next: deep(n - 1) });
Expand Down