meteormeteor-velocity

How to wait for the user to be logged in, in Velocity integration tests


In order to perform my integration tests, the callback from the Meteor.loginWithPassword(... has to have been executed.

If I postpone the test until the user exists, or some Session variable is defined, the tests are ignored.

This is my login function:

  Meteor.loginWithPassword(username, forge.util.encode64(aesKey), function(error) {
     if(!error) {
        Log.info("user loged in");
        Session.set("loggedIn", true);
     ...         
  })

and then in the Mocha test:

  Meteor.startup(function () {
     Tracker.autorun(function (c) {
        if (Session.get("loggedIn")) {
           c.stop();
           MochaWeb.testOnly(function () {
              Log.info("executing tests");
              describe("the KeyPair has been created", function () {
              ...

My question is: is there a way to make mocha wait for some state or do I have to mock the environment (which would defeat the integration test purpose)?

Also, on code changes, I get following error:

stream error Network error: ws://localhost:51366/websocket: connect ECONNREFUSED

thank you for your support


Solution

  • The feature request that @stubailo pointed out has now been implemented. See https://github.com/meteor/meteor/issues/3572 for more details.