Skip to content

Commit 2f21278

Browse files
test: stabilize flaky Temporal boundary assertions in DepartureFetcher tests
1 parent 5bf9ad9 commit 2f21278

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

tests/DepartureFetcher.test.mjs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -494,8 +494,9 @@ describe("getDepartureTime", () => {
494494
const reachableTime = fetcher.getReachableTime();
495495
const departureTime = fetcher.getDepartureTime();
496496

497-
// Should be the same when maxUnreachableDepartures is 0
498-
assert.strictEqual(departureTime.toString(), reachableTime.toString());
497+
// Both methods call Temporal.Now independently, so allow minor execution-time drift.
498+
const diff = Math.abs(departureTime.toInstant().epochMilliseconds - reachableTime.toInstant().epochMilliseconds);
499+
assert.ok(diff < 1000);
499500
});
500501

501502
it("should subtract leadTime when unreachable departures configured", () => {
@@ -547,14 +548,14 @@ describe("isReachable", () => {
547548
});
548549

549550
it("should mark departure as reachable when exactly at timeToStation boundary", () => {
550-
const exactTime = new Date();
551-
exactTime.setMinutes(exactTime.getMinutes() + 10); // Exactly timeToStation
551+
const exactInstant = Temporal.Now.instant().add({minutes: 10});
552+
const departure = createDeparture({when: exactInstant.toString()});
552553

553-
const departure = createDeparture({when: exactTime.toISOString()});
554+
fetcher.getReachableTime = () => exactInstant.toZonedDateTimeISO("UTC");
554555

555556
const result = fetcher.isReachable(departure);
556557

557-
// isSameOrAfter should return true for exact match
558+
// Compare exactly equal instants to verify boundary handling (>=).
558559
assert.strictEqual(result, true);
559560
});
560561
});

0 commit comments

Comments
 (0)