This repository has been archived by the owner on Apr 13, 2023. It is now read-only.
Force test-utils
to use the CJS version of React Apollo
#2907
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When running
MockedProvider
tests from a CLI or CI, those tests are run using the CommonJS bundled version of React Apollo (react-apollo.cjs.js
). Thetest-utils
themselves however, likeMockedProvider
, are not included in the productionreact-apollo.cjs.js
bundle, to help keep the prod bundle size down. To useMockedProvider
, it must be accessed using a nested/direct import like:Unfortunately, this nested import means
MockedProvider
is loaded outside of thereact-apollo.cjs.js
bundle, which means it requires and uses its own versions of other supporting React Apollo files. This causes problems in areas like using React's Context API. BothMockedProvider
and the component's it's attempting to test create and use their own versions of shared Context, which are not available to each other. So whenMockedProvider
creates a new Context and adds theclient
instance to it, its child components don't have access to it, since they've created their own Context separately.In React Apollo 3.0 we're going to move the
test-utils
out into their own package, which will fix this problem. As a workaround for now, this PR forces thetest-utils
to use thereact-apollo.cjs.js
version of React Apollo. This means tests have access to the same dependencies as the components being tested.Fixes #2900.