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

improve client tests to avoid wait patten #39

Closed
sibelius opened this issue Oct 23, 2020 · 2 comments · Fixed by #41
Closed

improve client tests to avoid wait patten #39

sibelius opened this issue Oct 23, 2020 · 2 comments · Fixed by #41
Labels
enhancement New feature or request released Has been released and published

Comments

@sibelius
Copy link
Contributor

Story

I'd like to add some tests in our GraphQL subscriptions server to make sure subscriptions are working well, my current problem is that subscribe happens after our pubsub.publish call.

example:

client.subscribe()

pubsub.publish() // this happens before `subscribe` completes

similar to the current test that uses wait(10)
https://github.com/enisdenjo/graphql-transport-ws/blob/f76ac73e9d21c80abe0118007e168e4f5d525036/src/tests/client.ts#L113

does it make sense to emit an event when the subscribe is "ready"

@sibelius
Copy link
Contributor Author

I've got working like this

const onConnectedPromise = createDeferred();

  client.on('connected', d => {
    onConnectedPromise.resolve();
  });

const disposeSubscription = client.subscribe({
    query,
  }, sink);

  await onConnectedPromise.promise;

I wait the connected event after subscribe call

@enisdenjo
Copy link
Owner

🎉 This issue has been resolved in version 1.9.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@enisdenjo enisdenjo added the released Has been released and published label Oct 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request released Has been released and published
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants