I have a karma.conf.js config, and when I configure it I need an ip address of the current gateway.
I have found this solution to get the ip address:
var network = require('network');
var gatewayIp;
network.get_gateway_ip(function(err, ip) {
console.log(err || ip); // err may be 'No active network interface found.'
gatewayIp = ip;
});
config.set({
....
hostname: gatewayIp
....
})
The problem is that I want to set the result of get_gateway_ip in config.set({ .... hostname: gatewayIp ... }) and the gatewayIp is not assigned when it run into config.set function call.
I cannot put the config.set() to the async result because it is not working (test are already running when the async result arrives).
How can I wait for the result of the get_gateway_ip?
I have seen this solution (How to return the response from an asynchronous call), but it not works becasue I cannot make karma's configuration to await.
Karma configuration:
module.exports = function(config) {
...
config.set({})
};
The function(config) cannot be async, because when I make it async it ignores the configuration:
module.exports = async function(config) {
...
config.set({}) // ignored
...
};