Meteor-Community-Packages/meteor-publication-collector

Error when trying to use stubbed collections for publication tests

ebbe-brandstrup opened this issue · 3 comments

Hi,

I'm trying to use the hwillson:stub-collections package for publication tests. I would like to use stubbed collections to have the tests run quicker.

The stacktrace of the error I get is:

Can't publish a cursor from a collection without a name. at [object Object].LocalCollection.Cursor._publishCursor (packages/minimongo.js:265:11) at packages/johanbrook:publication-collector/publication-collector.js:49:20 at Array.map (native) at PublicationCollector.collect (packages/johanbrook:publication-collector/publication-collector.js:44:47)

The error occurs because the hwillson:stub-collections package creates an in-memory (minimongo) collection to replace the real collection and that is achieved by creating a new Meteor collection without a name (null).

I realise this problem isn't because of your package, but I am hoping you have some insight to share?

Thanks!

Hey! Thanks for reporting in.

Often, there have been problems with other collection and publication packages, since they do some custom trickery which developers rely on in their business logic. But then at testing them publications with this package, things break, since the "publications" for this package aren't extended with the custom behaviour relied on.

The error is thrown from the _publishCursor method on a Cursor. It'll observe a cursor and publish its results. The stubbed collections package is creating a non-persistent collection (without a name).

And thus, it seems that the _publishCursor method for Minimongo's collection class will throw if it doesn't have a name property.

@hwillson might be able to work around it by setting a name on the in-memory collection in the stubbed package. Hope that helped.

Thanks a lot for the input @johanbrook! I have also opened an issue about this on @hwillson's repo.