I found out about how to easily obtain the current LAN ip by using os.networkInterfaces() like described in nodejs documentation http://nodejs.org/api/os.html#os_os_networkinterfaces
So if needed a dynamically obtained localLan ip automatically for the static proxyUrl config flag of intern.js we just add the corresponding code within the define of e.g. your Gruntfile as Grunt itself is being executed within the nodejs environment:
/* jshint node: true*/
"use strict";
module.exports = function (grunt) {
require("time-grunt")(grunt);
var os = require('os');
var interfaces = os.networkInterfaces(),
localLanIp = null,
setLocalLanIp = function (deviceDetails) {
if (deviceDetails.family === 'IPv4' && !deviceDetails.internal) {
localLanIp = deviceDetails.address;
}
return localLanIp !== null;
};
for (var device in interfaces) {
//just check devices containing LAN or eth
if (device.indexOf("LAN") > -1 || device.indexOf("eth") > -1) {
//as we can'T break a forEach on arrays we use some and break on return true.
interfaces[device].some(setLocalLanIp);
//break outer for as loaclIp is found.
if (localLanIp !== null) {
break;
}
}
}
//if no ip found default to localhost anyway.
if (localLanIp === null) {
localLanIp = "localhost";
}
grunt.initConfig({
intern: {
remote: {
options: {
runType: "runner",
config: "tests/intern.js",
reporters: [ "console" ],
suites: [ "tests/module" ],
proxyPort: 9000,
proxyUrl: 'http://' + localLanIp + ':' + 9000
}
}
}
});
grunt.loadNpmTasks("intern");
grunt.registerTask("default", ["intern"]);
};
In my opinion defaulting to a local LAN ip would have been a good idea, but this is working great if you can't rely on localhost or 0.0.0.0 addresses but do not want to manually edit any config at all (or can't due to any reason).