I am using grunt connect ("grunt-contrib-connect": "0.11.2"
) in conjunction with grunt jasmine ("grunt-contrib-jasmine": "^1.1.0"
). The connect config was previously hardcoding the port number and the jasmine config was also configured to use the same port number in the host
config option.
I now want to enable the useAvailablePort
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?
Here are the relevant sections of my grunt init config block:
connect: {
test: {
options: {
keepalive: false,
hostname: 'localhost',
port: 1234,
base: ['.']
}
}
}
jasmine: {
js: {
src: ...,
options: {
keepRunner: true,
summary: true,
host: 'http://localhost:1234/',
specs: 'src/test/js/**/*Spec.js',
vendor: ...
}
}
}
I have created a grunt test task using:
grunt.registerTask('test', ['connect', 'jasmine:js']);
So what would be the best practice way of capturing the port from connect
and setting the host in jasmine:js
?
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):
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');
});