Skip to article
Documentation

src/lib/perf/reporter.test.ts

Linked repository file from this build.

import { expect, test } from "bun:test";
import { performanceSample } from "../../../e2e/perf/reporter";

test("performance report preserves later dataset, navigation setup and budget failures", () => {
  const attachment = (name: string, value: unknown) => ({
    name,
    contentType: "application/json",
    body: Buffer.from(JSON.stringify(value)),
  });
  const measurement = {
    component: "reports",
    componentMs: 1234,
    mode: "cold",
    profile: { name: "local" },
    wireBytes: 17,
    apiJsonBytes: 20,
  };
  const sample = performanceSample({
    status: "failed",
    errors: [{ message: "Decoded payload exceeded target" }],
    attachments: [
      attachment("performance", measurement),
      attachment("dataset", { records: 1200 }),
      attachment("navigation-setup", { transferBytes: 250 }),
    ],
  });
  expect(sample).toEqual({
    ...measurement,
    status: "failed",
    dataset: { records: 1200 },
    dataDelivery: null,
    navigationSetup: { transferBytes: 250 },
    errors: ["Decoded payload exceeded target"],
  });
  expect(performanceSample({ status: "failed", errors: [], attachments: [] })).toBeNull();
});