first-navigation-metrics.test.ts 1.2 KB

1234567891011121314151617181920212223242526272829303132
  1. import { expect, test } from "bun:test"
  2. import { summarizeFirstNavigation } from "../timeline/first-navigation-metrics"
  3. test("reports blank frames before first destination and stable paint", () => {
  4. expect(
  5. summarizeFirstNavigation([
  6. { observedAtMs: 16, source: true, destination: false, content: true },
  7. { observedAtMs: 32, source: false, destination: false, content: false },
  8. { observedAtMs: 48, source: false, destination: true, content: true },
  9. { observedAtMs: 64, source: false, destination: true, content: true },
  10. { observedAtMs: 80, source: false, destination: true, content: true },
  11. ]),
  12. ).toEqual({
  13. samples: 5,
  14. firstDestinationObservedMs: 48,
  15. stableDestinationObservedMs: 80,
  16. sourceSamples: 1,
  17. blankSamples: 1,
  18. unknownSamples: 0,
  19. destinationSamples: 3,
  20. })
  21. })
  22. test("does not report stability for interrupted destination frames", () => {
  23. expect(
  24. summarizeFirstNavigation([
  25. { observedAtMs: 16, source: false, destination: true, content: true },
  26. { observedAtMs: 32, source: false, destination: false, content: true },
  27. { observedAtMs: 48, source: false, destination: true, content: true },
  28. ]).stableDestinationObservedMs,
  29. ).toBeNull()
  30. })