title: How to communicate port from grunt connect to grunt jasmine task
body: <p>I am using grunt connect (<code>"grunt-contrib-connect": "0.11.2"</code>) in conjunction with grunt jasmine (<code>"grunt-contrib-jasmine": "^1.1.0"</code>). The connect config was previously hardcoding the port number and the jasmine config was also configured to use the same port number in the <code>host</code> config option.</p>
  
  <p>I now want to enable the <code>useAvailablePort</code> option in connect in order to resolve an issue with concurrent builds using the same port. However I am struggling to understand how to correctly communicate the port number from connect to jasmine?</p>
  
  <p>Here are the relevant sections of my grunt init config block:</p>
  
  <pre class="lang-js prettyprint-override"><code>connect: {
    test: {
      options: {
        keepalive: false,
        hostname: 'localhost',
        port: 1234,
        base: ['.']
      }
    }
  }
  </code></pre>
  
  <pre class="lang-js prettyprint-override"><code>jasmine: {
    js: {
      src: ...,
      options: {
        keepRunner: true,
        summary: true,
        host: 'http://localhost:1234/',
        specs: 'src/test/js/**/*Spec.js',
        vendor: ...
      }
    }
  }
  </code></pre>
  
  <p>I have created a grunt test task using:</p>
  
  <pre class="lang-js prettyprint-override"><code>grunt.registerTask('test', ['connect', 'jasmine:js']);
  </code></pre>
  
  <p>So what would be the best practice way of capturing the port from <code>connect</code> and setting the host in <code>jasmine:js</code>?</p>
  
  <p>I have been trying to change the test task as follows, but with no joy (also not sure if this would be the correct way to do it):</p>
  
  <pre class="lang-js prettyprint-override"><code>grunt.registerTask('test', 'Run jasmine unit tests', function () {
    grunt.event.once('connect.test.listening', function(host, port) {
      var jasmineHost = 'http://' + host + ':' + port;
      grunt.log.writeln('Running jasmine tests from: ' + jasmineHost );
      grunt.config.set('jasmine:js:options:host', jasmineHost );
      grunt.task.run('jasmine:js');
    });
    grunt.task.run('connect:test');
  });
  </code></pre>