Skip to content
Myr

clock.test.ts

This file

Path

packages/testkit/test/clock.test.ts

46 lines · 1.5 KiB · TypeScript

Last changed by

Not known.

History of this file

Take it

The walk stopped after 200 commits: lines older than 678c8b8 point at it.

Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8

lines 1–46why, one step back
1import { describe, expect, it } from "@effect/vitest";
2import { Clock, DateTime, Duration, Effect, Fiber } from "effect";34import { advanceTo, at, defaultNow, hours } from "../src/clock.ts";56describe("the test clock helpers", () => {7 it("reads an ISO instant as a UTC date-time", () => {8 expect(DateTime.toEpochMillis(at("2026-10-07T12:00:00Z"))).toBe(9 1_791_374_400_00010 );11 expect(DateTime.isUtc(at("2026-10-07T12:00:00Z"))).toBeTruthy();12 expect(defaultNow).toStrictEqual(at("2026-10-07T12:00:00Z"));13 });1415 it("counts hours as durations", () => {16 expect(Duration.toMillis(hours(2))).toBe(7_200_000);17 expect(Duration.toMillis(hours(24))).toBe(86_400_000);18 });1920 it.effect("moves the test clock to an instant", () =>21 Effect.gen(function* () {22 yield* advanceTo("2026-10-07T12:00:00Z");2324 expect(yield* Clock.currentTimeMillis).toBe(1_791_374_400_000);25 expect(yield* DateTime.now).toStrictEqual(at("2026-10-07T12:00:00Z"));26 })27 );2829 it.effect(30 "wakes what sleeps until the instant it moves to, and nothing later",31 () =>32 Effect.gen(function* () {33 yield* advanceTo("2026-10-07T12:00:00Z");3435 const warn = yield* Effect.forkChild(Effect.sleep(hours(2)));36 const lapse = yield* Effect.forkChild(Effect.sleep(hours(24)));3738 yield* advanceTo("2026-10-07T14:00:00Z");3940 expect(warn.pollUnsafe()).toBeDefined();41 expect(lapse.pollUnsafe()).toBeUndefined();4243 yield* Fiber.interrupt(lapse);44 })45 );46});