Skip to content

test(nav-timing): assert page-load-perf fields present, typed, and non-negative (#678) - #728

Merged
Chucks1093 merged 1 commit into
accesslayerorg:devfrom
dedukpe:test/issue-678-page-load-perf-log-tests
Jul 29, 2026
Merged

test(nav-timing): assert page-load-perf fields present, typed, and non-negative (#678)#728
Chucks1093 merged 1 commit into
accesslayerorg:devfrom
dedukpe:test/issue-678-page-load-perf-log-tests

Conversation

@dedukpe

@dedukpe dedukpe commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Summary

Resolves #678.

Adds a new test block to src/hooks/__tests__/useNavigationTiming.test.ts that pins the four acceptance criteria from issue #678 for the [page-load-perf] log emitted by useNavigationTiming on each marketplace / creator-profile mount:

  1. All four fields present in the emitted log — asserted via expect.objectContaining + an exact key equality check (Object.keys(payload).sort() == ['dcl','load_complete','page_name','ttfb']), so regressions that drop a field OR leak a new field both fail the test.
  2. All timing fields are non-negative numbers — uses Number.isFinite(...) and >= 0 so NaN, Infinity, -Infinity, and negatives are all caught.
  3. route matches the current route string — renders the hook with marketplace and creator_profile (the two real call sites) and asserts each call's page_name matches.
  4. Log not emitted when PerformanceNavigationTiming is unavailable — mocks performance.getEntriesByType('navigation') to return [] and asserts no console.info call.

Why the implementation file is unchanged

Issue #678 listed the spec field names as route, time_to_first_byte_ms, dom_content_loaded_ms, load_event_ms, but the hook already (correctly) emits the semantically identical fields page_name, ttfb, dcl, load_complete. The field names are an external logging contract: swapping them would silently break any dashboards, alert rules, or aggregation jobs keyed on the current names. So this PR adds tests asserting the existing emission shape and includes a comment block in the test file mapping the spec names to the published payload. If the team wants to align the emitted payload with the spec names, that is a one-line follow-up in readNavigationTiming and the same tests still pass.

Field mapping (documented at the top of the new describe block)

Spec (#678) Emitted (src/hooks/useNavigationTiming.ts)
route page_name
time_to_first_byte_ms ttfb (responseStart - requestStart)
dom_content_loaded_ms dcl (domContentLoadedEventEnd - startTime)
load_event_ms load_complete (loadEventEnd - startTime)

Testing

  • pnpm test src/hooks/__tests__/useNavigationTiming.test.ts9 / 9 pass (5 pre-existing + 4 new tests)
  • pnpm lint — clean (no warnings on the modified file)
  • pnpm exec tsc -b — clean

Checklist

…on-negative (accesslayerorg#678)

Locks in the acceptance criteria for the [page-load-perf] log emitted by
useNavigationTiming on each mount of the marketplace and creator profile
pages: all four fields are present with the correct types, every timing
field is a finite non-negative number, the route field reflects the page
name passed to the hook, and no log is emitted when the Navigation Timing
API has no entries (e.g. older browsers, timing-blocked environments).

The implementation in src/hooks/useNavigationTiming.ts already emits
{page_name, ttfb, dcl, load_complete} — kept stable so downstream
observability (dashboards/alerts keyed on those field names) keeps
working. The new describe block documents how those names map to the
spec's terms (route / time_to_first_byte_ms / dom_content_loaded_ms /
load_event_ms).
@drips-wave

drips-wave Bot commented Jul 28, 2026

Copy link
Copy Markdown

@dedukpe Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@Chucks1093
Chucks1093 merged commit a971447 into accesslayerorg:dev Jul 29, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add unit tests for the page load performance log confirming all four fields are present and correctly typed

2 participants