mirror of
https://github.com/bitsofchris/openaugi-obsidian-plugin.git
synced 2026-07-22 05:46:42 +00:00
test: make distill date-range filter test deterministic
The 'filters content by date range' test used fixed fixture dates (### 2026-02-25) inside a 30-day window, so it passed only while the real clock was within 30 days of that date and began failing as the current date advanced. extractContentByDateRange is correct; it uses new Date() as "now". Pin the system clock with vi.setSystemTime so the fixed fixture dates evaluate deterministically regardless of the wall clock. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
parent
521399efd3
commit
cbc0c1b471
1 changed files with 12 additions and 4 deletions
|
|
@ -167,11 +167,19 @@ describe('DistillService', () => {
|
|||
});
|
||||
|
||||
it('filters content by date range', () => {
|
||||
const content = '# Daily Journal\n\n### 2026-02-25\nRecent entry\n\n### 2025-01-01\nVery old entry';
|
||||
const filtered = (service as any).extractContentByDateRange(content, 30);
|
||||
// Pin "now" so the fixed fixture dates are deterministic regardless of the
|
||||
// real current date. extractContentByDateRange uses new Date() as "now".
|
||||
vi.useFakeTimers();
|
||||
vi.setSystemTime(new Date('2026-02-28T12:00:00Z'));
|
||||
try {
|
||||
const content = '# Daily Journal\n\n### 2026-02-25\nRecent entry\n\n### 2025-01-01\nVery old entry';
|
||||
const filtered = (service as any).extractContentByDateRange(content, 30);
|
||||
|
||||
expect(filtered).toContain('Recent entry');
|
||||
expect(filtered).not.toContain('Very old entry');
|
||||
expect(filtered).toContain('Recent entry');
|
||||
expect(filtered).not.toContain('Very old entry');
|
||||
} finally {
|
||||
vi.useRealTimers();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue