meteor / todos

The example app "Todos", written following the Meteor Guide
Other
535 stars 367 forks source link

publication-collector #120

Closed msio closed 7 years ago

msio commented 8 years ago

Hi, I tried publication-collector package from todos app and unfortunately I got this error

test

I test my publication in publications.test.js it looks like that my publication can not be found Thanks for any help. Is there any other way how I can test publications on server ? Best Regards Michal

hwillson commented 8 years ago

Hi @msio777 - are you importing your publication file in your test file? For example, if you're calling your Meteor.publish() in a publications.js file, make sure you:

import 'some/path/publications.js';

in your test file.

msio commented 8 years ago

thanks a lot man you were right with import :) but unfortunately

describe('lists.public', function () {
    it('sends all public lists', function (done) {
        // Allows us to look at the output of a publication without
        // needing a client connection
        const collector = new PublicationCollector();
        collector.collect('interests', (collections) => {
            console.log(collections);
            //chai.assert.equal(collections.Interests.length, 3);
            done();
        });
    });
});

console.log(collections) is {} and I imported all related js files

hwillson commented 8 years ago

Are you using the factory package from the todos app? If so define and create your test data before calling your test with the PublicationCollector in it. By doing this you're manipulating your test collection, which ends up being caught by the PublicationCollector, so it then knows to publish the captured collection data. So something like:

...
  before(function () {
    Factory.define('product', products, {
      productId: faker.random.number(),
      productName: faker.random.words(),
      productUrl: faker.internet.url(),
      productImage: faker.image.imageUrl(),
      variationId: faker.random.number(),
      variationName: faker.random.words(),
      status: faker.random.word(),
    });
    _.times(3, () => {
      Factory.create('product');
    });
  });
...
  it('should publish all products if logged in', function (done) {
    const collector = new PublicationCollector({ userId });
    collector.collect('products.all', (collections) => {
      chai.expect(collections.products.length).to.equal(3);
      done();
    });
  });
...

I'm planning on publishing a publication-collector package soon, that will have expanded docs helping explain all of this.

msio commented 8 years ago

Thanks a lot I finally unterstood the concept but still this kind of error

test2

this is my code

describe('publications', function () {

    before(function () {
         Factory.define('interest', Interests,{
            name: 'Dance'
         });

         Factory.create('interest');
    });

    it('all interests', function (done) {
        const collector = new PublicationCollector();
        collector.collect('interests', (collections) => {
            console.log(collections);
            done();
        });
    });
});

I am using right know factory from todo app

enigma87 commented 8 years ago

I have this exact issue, but its intermittent. So I thought collector.collect is being asynchronous, and therefore I wrapped it with a promise, even then I get {} from publication-collector.

hwillson commented 7 years ago

If this is still an issue, please open a new issue with this packages new home.