'use strict';

var _chai;

function _load_chai() {
  return _chai = require('chai');
}

var _mockery;

function _load_mockery() {
  return _mockery = _interopRequireDefault(require('mockery'));
}

var _sinon;

function _load_sinon() {
  return _sinon = _interopRequireDefault(require('sinon'));
}

var _npmClient;

function _load_npmClient() {
  return _npmClient = _interopRequireDefault(require('../../src/npm-client'));
}

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

/**
 * Skipped the npm client tests because we changed the implementation of the npm install to stream (child process spawn)
 * we should fix this to work with spawn
 */
describe.skip('npmClient.install()', function () {
  var execSpy = (_sinon || _load_sinon()).default.spy();
  var childProcessMock = {
    exec: execSpy
  };

  var fsMock = {
    ensureDirSync: function ensureDirSync() {
      return null;
    }
  };

  before(function () {
    (_mockery || _load_mockery()).default.enable({
      warnOnReplace: false,
      warnOnUnregistered: false
    });

    (_mockery || _load_mockery()).default.registerMock('child_process', childProcessMock);
    (_mockery || _load_mockery()).default.registerMock('fs-extra', fsMock);
  });

  after(function () {
    (_mockery || _load_mockery()).default.disable();
  });

  beforeEach(function () {
    execSpy.reset();
  });

  it('should pass the cwd argument to the option of the exec function', function () {
    (_npmClient || _load_npmClient()).default.install(['mock-module'], { cwd: '/path/to/dir' });
    (0, (_chai || _load_chai()).expect)(execSpy.getCall(0).args[1].cwd).to.eql('/path/to/dir');
  });

  it('should except an object of dependencies (from package.json and install the dependencies)', function () {
    (_npmClient || _load_npmClient()).default.install({ 'mock-module': '^1.1.2', 'another-module': '3.3.2' });
    (0, (_chai || _load_chai()).expect)(execSpy.getCall(0).args[0]).to.eql('npm install mock-module@^1.1.2 another-module@3.3.2');
  });

  it('if no cwd was passed it should be process.cwd()', function () {
    (_npmClient || _load_npmClient()).default.install(['mock-module']);
    (0, (_chai || _load_chai()).expect)(execSpy.getCall(0).args[1].cwd).to.eql(process.cwd());
  });

  it('should work if no arguments supplied', function () {
    (_npmClient || _load_npmClient()).default.install();
    (0, (_chai || _load_chai()).expect)(execSpy.getCall(0).args[0]).to.eql('npm install');
  });

  it('should work if the first argument is a string', function () {
    (_npmClient || _load_npmClient()).default.install('mock-module');
    (0, (_chai || _load_chai()).expect)(execSpy.getCall(0).args[0]).to.eql('npm install mock-module');
  });

  it('should work if the first argument is an array or strings', function () {
    (_npmClient || _load_npmClient()).default.install(['mock-module@1.0.0', 'another-module@3.4.5']);
    (0, (_chai || _load_chai()).expect)(execSpy.getCall(0).args[0]).to.eql('npm install mock-module@1.0.0 another-module@3.4.5');
  });
});