Skip to content

feat(ui-extensions-tester): add shopify.intercept mock and POS event data factories - #4643

Draft
vctrchu wants to merge 1 commit into
vc/pos-resolution-target-typesfrom
vc/pos-intercept-tester-mock
Draft

feat(ui-extensions-tester): add shopify.intercept mock and POS event data factories#4643
vctrchu wants to merge 1 commit into
vc/pos-resolution-target-typesfrom
vc/pos-intercept-tester-mock

Conversation

@vctrchu

@vctrchu vctrchu commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Background

Stacked on #4641, which adds the POS intercept resolution target types. Extensions registering interceptors via shopify.intercept() had no way to unit-test their blocking logic: the tester exposed no intercept on the mock shopify global and no way to invoke a registered interceptor.

Solution

Mirrors the existing addEventListener/dispatch pair:

  • shopify.intercept(name, interceptor) on the mock global — same semantics as the sandbox implementation: interceptor must be a function, event name must be a supported intercept event, one interceptor per event, returns an unregister function.
  • extension.fireIntercept(name, data) — invokes the registered interceptor with {type, ...data} (the host payload shape) and returns its InterceptResult. Returns undefined when nothing is registered; throws if the interceptor returns a Promise, matching the host's synchronous-only rule.
  • Event data factoriescreateCartValidationsEventData() and createPaymentValidationsEventData() build the payloads for fireIntercept() and double as shopify.resolution.event values on the resolution targets from feat(point-of-sale): add resolution target types for cart and payment validations #4641. createPosCart() is now exported (it was already referenced in the harness docs) and backs the cart event factory.

Both READMEs updated per the tester's documentation requirements.

🎩

  • 12 new tests in pos-intercepts.test.ts covering registration rules, unregistration, fire semantics, sync enforcement, and factory defaults — 116 total passing
  • yarn build, eslint, prettier — green
  • Example test suites fail at vitest startup locally (ERR_REQUIRE_ESM, pre-existing on the base branch); relying on CI for those

Checklist

  • I have 🎩'd these changes
  • I have updated relevant documentation

…data factories

Assisted-By: devx/c380b28c-ab53-4c64-a5d7-b1e4b72559e9
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.

1 participant