Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interoperability for test helpers #1939

Open
aaronadamsCA opened this issue Jan 7, 2025 · 2 comments
Open

Interoperability for test helpers #1939

aaronadamsCA opened this issue Jan 7, 2025 · 2 comments

Comments

@aaronadamsCA
Copy link

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.

@lizkenyon
Copy link
Contributor

Hi there 👋

Thanks for the flag! If you would like to contribute a PR, for these changes the team would prioritize reviewing.

@aaronadamsCA
Copy link
Author

Thanks @lizkenyon, IMHO the team should probably figure out how the tests would work first. Before making any changes I'd want to know they'd be tested in both Node.js and browser environments going forward.

Without that there's a pretty good chance my PR would break someone else's environment, or someone else's future PR would break mine.

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

No branches or pull requests

2 participants