spb/earth-now Public License
earth-now.co — real-time planetary dashboard: live world metrics modeled, not streamed.
TypeScript 93%
Shell 2.3%
SQL 1.4%
JavaScript 1.3%
Dockerfile 1.2%
CSS 0.8%
1/**2 * earth-now.co3 * Author: Simon-Pierre Boucher4 * Contact: contact@spboucher.ai5 * File: apps/web/test/consistency.jsdom.test.ts6 * Purpose: Client/server consistency — counterValue in the JSDOM (browser-like) environment must match the same closed-form values bit-for-bit7 *8 * @vitest-environment jsdom9 */1011import { describe, expect, it } from "vitest";12import { counterValue, parseIsoUtc } from "@earth-now/counter";13import {14 INSTANTS,15 LINEAR_MODEL,16 SEASONAL_MODEL,17 linearClosedForm,18 seasonalClosedForm,19} from "./consistency-shared";2021describe("counterValue consistency (jsdom environment)", () => {22 it("runs in a browser-like environment (DOM present)", () => {23 expect(typeof globalThis.window).not.toBe("undefined");24 expect(typeof document).not.toBe("undefined");25 });2627 it("value(anchorTime) === anchorValue exactly", () => {28 const anchorMs = parseIsoUtc(LINEAR_MODEL.anchorTime);29 expect(Object.is(counterValue(LINEAR_MODEL, anchorMs), LINEAR_MODEL.anchorValue)).toBe(true);30 expect(Object.is(counterValue(SEASONAL_MODEL, anchorMs), SEASONAL_MODEL.anchorValue)).toBe(31 true,32 );33 });3435 it("matches the linear closed form bit-for-bit at all five instants (same values as node)", () => {36 for (const t of INSTANTS) {37 expect(Object.is(counterValue(LINEAR_MODEL, t), linearClosedForm(t))).toBe(true);38 }39 });4041 it("matches the seasonal closed form bit-for-bit at all five instants (same values as node)", () => {42 for (const t of INSTANTS) {43 expect(Object.is(counterValue(SEASONAL_MODEL, t), seasonalClosedForm(t))).toBe(true);44 }45 });4647 it("is deterministic: re-evaluation yields Object.is-identical numbers", () => {48 for (const t of INSTANTS) {49 expect(Object.is(counterValue(LINEAR_MODEL, t), counterValue(LINEAR_MODEL, t))).toBe(true);50 expect(Object.is(counterValue(SEASONAL_MODEL, t), counterValue(SEASONAL_MODEL, t))).toBe(51 true,52 );53 }54 });55});56