"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

function _chai() {
  const data = require("chai");

  _chai = function () {
    return data;
  };

  return data;
}

function _mockery() {
  const data = _interopRequireDefault(require("mockery"));

  _mockery = function () {
    return data;
  };

  return data;
}

function _sinon() {
  const data = _interopRequireDefault(require("sinon"));

  _sinon = function () {
    return data;
  };

  return data;
}

function _npmClient() {
  const data = _interopRequireDefault(require("../npm-client"));

  _npmClient = function () {
    return data;
  };

  return data;
}

/**
 * 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()', () => {
  const execSpy = _sinon().default.spy();

  const childProcessMock = {
    exec: execSpy
  };
  const fsMock = {
    ensureDirSync: () => {
      return null;
    }
  };
  before(() => {
    _mockery().default.enable({
      warnOnReplace: false,
      warnOnUnregistered: false
    });

    _mockery().default.registerMock('child_process', childProcessMock);

    _mockery().default.registerMock('fs-extra', fsMock);
  });
  after(() => {
    _mockery().default.disable();
  });
  beforeEach(() => {
    execSpy.reset();
  });
  it('should pass the cwd argument to the option of the exec function', () => {
    _npmClient().default.install(['mock-module'], {
      cwd: '/path/to/dir'
    });

    (0, _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)', () => {
    _npmClient().default.install({
      'mock-module': '^1.1.2',
      'another-module': '3.3.2'
    });

    (0, _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()', () => {
    _npmClient().default.install(['mock-module']);

    (0, _chai().expect)(execSpy.getCall(0).args[1].cwd).to.eql(process.cwd());
  });
  it('should work if no arguments supplied', () => {
    _npmClient().default.install();

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

    (0, _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', () => {
    _npmClient().default.install(['mock-module@1.0.0', 'another-module@3.4.5']);

    (0, _chai().expect)(execSpy.getCall(0).args[0]).to.eql('npm install mock-module@1.0.0 another-module@3.4.5');
  });
});