Add PerfKit integration contract tests#3774
Open
dangayle wants to merge 1 commit into
Open
Conversation
Contributor
|
Oxygen deployed a preview of your
Learn more about Hydrogen's GitHub integration. |
Lock down the deterministic Hydrogen <-> PerfKit contract with dedicated tests, without changing runtime behavior: - Export the pinned PERF_KIT_URL constant (shopify-perf-kit-spa.min.js) so the exact SPA script URL is asserted in tests; bumping it is now a deliberate, reviewed change. - Memoize the data-* attributes object (stable identity; lets tests assert the exact attributes). No behavior change. - PerfKit.test.tsx covers: SPA script URL; exact data-* attributes; shop GID parsing; storefront id from hydrogenSubchannelId; Internal_Shopify_Perf_Kit registration; no wiring while loading/error; wiring only after done; all five view subscriptions; ready() once after wiring; no double-wire across a loading->done transition; page_viewed -> navigate(); product/collection/ search/cart -> setPageType(...); no throw when window.PerfKit is absent. Non-user-facing, nothing exported from the package entrypoint, no semver change (empty changeset). Requested by Dan Gayle <dan.gayle@shopify.com>
d6e6b62 to
da534b6
Compare
andguy95
approved these changes
Jun 4, 2026
| @@ -0,0 +1,6 @@ | |||
| --- | |||
Collaborator
There was a problem hiding this comment.
This change set can be removed as there is not package bumps!
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.
What this PR does
PerfKit.tsxhad zero tests, so if someone accidentally changed a label, broke the load order, or stopped pinging PerfKit on navigation, nothing would catch it — it would just silently ship broken.This PR adds a safety net. Three small things:
PerfKit.test.tsxchecks the adapter still does exactly what it should — loads the right script URL, sets the rightdata-*labels, waits until the script is loaded before wiring anything up, and calls PerfKit on the five view events. If anyone breaks the contract later, the test fails.PERF_KIT_URL) so the test can point at it, and so changing that URL becomes a deliberate, reviewed edit instead of a quiet one.data-*labels into a single object so the test can read them. No behavior change.That's the whole PR. No new features, nothing users see, no version bump. It's purely a guard so Hydrogen can't accidentally break its own PerfKit wiring.
What the tests lock down
PerfKit.test.tsx(PerfKit is mocked at the network level — the real script is never downloaded):data-*labels exactly:data-application=hydrogen,data-spa-mode=true, parseddata-shop-id,data-storefront-id(fromhydrogenSubchannelId),data-monorail-region=global,data-resource-timing-sampling-rate=100.Internal_Shopify_Perf_Kit.loading, and not onerror— only after it'sdone.page_viewed,product_viewed,collection_viewed,search_viewed,cart_viewed).ready()exactly once, after wiring.loading → donetransition (the re-render guard).page_viewed → window.PerfKit.navigate(); product/collection/search/cart →setPageType(...).window.PerfKitisn't there yet (script-load race).About versions
The PerfKit script URL is pinned in
PERF_KIT_URLand asserted exactly in the test:https://cdn.shopify.com/shopifycloud/perf-kit/shopify-perf-kit-spa.min.jsHeads-up for reviewers: this URL is not stable across Hydrogen versions (older builds used a versioned URL like
shopify-perf-kit-1.0.1.min.js; the current build uses the unversioned-spabundle), andwindow.PerfKitexposes no runtime version. This PR just pins the current-spabuild. Giving PerfKit an explicit version/capability signal is a separate, cross-team follow-up.Scope / impact
PERF_KIT_URLis module-local — nothing new is exported from the package entrypoint. No runtime behavior change. No semver bump (empty changeset).PerfKit.tsx,PerfKit.test.tsx(new), and an empty changeset.Checks run
pnpm --dir packages/hydrogen typecheck✅pnpm --dir packages/hydrogen test✅ — 58 files, 548 testspnpm --dir packages/hydrogen exec vitest run src/analytics-manager/PerfKit.test.tsx✅ — 16 testseslint+prettieron changed files ✅Follow-ups (separate, not in this PR)
Requested by Dan Gayle dan.gayle@shopify.com