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

fix: fetch api polyfill #3262

Merged
merged 2 commits into from
Oct 10, 2023
Merged

fix: fetch api polyfill #3262

merged 2 commits into from
Oct 10, 2023

Conversation

abreu-ct
Copy link
Contributor

@abreu-ct abreu-ct commented Oct 10, 2023

This PR adds Request and Response to the Fetch API polyfill. Unfortunately jsdom does not provide a way to use Node native Fetch API, I used the same approach for the Headers class and also exported Request and Response from node-fetch.

This PR will allow running jest tests with jsdom env that relies on the Fetch API fixing https://github.com/commercetools/merchant-center-frontend/pull/15461

Notes:

In setup-test-framework.js#L2 we are using the unfetch/polyfill to export the Fetch function and relying on node-fetch to export Headers, Request and Response. I tried to change unfetch/polyfill polyfill but unfortunately some tests in merchant-center-frontend started to fail.

@changeset-bot
Copy link

changeset-bot bot commented Oct 10, 2023

🦋 Changeset detected

Latest commit: d9d68b0

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 36 packages
Name Type
@commercetools-frontend/jest-preset-mc-app Patch
@commercetools-applications/merchant-center-template-starter-typescript Patch
@commercetools-applications/merchant-center-template-starter Patch
@commercetools-applications/merchant-center-custom-view-template-starter-typescript Patch
@commercetools-backend/eslint-config-node Patch
@commercetools-backend/express Patch
@commercetools-backend/loggers Patch
@commercetools-frontend/actions-global Patch
@commercetools-frontend/application-components Patch
@commercetools-frontend/application-config Patch
@commercetools-frontend/application-shell-connectors Patch
@commercetools-frontend/application-shell Patch
@commercetools-frontend/assets Patch
@commercetools-frontend/babel-preset-mc-app Patch
@commercetools-frontend/browser-history Patch
@commercetools-frontend/codemod Patch
@commercetools-frontend/constants Patch
@commercetools-frontend/create-mc-app Patch
@commercetools-frontend/cypress Patch
@commercetools-frontend/eslint-config-mc-app Patch
@commercetools-frontend/i18n Patch
@commercetools-frontend/jest-stylelint-runner Patch
@commercetools-frontend/l10n Patch
@commercetools-frontend/mc-dev-authentication Patch
@commercetools-frontend/mc-html-template Patch
@commercetools-frontend/mc-scripts Patch
@commercetools-frontend/notifications Patch
@commercetools-frontend/permissions Patch
@commercetools-frontend/react-notifications Patch
@commercetools-frontend/sdk Patch
@commercetools-frontend/sentry Patch
@commercetools-frontend/url-utils Patch
@commercetools-local/playground Patch
@commercetools-local/visual-testing-app Patch
@commercetools-website/custom-applications Patch
@commercetools-website/components-playground Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Member

@emmenko emmenko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@github-actions
Copy link
Contributor

github-actions bot commented Oct 10, 2023

Deploy preview for merchant-center-application-kit ready!

✅ Preview
https://merchant-center-application-og4cd7s5g-commercetools.vercel.app
https://appkit-sha-8aca4ebd31a29b2b0410b91e2e463a13600002cb.commercetools.vercel.app
https://appkit-pr-3262.commercetools.vercel.app

Built with commit d9d68b0.
This pull request is being automatically deployed with vercel-action

@emmenko emmenko merged commit d4765a2 into main Oct 10, 2023
14 checks passed
@emmenko emmenko deleted the abreu-ct/fix-fetch-api-polyfill branch October 10, 2023 15:04
This was referenced Oct 10, 2023
@harm-meijer
Copy link

@tdeekens @emmenko @abreu-ct I understand why someone would add a polyfill for fetch since that is what a quick google would suggest but that polyfill isn't needed when you use node 18 and would not be needed in a browser for quite some time. The root cause of this issue is because the jsdom environment is outdated and a custom profile representing a more up to date jsdom environment would have solved this better in my opinion.

@emmenko
Copy link
Member

emmenko commented Oct 11, 2023

Thanks for the feedback. That sounds indeed like a better solution.

I'll take a note for us to look into that as a follow up.

@tdeekens
Copy link
Contributor

Thanks make sense. Let's follow-up and first unblock the team :)

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.

4 participants