Meteor-Community-Packages / meteor-publication-collector

Test a Meteor publication by collecting its output.
https://atmospherejs.com/johanbrook/publication-collector
MIT License
33 stars 20 forks source link

"ready" event sent twice for publications using the low-level added/changed/removed interface #16

Closed nkahnfr closed 7 years ago

nkahnfr commented 7 years ago

Hi,

First thanks for your package, it's really useful for testing Meteor publications.

With latest version I am getting following errors while testing my publications: Error: done() called multiple times

Here the "done" function is the Mocha callback used for asynchronous code like the one you use in your usage example.

The publications I am testing are using the low-level added/changed/removed interface which means I am also calling the "ready" method once the initial record set is complete. The problem in that case is that you're also calling "this.ready()" at the end of "collect" method and thus the callback passed to the "collect" method is called twice since it's part of the "ready" listener you're defining before calling the publication function.

That behavior was introduced in v1.0.5 since you're now adding the "ready" listener before calling the publication function.

I could be wrong but my recommendation would be to define an empty "ready" method on PublicationCollector class (like the stop() one) and use a different name for your custom ready event.

Let me know if that's not clear enough. Thanks for your help.

-Nicolas

johanbrook commented 7 years ago

Hey there!

Thanks for reporting in. I see how you mean. I'll try to reproduce it as a failing test case.

ShinyLeee commented 7 years ago

@johanbrook Maybe you can see this repro. But run npm run test-d

11

nkahnfr commented 7 years ago

@johanbrook I created pull request #18 to fix that issue. Hope it helps.

johanbrook commented 7 years ago

Thanks! Will check it out.

johanbrook commented 7 years ago

Published as 1.0.6.