title: How to wait for the user to be logged in, in Velocity integration tests
body: <p>In order to perform my integration tests, the callback from the <code>Meteor.loginWithPassword(...</code> has to have been executed.</p>
  
  <p>If I postpone the test until the user exists, or some <code>Session</code> variable is defined, the tests are ignored.</p>
  
  <p>This is my login function:</p>
  
  <pre><code>  Meteor.loginWithPassword(username, forge.util.encode64(aesKey), function(error) {
       if(!error) {
          Log.info("user loged in");
          Session.set("loggedIn", true);
       ...         
    })
  </code></pre>
  
  <p>and then in the Mocha test:</p>
  
  <pre><code>  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 () {
                ...
  </code></pre>
  
  <p>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)?</p>
  
  <p>Also, on code changes, I get following error:</p>
  
  <pre><code>stream error Network error: ws://localhost:51366/websocket: connect ECONNREFUSED
  </code></pre>
  
  <p>thank you for your support</p>