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

Added @apollo/client/testing/core entry point #8687

Merged

Conversation

wassim-k
Copy link
Contributor

Hi,

MockLink and MockSubscriptionLink from @apollo/client/testing are quite useful for running unit tests against apollo client logic.
The only issue is that @apollo/client/testing has a direct dependency on react through MockedProvider which makes it unusable for other frameworks like Angular that would like to make use of the testing framework without having to pull in react and all of its dependencies.

This PR introduces a new entry point @apollo/client/testing/core which is identical to @apollo/client/testing except it doesn't export MockedProvider allowing other frameworks to make use of it without having to depend on react.

I made sure non of the existing entry points and exports are affected by this change so everything should work as it always has.

I hope you find this useful and please let me know if you can think of other better ways to solve this issue.

Thanks.

@brainkim brainkim self-requested a review August 23, 2021 15:06
src/testing/core/index.ts Outdated Show resolved Hide resolved
benjamn added a commit that referenced this pull request Sep 10, 2021
#8687 (comment)

Until now, the `@apollo/client/testing` entry point has merely
re-exported the contents of `@apollo/client/utilities/testing`, even
though the latter is not an official entry point, leading to "Risky
cross-entry-point nested import..." warnings during build.

This commit moves the contents of `@apollo/client/utilities/testing` to
actually reside within `@apollo/client/testing`, which should be safe
because `@apollo/client/testing` was the only safe way to access these
modules before now.
benjamn added a commit that referenced this pull request Sep 10, 2021
#8687 (comment)

Until now, the `@apollo/client/testing` entry point has merely
re-exported the contents of `@apollo/client/utilities/testing`, even
though the latter is not an official entry point, leading to "Risky
cross-entry-point nested import..." warnings during build.

This commit moves the contents of `@apollo/client/utilities/testing` to
reside within `@apollo/client/testing`, which should be safe
because `@apollo/client/testing` was the only safe way to access these
modules previously.
benjamn added a commit that referenced this pull request Sep 10, 2021
#8687 (comment)

Until now, the `@apollo/client/testing` entry point has merely
re-exported the contents of `@apollo/client/utilities/testing`, even
though the latter is not an official entry point, leading to "Risky
cross-entry-point nested import..." warnings during build.

This commit moves the contents of `@apollo/client/utilities/testing` to
reside within `@apollo/client/testing`, which should be safe
because `@apollo/client/testing` was the only safe way to access these
modules previously.
@benjamn benjamn changed the base branch from master to make-@apollo/client/testing-an-entry-point September 10, 2021 22:17
benjamn added a commit that referenced this pull request Sep 10, 2021
#8687 (comment)

Until now, the `@apollo/client/testing` entry point has merely
re-exported the contents of `@apollo/client/utilities/testing`, even
though the latter is not an official entry point, leading to "Risky
cross-entry-point nested import..." warnings during build.

This commit moves the contents of `@apollo/client/utilities/testing` to
reside within `@apollo/client/testing`, which should be safe
because `@apollo/client/testing` was the only safe way to access these
modules previously.
@benjamn benjamn force-pushed the make-@apollo/client/testing-an-entry-point branch from 9861f01 to bc9f401 Compare September 10, 2021 22:43
@benjamn benjamn assigned benjamn and unassigned benjamn Sep 10, 2021
@benjamn benjamn force-pushed the feature/testing-core-entry-point branch from e175d4b to 634a86d Compare September 10, 2021 22:47
benjamn added a commit to wassim-k/apollo-client that referenced this pull request Sep 10, 2021
@benjamn benjamn added this to the Release 3.5 milestone Sep 10, 2021
Copy link
Member

@benjamn benjamn left a comment

Choose a reason for hiding this comment

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

Thanks for tackling this @wassim-k! I'm happy to merge this PR once #8687 is approved and merged (into release-3.5).

@benjamn benjamn deleted the branch apollographql:release-3.5 September 13, 2021 14:31
@benjamn benjamn closed this Sep 13, 2021
@benjamn benjamn reopened this Sep 13, 2021
@benjamn benjamn changed the base branch from make-@apollo/client/testing-an-entry-point to release-3.5 September 13, 2021 14:33
@benjamn benjamn force-pushed the feature/testing-core-entry-point branch from 3346ab5 to e3f5ed9 Compare September 13, 2021 14:36
@benjamn benjamn merged commit c929c0d into apollographql:release-3.5 Sep 13, 2021
@benjamn
Copy link
Member

benjamn commented Sep 13, 2021

These changes are now available in @apollo/client@3.5.0-beta.13. Please try it out when you have a chance @wassim-k!

As a sign this is working, you should be able to do this in a browser console:

await import("https://esm.run/@apollo/client@3.5.0-beta.13/testing/core")

whereas this (still) doesn't work, because of the React dependencies:

await import("https://esm.run/@apollo/client@3.5.0-beta.13/testing")

@wassim-k
Copy link
Contributor Author

@benjamn works like a treat, thanks heaps for the great work!

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 15, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants