[SOLVED] How to wait for Meteor to be ready before running tests?

I’m trying to run some code in Meteor.startup, before running my test suite. But my test suite starts running before the startup callback is called.

How can I force Meteor to wait for it?

If you are performing a client side test you can use the method Meteor.status(), it will return an object indicates the status so you can wait until it is {connected:true}, at this stage the server is totally ready

1 Like

Well, it’s specifically on the server :confused:

Well, this might do the trick:

describe('Init', () => {
  before(done => {
    Meteor.startup(done);
  });

  it('Has Initiated', () => {
    console.log('Server is ready')
  });
});

You just need to make sure this test suite runs first

7 Likes

@florianbienefelt Very cool.

I suggest to use root level mocha hooks.
Then before block will run before all tests.

// init.app-test.js

/* eslint-env mocha */
import { Meteor } from 'meteor/meteor';

before((done) => {
    // wait until all server modules are loaded (in Meteor.startup)
    Meteor.startup(done);
});

2 Likes