UNPKG

@ogcio/o11y-sdk-react

Version:

Opentelemetry standard instrumentation SDK for React based project

66 lines (52 loc) 2.09 kB
import { test, describe, assert, vi, expect } from "vitest"; import buildFaroInstrumentation from "../lib/instrumentation.faro.js"; import { Faro } from "@grafana/faro-react"; import { instrumentFaro } from "../index.js"; describe("validation config: should return without breaking the execution", () => { test("should call buildFaroInstrumentation without config and skip instrumentation", async () => { const consoleWarnSpy = vi .spyOn(console, "warn") .mockImplementation(vi.fn()); instrumentFaro(); expect(consoleWarnSpy).toHaveBeenCalled(); expect(consoleWarnSpy).toHaveBeenCalledWith( "observability config not set. Skipping Faro OpenTelemetry instrumentation.", ); }); test("faro instrumentation: url undefined", () => { let sdk: Faro | undefined = undefined; const consoleWarnSpy = vi .spyOn(console, "warn") .mockImplementation(vi.fn()); const consoleLogSpy = vi.spyOn(console, "log").mockImplementation(vi.fn()); assert.doesNotThrow(() => { sdk = buildFaroInstrumentation({ collectorUrl: undefined!, }); }); assert.equal(sdk, undefined); expect(consoleWarnSpy).toHaveBeenCalled(); expect(consoleWarnSpy).toHaveBeenCalledWith( "collectorUrl not set. Skipping Faro OpenTelemetry instrumentation.", ); expect(consoleLogSpy).not.toHaveBeenCalled(); }); test("faro instrumentation: invalid url", () => { let sdk: Faro | undefined = undefined; const consoleErrorSpy = vi .spyOn(console, "error") .mockImplementation(vi.fn()); const consoleLogSpy = vi.spyOn(console, "log").mockImplementation(vi.fn()); assert.doesNotThrow(() => { sdk = buildFaroInstrumentation({ collectorUrl: "notavalidURL", }); }); assert.equal(sdk, undefined); expect(consoleErrorSpy).toHaveBeenCalled(); expect(consoleErrorSpy).toHaveBeenCalledWith( "collectorUrl does not use a valid format. Skipping Faro OpenTelemetry instrumentation.", ); expect(consoleLogSpy).not.toHaveBeenCalled(); }); });