test(nav-timing): assert page-load-perf fields present, typed, and non-negative (#678) - #728
Merged
Chucks1093 merged 1 commit intoJul 29, 2026
Conversation
…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).
|
@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! 🚀 |
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Resolves #678.
Adds a new test block to
src/hooks/__tests__/useNavigationTiming.test.tsthat pins the four acceptance criteria from issue #678 for the[page-load-perf]log emitted byuseNavigationTimingon each marketplace / creator-profile mount: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.Number.isFinite(...)and>= 0soNaN,Infinity,-Infinity, and negatives are all caught.routematches the current route string — renders the hook withmarketplaceandcreator_profile(the two real call sites) and asserts each call'spage_namematches.performance.getEntriesByType('navigation')to return[]and asserts noconsole.infocall.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 fieldspage_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 inreadNavigationTimingand the same tests still pass.Field mapping (documented at the top of the new
describeblock)src/hooks/useNavigationTiming.ts)routepage_nametime_to_first_byte_msttfb(responseStart - requestStart)dom_content_loaded_msdcl(domContentLoadedEventEnd - startTime)load_event_msload_complete(loadEventEnd - startTime)Testing
pnpm test src/hooks/__tests__/useNavigationTiming.test.ts— 9 / 9 pass (5 pre-existing + 4 new tests)pnpm lint— clean (no warnings on the modified file)pnpm exec tsc -b— cleanChecklist