This repository was 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
Merged
Conversation
test-utils to use the CJS version of React Apollo
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`). The `test-utils` themselves however, like
`MockedProvider`, are not included in the production
`react-apollo.cjs.js` bundle, to help keep the prod bundle size
down. To use `MockedProvider`, it must be accessed using a
nested/direct import like:
```
import { MockedProvider } from "react-apollo/test-utils";
```
Unfortunately, this nested import means `MockedProvider` is
loaded outside of the `react-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. Both `MockedProvider` 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 when `MockedProvider` creates a new Context and adds
the `client` 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 commit forces the `test-utils` to use
the `react-apollo.cjs.js` version of React Apollo. This means
tests have access to the same dependencies as the components
being tested.
Fixes #2900.
This was referenced May 10, 2019
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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
MockedProvidertests from a CLI or CI, those tests are run using the CommonJS bundled version of React Apollo (react-apollo.cjs.js). Thetest-utilsthemselves however, likeMockedProvider, are not included in the productionreact-apollo.cjs.jsbundle, 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
MockedProvideris loaded outside of thereact-apollo.cjs.jsbundle, 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. BothMockedProviderand 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 whenMockedProvidercreates a new Context and adds theclientinstance 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-utilsout into their own package, which will fix this problem. As a workaround for now, this PR forces thetest-utilsto use thereact-apollo.cjs.jsversion of React Apollo. This means tests have access to the same dependencies as the components being tested.Fixes #2900.