All files / lib eshost.js

78.95% Statements 15/19
25% Branches 1/4
66.67% Functions 2/3
77.78% Lines 14/18

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40            2x 2x 2x 375x   2x 353x 353x   353x 353x 353x 353x                   2x 2x   2x                
'use strict';
 
const {
  getDependencies,
  hasModuleSpecifier,
  rawSource
} = require('./dependencies');
const writeSources = require('./write-sources');
const {supportedHosts, supportedHostsMap} = require('./supported-hosts');
const normalizeHostForVU = hostType => supportedHostsMap[hostType] || hostType;
 
exports.createAgent = function(type, options) {
  const hostType = normalizeHostForVU(type);
  const reqPath = `./agents/${hostType}.js`;
 
  try {
    const Agent = require(reqPath);
    const a = new Agent(options);
    return a.initialize();
  } catch (error) {
    if (error.message.indexOf(`Cannot find module '${reqPath}'`) > -1) {
      throw new Error(`Agent for '${hostType}' not supported. Supported host type names are '${supportedHosts.join(', ')}'`);
    } else {
      throw error;
    }
  }
};
 
exports.supportedHosts = supportedHosts;
exports.normalizeHostForVU = normalizeHostForVU;
 
exports.source = {
  getDependencies,
  hasModuleSpecifier,
  writeSources,
  getSource(fileName) {
    return rawSource.get(fileName);
  }
};