Skip to content

Commit 9894921

Browse files
committed
fix(api): stop fakeToday test helper from leaking frozen Date.now across files
The helper mutated the real Date constructor's static .now before swapping globalThis.Date, so cleanup assigned to FakeDate.now instead of restoring the real one. Subsequent test files saw Date.now() frozen at the last fakeNow value, flipping isExpired() checks in api-key.test.ts when files ran in a certain order in CI.
1 parent ad7a719 commit 9894921

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

apps/api/src/lib/date-presets.test.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@ import type { DatePreset } from "../schemas/query-schemas";
44

55
function fakeToday(dateStr: string) {
66
const fakeNow = new Date(`${dateStr}T12:00:00Z`).getTime();
7-
const original = Date.now;
8-
Date.now = () => fakeNow;
9-
const _origDate = globalThis.Date;
10-
const OrigDate = Date;
7+
const OrigDate = globalThis.Date;
118
const FakeDate = function (...args: unknown[]) {
129
if (args.length === 0) return new OrigDate(fakeNow);
1310
// @ts-expect-error - constructor forwarding
@@ -19,8 +16,7 @@ function fakeToday(dateStr: string) {
1916
FakeDate.prototype = OrigDate.prototype;
2017
globalThis.Date = FakeDate;
2118
return () => {
22-
Date.now = original;
23-
globalThis.Date = _origDate;
19+
globalThis.Date = OrigDate;
2420
};
2521
}
2622

0 commit comments

Comments
 (0)