Question

my configuration is an intern test environment launched by grunt and the following intern config (partly):

proxyPort: 9000,
proxyUrl: 'http://<my-ip>:9000',

The problem is the hardcoded my-ip. Selenium grid and nodes are running on different machines / respective ips and the config file for intern is to be checked in together with all the build and test environment.

If I leave proxyUrl at localhost the selenium nodes can't load the data for the intern tests.

Thus my-ip will be different for all developers testing. I really don't want everybody to enter the own ip into the intern config and accidently check in config, neither to check in a template file for everybody to change.

Don't understand me wrong. The setup is working just fine but the local ip has to be entered hardcoded which I personally see as smell.

Maybe its easy to parametrize the proxyURL but I just can't find any resource for it :(

Regards,

Flowkap

Was it helpful?

Solution 2

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).

OTHER TIPS

As of Intern 1.6, you can retrieve additional command-line arguments from intern.args:

// in tests/config.js
define([ 'intern' ], function (intern) {
  return {
    proxyUrl: intern.args.proxyUrl,

    // ... additional configuration ...
  };
});
$ intern-runner config=tests/config proxyUrl=http://www.example.com:1234/
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top