Track HiveGrid Cloud planning reference
This commit is contained in:
1 parent
b3d5ea6764
commit
e341c5938a
5784 files changed
+1104929
-3
No files matched your search
@@ -0,0 +1,62 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
|
||||
import { reportWebVitals } from "./web-vitals";
|
||||
|
||||
describe("reportWebVitals", () => {
|
||||
it("registers handlers for CLS/LCP/INP/TTFB/FCP", async () => {
|
||||
const reporter = vi.fn();
|
||||
const onCLS = vi.fn();
|
||||
const onLCP = vi.fn();
|
||||
const onINP = vi.fn();
|
||||
const onTTFB = vi.fn();
|
||||
const onFCP = vi.fn();
|
||||
await reportWebVitals({
|
||||
reporter,
|
||||
loader: async () => ({ onCLS, onLCP, onINP, onTTFB, onFCP }) as unknown as typeof import("web-vitals"),
|
||||
});
|
||||
expect(onCLS).toHaveBeenCalledWith(reporter);
|
||||
expect(onLCP).toHaveBeenCalledWith(reporter);
|
||||
expect(onINP).toHaveBeenCalledWith(reporter);
|
||||
expect(onTTFB).toHaveBeenCalledWith(reporter);
|
||||
expect(onFCP).toHaveBeenCalledWith(reporter);
|
||||
});
|
||||
|
||||
it("silently no-ops when the library throws", async () => {
|
||||
await expect(
|
||||
reportWebVitals({
|
||||
reporter: vi.fn(),
|
||||
loader: async () => {
|
||||
throw new Error("nope");
|
||||
},
|
||||
})
|
||||
).resolves.toBeUndefined();
|
||||
});
|
||||
|
||||
it("delivers reported metric values via the reporter callback", async () => {
|
||||
const reporter = vi.fn();
|
||||
type CB = (m: { name: string; value: number; rating: string; delta: number; id: string; navigationType: string }) => void;
|
||||
let captured: CB | null = null;
|
||||
await reportWebVitals({
|
||||
reporter,
|
||||
loader: async () =>
|
||||
({
|
||||
onCLS: (cb: CB) => {
|
||||
captured = cb;
|
||||
},
|
||||
onLCP: () => {},
|
||||
onINP: () => {},
|
||||
onTTFB: () => {},
|
||||
}) as unknown as typeof import("web-vitals"),
|
||||
});
|
||||
captured?.({
|
||||
name: "CLS",
|
||||
value: 0.05,
|
||||
rating: "good",
|
||||
delta: 0.05,
|
||||
id: "v1-cls",
|
||||
navigationType: "navigate",
|
||||
});
|
||||
expect(reporter).toHaveBeenCalledTimes(1);
|
||||
expect(reporter.mock.calls[0]?.[0]).toMatchObject({ name: "CLS", value: 0.05 });
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user