Skip to content

Interoperability for test helpers #1939

Open
@aaronadamsCA

Description

We'd like to be able to use the setUpValidRequest() and setUpValidSession() test helpers in a browser environment. Right now they only work in a Node.js environment, and I haven't had any luck with polyfills.

Our use case is mocking Shopify app authentication in Storybook.

For now we've rolled our own interoperable helpers with two main changes.

We're using Jose for JWT signing:

return new SignJWT(payload)
  .setProtectedHeader({ alg: "HS256" })
  .sign(new TextEncoder().encode(CLIENT_SECRET));

And we're using btoa() (which is not deprecated in Node.js!) to encode the host:

const BASE64_HOST = btoa(SHOPIFY_HOST);

With these changes we get interop across multiple runtimes.

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions