53 lines · 1.7 KB · TypeScript
RawDownload
import { describe, expect, it } from "vitest";import {  extractPersistedServerObservabilitySettings,  normalizePersistedServerSettingString,  parsePersistedServerObservabilitySettings,} from "./serverSettings"; describe("serverSettings helpers", () => {  it("normalizes optional persisted strings", () => {    expect(normalizePersistedServerSettingString(undefined)).toBeUndefined();    expect(normalizePersistedServerSettingString("   ")).toBeUndefined();    expect(normalizePersistedServerSettingString("  http://localhost:4318/v1/traces  ")).toBe(      "http://localhost:4318/v1/traces",    );  });   it("extracts persisted observability settings", () => {    expect(      extractPersistedServerObservabilitySettings({        observability: {          otlpTracesUrl: "  http://localhost:4318/v1/traces  ",          otlpMetricsUrl: "  http://localhost:4318/v1/metrics  ",        },      }),    ).toEqual({      otlpTracesUrl: "http://localhost:4318/v1/traces",      otlpMetricsUrl: "http://localhost:4318/v1/metrics",    });  });   it("parses lenient persisted settings JSON", () => {    expect(      parsePersistedServerObservabilitySettings(        JSON.stringify({          observability: {            otlpTracesUrl: "http://localhost:4318/v1/traces",            otlpMetricsUrl: "http://localhost:4318/v1/metrics",          },        }),      ),    ).toEqual({      otlpTracesUrl: "http://localhost:4318/v1/traces",      otlpMetricsUrl: "http://localhost:4318/v1/metrics",    });  });   it("falls back cleanly when persisted settings are invalid", () => {    expect(parsePersistedServerObservabilitySettings("{")).toEqual({      otlpTracesUrl: undefined,      otlpMetricsUrl: undefined,    });  });});