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

Test Utils for Apollo-server #1909

Merged
merged 17 commits into from Nov 5, 2018
Merged

Test Utils for Apollo-server #1909

merged 17 commits into from Nov 5, 2018

Conversation

JakeDawkins
Copy link
Contributor

@JakeDawkins JakeDawkins commented Nov 1, 2018

TODO:

  • Update CHANGELOG.md with your change (include reference to issue & this PR)
  • Make sure all of the significant new logic is covered by tests
  • Rebase your changes on master so that they can be merged easily
  • Make sure all tests and linter rules pass

@JakeDawkins JakeDawkins changed the title Jake testing Test Utils for Apollo-server Nov 1, 2018
Copy link
Member

@abernix abernix left a comment

Choose a reason for hiding this comment

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

This is awesome! I've made a few suggestions and comments which I think need addressing, but this should really help with testing!

package-lock.json Outdated Show resolved Hide resolved
packages/apollo-server-core/src/ApolloServer.ts Outdated Show resolved Hide resolved
packages/apollo-server-testing/src/createTestClient.ts Outdated Show resolved Hide resolved
packages/apollo-server-testing/src/createTestClient.ts Outdated Show resolved Hide resolved
packages/apollo-server-testing/src/createTestClient.ts Outdated Show resolved Hide resolved
packages/apollo-server-testing/src/index.ts Outdated Show resolved Hide resolved
packages/apollo-server-testing/src/index.ts Outdated Show resolved Hide resolved
packages/apollo-server-testing/src/createTestClient.ts Outdated Show resolved Hide resolved
packages/apollo-server-testing/package.json Show resolved Hide resolved
@abernix abernix merged commit e3d5be9 into master Nov 5, 2018
@abernix abernix deleted the jake-testing branch November 5, 2018 19:22
abernix added a commit that referenced this pull request May 28, 2020
The `apollo-server-testing` package uses an internal Apollo Server method
called `executeOperation` (introduced in [#1909]) in order to power its
`createTestClient` functionality.  This is the testing practice which is
documented within [Integration testing] in the Apollo Server documentation.

However, it failed to introduce the same context-cloning which [takes place
in `runHttpQuery`][Ref 1], prior to arriving at the main request pipeline.

Since the context was not cloned, and we had made the expectation in [#3988]
that it was a unique context on every single request (which it was, in a
non-testing context), the Symbol we use to implement `willResolveField` was
already present [on the request pipeline][Ref 2] when running a subsequent
test via `createTestClient`!

This commit introduces the same cloning that takes place in
`buildRequestContext` within `runHttpQuery`, and adds tests to ensure the
behavior is preserved.

[Fixes #4170]: #4170
[#1909]: #1909
[Integration testing]: https://www.apollographql.com/docs/apollo-server/testing/testing/
[Ref 1]: https://git.io/Jfou6
[#3988]: #3988
[Ref 2]: https://git.io/Jfouy
abernix added a commit that referenced this pull request May 28, 2020
The `apollo-server-testing` package uses an internal Apollo Server method
called `executeOperation` (introduced in [#1909]) in order to power its
`createTestClient` functionality.  This is the testing practice which is
documented within [Integration testing] in the Apollo Server documentation.

However, it failed to introduce the same context-cloning which [takes place
in `runHttpQuery`][Ref 1], prior to arriving at the main request pipeline.

Since the context was not cloned, and we had made the expectation in [#3988]
that it was a unique context on every single request (which it was, in a
non-testing context), the Symbol we use to implement `willResolveField` was
already present [on the request pipeline][Ref 2] when running a subsequent
test via `createTestClient`!

This commit introduces the same cloning that takes place in
`buildRequestContext` within `runHttpQuery`, and adds tests to ensure the
behavior is preserved.

[Fixes #4170]: #4170
[#1909]: #1909
[Integration testing]: https://www.apollographql.com/docs/apollo-server/testing/testing/
[Ref 1]: https://git.io/Jfou6
[#3988]: #3988
[Ref 2]: https://git.io/Jfouy
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants