Code coverage report for src/registryUrl.js

Statements: 77.78% (21 / 27)      Branches: 50% (1 / 2)      Functions: 60% (3 / 5)      Lines: 77.78% (21 / 27)     

All files » src/ » registryUrl.js
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 41 42 43 44 451 1 1 1     1 1 1 1 1   1 1   1 1     1       1         1 1 1               1   1     1  
var check = require('check-types');
var spawn = require('child_process').spawn;
var q = require('q');
var NPM_PATH = require('./npm-path');
 
// returns a promise
function registryUrl() {
  check.verify.string(NPM_PATH, 'missing npm path string');
  var npm = spawn(NPM_PATH, ['config', 'get', 'registry']);
  var output = '';
  var errors = '';
 
  npm.stdout.setEncoding('utf-8');
  npm.stderr.setEncoding('utf-8');
 
  npm.stdout.on('data', function (data) {
    output += data;
  });
 
  npm.stderr.on('data', function (data) {
    errors += data;
  });
 
  npm.on('error', function (err) {
    console.error(err);
    errors += err.toString();
  });
 
  var deferred = q.defer();
  npm.on('exit', function (code) {
    Iif (code) {
      console.error('npm config get registry returned', code);
      console.error('errors:\n' + errors);
      deferred.reject({
        code: code,
        errors: errors
      });
    }
    deferred.resolve(output);
  });
  return deferred.promise;
}
 
module.exports = registryUrl;