Add a date-independence test (freezes Date at two different days via a preload). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
10 lines
434 B
JavaScript
10 lines
434 B
JavaScript
// Test helper: freeze the wall clock for a child process. FAKE_NOW=<ISO date> (node -r this).
|
|
const RealDate = Date;
|
|
const fixed = new RealDate(process.env.FAKE_NOW).getTime();
|
|
if (!Number.isFinite(fixed)) throw new Error('FAKE_NOW must be a valid ISO date');
|
|
class FakeDate extends RealDate {
|
|
constructor(...a) { if (a.length === 0) super(fixed); else super(...a); }
|
|
static now() { return fixed; }
|
|
}
|
|
globalThis.Date = FakeDate;
|