Skip to content

Test Utils for Apollo-server#1909

Merged
abernix merged 17 commits into
masterfrom
jake-testing
Nov 5, 2018
Merged

Test Utils for Apollo-server#1909
abernix merged 17 commits into
masterfrom
jake-testing

Conversation

@JakeDawkins

@JakeDawkins JakeDawkins commented Nov 1, 2018

Copy link
Copy Markdown
Contributor

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

@abernix abernix left a comment

Copy link
Copy Markdown
Member

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!

Comment thread package-lock.json Outdated
Comment thread packages/apollo-server-core/src/ApolloServer.ts Outdated
Comment thread packages/apollo-server-testing/src/createTestClient.ts Outdated
Comment thread packages/apollo-server-testing/src/createTestClient.ts Outdated
Comment thread packages/apollo-server-testing/src/createTestClient.ts Outdated
Comment thread packages/apollo-server-testing/src/index.ts Outdated
Comment thread packages/apollo-server-testing/src/index.ts Outdated
Comment thread packages/apollo-server-testing/src/createTestClient.ts Outdated
Comment thread packages/apollo-server-testing/package.json
@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.

3 participants