'use strict';

var _regenerator;

function _load_regenerator() {
  return _regenerator = _interopRequireDefault(require('babel-runtime/regenerator'));
}

var _bluebird;

function _load_bluebird() {
  return _bluebird = require('bluebird');
}

var _path;

function _load_path() {
  return _path = _interopRequireDefault(require('path'));
}

var _chai;

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

var _dependencyFileLinkGenerator;

function _load_dependencyFileLinkGenerator() {
  return _dependencyFileLinkGenerator = _interopRequireDefault(require('./dependency-file-link-generator'));
}

var _consumerComponent;

function _load_consumerComponent() {
  return _consumerComponent = _interopRequireDefault(require('../consumer/component/consumer-component'));
}

var _barFoo;

function _load_barFoo() {
  return _barFoo = _interopRequireDefault(require('../../fixtures/consumer-components/plain-javascript/bar-foo.json'));
}

var _utilsIsString;

function _load_utilsIsString() {
  return _utilsIsString = _interopRequireDefault(require('../../fixtures/consumer-components/plain-javascript/utils-is-string.json'));
}

var _barFoo2;

function _load_barFoo2() {
  return _barFoo2 = _interopRequireDefault(require('../../fixtures/consumer-components/es6/bar-foo.json'));
}

var _utilsIsString2;

function _load_utilsIsString2() {
  return _utilsIsString2 = _interopRequireDefault(require('../../fixtures/consumer-components/es6/utils-is-string.json'));
}

var _barFoo3;

function _load_barFoo3() {
  return _barFoo3 = _interopRequireDefault(require('../../fixtures/consumer-components/custom-resolved-modules/bar-foo.json'));
}

var _utilsIsString3;

function _load_utilsIsString3() {
  return _utilsIsString3 = _interopRequireDefault(require('../../fixtures/consumer-components/custom-resolved-modules/utils-is-string.json'));
}

var _path2;

function _load_path2() {
  return _path2 = require('../utils/path');
}

var _globalConfig;

function _load_globalConfig() {
  return _globalConfig = _interopRequireWildcard(require('../api/consumer/lib/global-config'));
}

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }

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

var mockBitMap = function mockBitMap() {
  return {
    getComponent: function getComponent() {
      return {
        rootDir: '.dependencies/utils/is-string/remote-scope/0.0.1',
        getRootDir() {
          return this.rootDir;
        }
      };
    }
  };
};

var mockConsumer = function mockConsumer() {
  var distIsInsideTheComponent = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;

  var consumer = {
    bitMap: mockBitMap(),
    getPath: function getPath() {
      return '/root';
    },
    shouldDistsBeInsideTheComponent: function shouldDistsBeInsideTheComponent() {
      return true;
    },
    toAbsolutePath: function toAbsolutePath(str) {
      return `/root/${str}`;
    }
  };
  if (!distIsInsideTheComponent) {
    consumer.config = { distEntry: 'src', distTarget: 'dist' };
    consumer.shouldDistsBeInsideTheComponent = function () {
      return false;
    };
  }

  return consumer;
};

var mockGetSync = function mockGetSync() {
  (_globalConfig || _load_globalConfig()).getSync = function () {
    return '@bit';
  };
};

describe('DependencyFileLinkGenerator', function () {
  before(function () {
    mockGetSync();
  });
  describe('generate()', (0, (_bluebird || _load_bluebird()).coroutine)( /*#__PURE__*/(_regenerator || _load_regenerator()).default.mark(function _callee6() {
    return (_regenerator || _load_regenerator()).default.wrap(function _callee6$(_context6) {
      while (1) {
        switch (_context6.prev = _context6.next) {
          case 0:
            describe('using plain javascript', function () {
              var dependencyFileLinkGenerator = void 0;
              var linkResult = void 0;
              before((0, (_bluebird || _load_bluebird()).coroutine)( /*#__PURE__*/(_regenerator || _load_regenerator()).default.mark(function _callee() {
                var component, dependencyComponent, linkResults;
                return (_regenerator || _load_regenerator()).default.wrap(function _callee$(_context) {
                  while (1) {
                    switch (_context.prev = _context.next) {
                      case 0:
                        _context.next = 2;
                        return (_consumerComponent || _load_consumerComponent()).default.fromString(JSON.stringify((_barFoo || _load_barFoo()).default));

                      case 2:
                        component = _context.sent;
                        component.componentMap = {
                          rootDir: 'components/bar/foo',

                          getRootDir() {
                            return this.rootDir;
                          }
                        };
                        _context.next = 6;
                        return (_consumerComponent || _load_consumerComponent()).default.fromString(JSON.stringify((_utilsIsString || _load_utilsIsString()).default));

                      case 6:
                        dependencyComponent = _context.sent;

                        dependencyFileLinkGenerator = new (_dependencyFileLinkGenerator || _load_dependencyFileLinkGenerator()).default({
                          consumer: mockConsumer(),
                          bitMap: mockBitMap(),
                          component,
                          relativePath: component.dependencies.get()[0].relativePaths[0],
                          dependencyComponent,
                          createNpmLinkFiles: false,
                          targetDir: ''
                        });
                        linkResults = dependencyFileLinkGenerator.generate();

                        linkResult = linkResults[0];

                      case 10:
                      case 'end':
                        return _context.stop();
                    }
                  }
                }, _callee, undefined);
              })));
              it('should generate linkPath that consist of component rootDir + sourceRelativePath', function () {
                (0, (_chai || _load_chai()).expect)(linkResult.linkPath).to.equal((_path || _load_path()).default.normalize('components/bar/foo/utils/is-string.js'));
              });
              it('should generate linkContent that points to dependency rootDir + destinationRelativePath', function () {
                (0, (_chai || _load_chai()).expect)(linkResult.linkContent).to.have.string('.dependencies/utils/is-string/remote-scope/0.0.1/utils/is-string');
              });
              it('should generate linkContent that is relative to the linkPath', function () {
                var absoluteDest = 'components/.dependencies/utils/is-string/remote-scope/0.0.1/utils/is-string';
                var relativeDest = (0, (_path2 || _load_path2()).pathRelativeLinux)(linkResult.linkPath, absoluteDest);
                (0, (_chai || _load_chai()).expect)(linkResult.linkContent).to.have.string(`require('${relativeDest}')`);
              });
              it('should set isEs6 to false as it does not have ImportSpecifiers', function () {
                (0, (_chai || _load_chai()).expect)(linkResult.isEs6).to.be.false;
              });
              describe('when isLinkToPackage is set to true', function () {
                before(function () {
                  dependencyFileLinkGenerator.isLinkToPackage = true;
                  var linkResults = dependencyFileLinkGenerator.generate();
                  linkResult = linkResults[0];
                });
                it('should generate linkContent that points to the package name instead of a file', function () {
                  (0, (_chai || _load_chai()).expect)(linkResult.linkContent).to.equal("module.exports = require('@bit/remote-scope.utils.is-string');");
                });
                it('should generate linkPath that consist of component rootDir + sourceRelativePath', function () {
                  (0, (_chai || _load_chai()).expect)(linkResult.linkPath).to.equal((_path || _load_path()).default.normalize('components/bar/foo/utils/is-string.js'));
                });
                it('should set isEs6 to false as it does not have ImportSpecifiers', function () {
                  (0, (_chai || _load_chai()).expect)(linkResult.isEs6).to.be.false;
                });
              });
            });
            describe('using ES6', function () {
              describe('when dist is inside the component dir', function () {
                var dependencyFileLinkGenerator = void 0;
                var linkResults = void 0;
                before((0, (_bluebird || _load_bluebird()).coroutine)( /*#__PURE__*/(_regenerator || _load_regenerator()).default.mark(function _callee2() {
                  var component, dependencyComponent;
                  return (_regenerator || _load_regenerator()).default.wrap(function _callee2$(_context2) {
                    while (1) {
                      switch (_context2.prev = _context2.next) {
                        case 0:
                          _context2.next = 2;
                          return (_consumerComponent || _load_consumerComponent()).default.fromString(JSON.stringify((_barFoo2 || _load_barFoo2()).default));

                        case 2:
                          component = _context2.sent;
                          component.componentMap = {
                            rootDir: 'components/bar/foo',

                            getRootDir() {
                              return this.rootDir;
                            }
                          };
                          _context2.next = 6;
                          return (_consumerComponent || _load_consumerComponent()).default.fromString(JSON.stringify((_utilsIsString2 || _load_utilsIsString2()).default));

                        case 6:
                          dependencyComponent = _context2.sent;

                          dependencyFileLinkGenerator = new (_dependencyFileLinkGenerator || _load_dependencyFileLinkGenerator()).default({
                            consumer: mockConsumer(),
                            bitMap: mockBitMap(),
                            component,
                            relativePath: component.dependencies.get()[0].relativePaths[0],
                            dependencyComponent,
                            createNpmLinkFiles: false,
                            targetDir: ''
                          });
                          linkResults = dependencyFileLinkGenerator.generate();

                        case 9:
                        case 'end':
                          return _context2.stop();
                      }
                    }
                  }, _callee2, undefined);
                })));
                it('should generate two link files, one for the source and one for the dist', function () {
                  (0, (_chai || _load_chai()).expect)(linkResults).to.have.lengthOf(2);
                });
                describe('link file of the source', function () {
                  var linkResult = void 0;
                  before(function () {
                    linkResult = linkResults[0];
                  });
                  it('should generate linkPath that consist of component rootDir + sourceRelativePath', function () {
                    (0, (_chai || _load_chai()).expect)(linkResult.linkPath).to.equal((_path || _load_path()).default.normalize('components/bar/foo/utils/is-string.js'));
                  });
                  it('should generate linkContent that points to dependency rootDir + destinationRelativePath', function () {
                    (0, (_chai || _load_chai()).expect)(linkResult.linkContent).to.have.string('.dependencies/utils/is-string/remote-scope/0.0.1/utils/is-string');
                  });
                  it('should generate linkContent that is relative to the linkPath', function () {
                    var absoluteDest = 'components/.dependencies/utils/is-string/remote-scope/0.0.1/utils/is-string';
                    var relativeDest = (0, (_path2 || _load_path2()).pathRelativeLinux)(linkResult.linkPath, absoluteDest);
                    (0, (_chai || _load_chai()).expect)(linkResult.linkContent).to.have.string(`require('${relativeDest}')`);
                  });
                  it('should set isEs6 to true as it has ImportSpecifiers', function () {
                    (0, (_chai || _load_chai()).expect)(linkResult.isEs6).to.be.true;
                  });
                });
                describe('link file of the dist', function () {
                  var linkResult = void 0;
                  before(function () {
                    linkResult = linkResults[1];
                  });
                  it('should generate linkPath that consist of component rootDir + dist + sourceRelativePath', function () {
                    (0, (_chai || _load_chai()).expect)(linkResult.linkPath).to.equal((_path || _load_path()).default.normalize('components/bar/foo/dist/utils/is-string.js'));
                  });
                  it('should generate linkContent that points to dependency rootDir + dist + destinationRelativePath', function () {
                    (0, (_chai || _load_chai()).expect)(linkResult.linkContent).to.have.string('.dependencies/utils/is-string/remote-scope/0.0.1/dist/utils/is-string');
                  });
                  it('should generate linkContent that is relative to the linkPath', function () {
                    var absoluteDest = 'components/.dependencies/utils/is-string/remote-scope/0.0.1/dist/utils/is-string';
                    var relativeDest = (0, (_path2 || _load_path2()).pathRelativeLinux)(linkResult.linkPath, absoluteDest);
                    (0, (_chai || _load_chai()).expect)(linkResult.linkContent).to.have.string(`require('${relativeDest}')`);
                  });
                  it('should set isEs6 to true as it has ImportSpecifiers', function () {
                    (0, (_chai || _load_chai()).expect)(linkResult.isEs6).to.be.true;
                  });
                });
                describe('when createNpmLinkFiles is set to true', function () {
                  before(function () {
                    dependencyFileLinkGenerator.isLinkToPackage = true;
                    linkResults = dependencyFileLinkGenerator.generate();
                  });
                  it('should generate two link files, one for the source and one for the dist', function () {
                    (0, (_chai || _load_chai()).expect)(linkResults).to.have.lengthOf(2);
                  });
                  describe('link file of the source', function () {
                    var linkResult = void 0;
                    before(function () {
                      linkResult = linkResults[0];
                    });
                    it('should generate linkContent that points to the package name instead of a file', function () {
                      (0, (_chai || _load_chai()).expect)(linkResult.linkContent).to.equal("module.exports = require('@bit/remote-scope.utils.is-string');");
                    });
                    it('should generate linkPath that consist of component rootDir + sourceRelativePath', function () {
                      (0, (_chai || _load_chai()).expect)(linkResult.linkPath).to.equal((_path || _load_path()).default.normalize('components/bar/foo/utils/is-string.js'));
                    });
                  });
                  describe('link file of the dist', function () {
                    var linkResult = void 0;
                    before(function () {
                      linkResult = linkResults[1];
                    });
                    it('should generate linkContent that points to the package name instead of a file', function () {
                      (0, (_chai || _load_chai()).expect)(linkResult.linkContent).to.equal("module.exports = require('@bit/remote-scope.utils.is-string');");
                    });
                    it('should generate linkPath that consist of component rootDir + dist + sourceRelativePath', function () {
                      (0, (_chai || _load_chai()).expect)(linkResult.linkPath).to.equal((_path || _load_path()).default.normalize('components/bar/foo/dist/utils/is-string.js'));
                    });
                  });
                });
              });
              describe('when dist is outside the component dir', function () {
                var dependencyFileLinkGenerator = void 0;
                var linkResults = void 0;
                before((0, (_bluebird || _load_bluebird()).coroutine)( /*#__PURE__*/(_regenerator || _load_regenerator()).default.mark(function _callee3() {
                  var component, dependencyComponent;
                  return (_regenerator || _load_regenerator()).default.wrap(function _callee3$(_context3) {
                    while (1) {
                      switch (_context3.prev = _context3.next) {
                        case 0:
                          _context3.next = 2;
                          return (_consumerComponent || _load_consumerComponent()).default.fromString(JSON.stringify((_barFoo2 || _load_barFoo2()).default));

                        case 2:
                          component = _context3.sent;
                          component.componentMap = {
                            rootDir: 'components/bar/foo',

                            getRootDir() {
                              return this.rootDir;
                            }
                          };
                          _context3.next = 6;
                          return (_consumerComponent || _load_consumerComponent()).default.fromString(JSON.stringify((_utilsIsString2 || _load_utilsIsString2()).default));

                        case 6:
                          dependencyComponent = _context3.sent;

                          dependencyFileLinkGenerator = new (_dependencyFileLinkGenerator || _load_dependencyFileLinkGenerator()).default({
                            consumer: mockConsumer(false),
                            bitMap: mockBitMap(),
                            component,
                            relativePath: component.dependencies.get()[0].relativePaths[0],
                            dependencyComponent,
                            createNpmLinkFiles: false,
                            targetDir: ''
                          });
                          linkResults = dependencyFileLinkGenerator.generate();

                        case 9:
                        case 'end':
                          return _context3.stop();
                      }
                    }
                  }, _callee3, undefined);
                })));
                it('should generate two link files, one for the source and one for the dist', function () {
                  (0, (_chai || _load_chai()).expect)(linkResults).to.have.lengthOf(2);
                });
                describe('link file of the source', function () {
                  var linkResult = void 0;
                  before(function () {
                    linkResult = linkResults[0];
                  });
                  it('should generate linkPath that consist of component rootDir + sourceRelativePath', function () {
                    (0, (_chai || _load_chai()).expect)(linkResult.linkPath).to.equal((_path || _load_path()).default.normalize('components/bar/foo/utils/is-string.js'));
                  });
                  it('should generate linkContent that points to dependency rootDir + destinationRelativePath', function () {
                    (0, (_chai || _load_chai()).expect)(linkResult.linkContent).to.have.string('.dependencies/utils/is-string/remote-scope/0.0.1/utils/is-string');
                  });
                  it('should generate linkContent that is relative to the linkPath', function () {
                    var absoluteDest = 'components/.dependencies/utils/is-string/remote-scope/0.0.1/utils/is-string';
                    var relativeDest = (0, (_path2 || _load_path2()).pathRelativeLinux)(linkResult.linkPath, absoluteDest);
                    (0, (_chai || _load_chai()).expect)(linkResult.linkContent).to.have.string(`require('${relativeDest}')`);
                  });
                  it('should set isEs6 to true as it has ImportSpecifiers', function () {
                    (0, (_chai || _load_chai()).expect)(linkResult.isEs6).to.be.true;
                  });
                });
                describe('link file of the dist', function () {
                  var linkResult = void 0;
                  before(function () {
                    linkResult = linkResults[1];
                  });
                  it('should generate linkPath that consist of dist + component rootDir + sourceRelativePath', function () {
                    (0, (_chai || _load_chai()).expect)(linkResult.linkPath).to.equal((_path || _load_path()).default.normalize('dist/components/bar/foo/utils/is-string.js'));
                  });
                  it('should generate linkContent that points to dependency rootDir + destinationRelativePath (the dist should not be there as it is already inside dist)', function () {
                    (0, (_chai || _load_chai()).expect)(linkResult.linkContent).to.have.string('.dependencies/utils/is-string/remote-scope/0.0.1/utils/is-string');
                  });
                  it('should generate linkContent that is relative to the linkPath', function () {
                    var absoluteDest = 'dist/components/.dependencies/utils/is-string/remote-scope/0.0.1/utils/is-string';
                    var relativeDest = (0, (_path2 || _load_path2()).pathRelativeLinux)(linkResult.linkPath, absoluteDest);
                    (0, (_chai || _load_chai()).expect)(linkResult.linkContent).to.have.string(`require('${relativeDest}')`);
                  });
                  it('should set isEs6 to true as it has ImportSpecifiers', function () {
                    (0, (_chai || _load_chai()).expect)(linkResult.isEs6).to.be.true;
                  });
                });
                describe('when isLinkToPackage is set to true', function () {
                  before(function () {
                    dependencyFileLinkGenerator.isLinkToPackage = true;
                    linkResults = dependencyFileLinkGenerator.generate();
                  });
                  it('should generate two link files, one for the source and one for the dist', function () {
                    (0, (_chai || _load_chai()).expect)(linkResults).to.have.lengthOf(2);
                  });
                  describe('link file of the source', function () {
                    var linkResult = void 0;
                    before(function () {
                      linkResult = linkResults[0];
                    });
                    it('should generate linkContent that points to the package name instead of a file', function () {
                      (0, (_chai || _load_chai()).expect)(linkResult.linkContent).to.equal("module.exports = require('@bit/remote-scope.utils.is-string');");
                    });
                    it('should generate linkPath that consist of component rootDir + sourceRelativePath', function () {
                      (0, (_chai || _load_chai()).expect)(linkResult.linkPath).to.equal((_path || _load_path()).default.normalize('components/bar/foo/utils/is-string.js'));
                    });
                  });
                  describe('link file of the dist', function () {
                    var linkResult = void 0;
                    before(function () {
                      linkResult = linkResults[1];
                    });
                    it('should generate linkContent that points to the package name instead of a file', function () {
                      (0, (_chai || _load_chai()).expect)(linkResult.linkContent).to.equal("module.exports = require('@bit/remote-scope.utils.is-string');");
                    });
                    it('should generate linkPath that consist of dist + component rootDir + sourceRelativePath', function () {
                      (0, (_chai || _load_chai()).expect)(linkResult.linkPath).to.equal((_path || _load_path()).default.normalize('dist/components/bar/foo/utils/is-string.js'));
                    });
                  });
                });
              });
            });
            describe('using custom resolved modules with ES6', function () {
              describe('when dist is inside the component dir', function () {
                var dependencyFileLinkGenerator = void 0;
                var linkResults = void 0;
                var linkResult = void 0;
                before((0, (_bluebird || _load_bluebird()).coroutine)( /*#__PURE__*/(_regenerator || _load_regenerator()).default.mark(function _callee4() {
                  var component, dependencyComponent;
                  return (_regenerator || _load_regenerator()).default.wrap(function _callee4$(_context4) {
                    while (1) {
                      switch (_context4.prev = _context4.next) {
                        case 0:
                          _context4.next = 2;
                          return (_consumerComponent || _load_consumerComponent()).default.fromString(JSON.stringify((_barFoo3 || _load_barFoo3()).default));

                        case 2:
                          component = _context4.sent;
                          component.componentMap = {
                            rootDir: 'components/bar/foo',

                            getRootDir() {
                              return this.rootDir;
                            }
                          };
                          _context4.next = 6;
                          return (_consumerComponent || _load_consumerComponent()).default.fromString(JSON.stringify((_utilsIsString3 || _load_utilsIsString3()).default));

                        case 6:
                          dependencyComponent = _context4.sent;

                          dependencyFileLinkGenerator = new (_dependencyFileLinkGenerator || _load_dependencyFileLinkGenerator()).default({
                            consumer: mockConsumer(),
                            bitMap: mockBitMap(),
                            component,
                            relativePath: component.dependencies.get()[0].relativePaths[0],
                            dependencyComponent,
                            createNpmLinkFiles: false,
                            targetDir: ''
                          });
                          linkResults = dependencyFileLinkGenerator.generate();
                          linkResult = linkResults[0];

                        case 10:
                        case 'end':
                          return _context4.stop();
                      }
                    }
                  }, _callee4, undefined);
                })));
                it('should generate one link file because it is stored in node_modules which is shared between the src and the dist', function () {
                  (0, (_chai || _load_chai()).expect)(linkResults).to.have.lengthOf(1);
                });
                it('should generate linkPath that consist of component rootDir + node_modules + importSource (stored in relativePaths) + index.js', function () {
                  (0, (_chai || _load_chai()).expect)(linkResult.linkPath).to.equal((_path || _load_path()).default.normalize('components/bar/foo/node_modules/utils/is-string/index.js'));
                });
                it('should generate linkContent that points to dependency rootDir + dist + destinationRelativePath', function () {
                  (0, (_chai || _load_chai()).expect)(linkResult.linkContent).to.have.string('.dependencies/utils/is-string/remote-scope/0.0.1/dist/src/utils/is-string');
                });
                it('should generate linkContent that is relative to the linkPath', function () {
                  var absoluteDest = 'components/.dependencies/utils/is-string/remote-scope/0.0.1/dist/src/utils/is-string';
                  var relativeDest = (0, (_path2 || _load_path2()).pathRelativeLinux)(linkResult.linkPath, absoluteDest);
                  (0, (_chai || _load_chai()).expect)(linkResult.linkContent).to.have.string(`require('${relativeDest}')`);
                });
                describe('when createNpmLinkFiles is set to true', function () {
                  before(function () {
                    dependencyFileLinkGenerator.isLinkToPackage = true;
                    dependencyFileLinkGenerator.createNpmLinkFiles = true;
                    linkResults = dependencyFileLinkGenerator.generate();
                    linkResult = linkResults[0];
                  });
                  it('should generate one link file because it is stored in node_modules which is shared between the src and the dist', function () {
                    (0, (_chai || _load_chai()).expect)(linkResults).to.have.lengthOf(1);
                  });
                  it('should generate the link as postInstallLink (so then npm install will rewrite the links that are written in node_modules)', function () {
                    (0, (_chai || _load_chai()).expect)(linkResult.postInstallLink).to.be.true;
                  });
                  it('should generate linkContent that points to the package name instead of a file', function () {
                    (0, (_chai || _load_chai()).expect)(linkResult.linkContent).to.equal("module.exports = require('@bit/remote-scope.utils.is-string');");
                  });
                  it('should generate linkPath that consist of node_modules + importSource + index.js (it must be relative because it is written by postinstall script)', function () {
                    (0, (_chai || _load_chai()).expect)(linkResult.linkPath).to.equal((_path || _load_path()).default.normalize('node_modules/utils/is-string/index.js'));
                  });
                });
              });
              describe('when dist is outside the component dir', function () {
                var dependencyFileLinkGenerator = void 0;
                var linkResults = void 0;
                before((0, (_bluebird || _load_bluebird()).coroutine)( /*#__PURE__*/(_regenerator || _load_regenerator()).default.mark(function _callee5() {
                  var component, dependencyComponent;
                  return (_regenerator || _load_regenerator()).default.wrap(function _callee5$(_context5) {
                    while (1) {
                      switch (_context5.prev = _context5.next) {
                        case 0:
                          _context5.next = 2;
                          return (_consumerComponent || _load_consumerComponent()).default.fromString(JSON.stringify((_barFoo3 || _load_barFoo3()).default));

                        case 2:
                          component = _context5.sent;
                          component.componentMap = {
                            rootDir: 'components/bar/foo',

                            getRootDir() {
                              return this.rootDir;
                            }
                          };
                          _context5.next = 6;
                          return (_consumerComponent || _load_consumerComponent()).default.fromString(JSON.stringify((_utilsIsString3 || _load_utilsIsString3()).default));

                        case 6:
                          dependencyComponent = _context5.sent;

                          dependencyFileLinkGenerator = new (_dependencyFileLinkGenerator || _load_dependencyFileLinkGenerator()).default({
                            consumer: mockConsumer(false),
                            bitMap: mockBitMap(),
                            component,
                            relativePath: component.dependencies.get()[0].relativePaths[0],
                            dependencyComponent,
                            createNpmLinkFiles: false,
                            targetDir: ''
                          });
                          linkResults = dependencyFileLinkGenerator.generate();

                        case 9:
                        case 'end':
                          return _context5.stop();
                      }
                    }
                  }, _callee5, undefined);
                })));
                it('should generate two link files, one for the source and one for the dist', function () {
                  (0, (_chai || _load_chai()).expect)(linkResults).to.have.lengthOf(2);
                });
                describe('link file of the source', function () {
                  var linkResult = void 0;
                  before(function () {
                    linkResult = linkResults[0];
                  });
                  it('should generate linkPath that consist of component rootDir + importSource + index.js', function () {
                    (0, (_chai || _load_chai()).expect)(linkResult.linkPath).to.equal((_path || _load_path()).default.normalize('components/bar/foo/node_modules/utils/is-string/index.js'));
                  });
                  it('should generate linkContent that points to dependency rootDir + destinationRelativePath', function () {
                    (0, (_chai || _load_chai()).expect)(linkResult.linkContent).to.have.string('.dependencies/utils/is-string/remote-scope/0.0.1/src/utils/is-string');
                  });
                  it('should generate linkContent that is relative to the linkPath', function () {
                    var absoluteDest = 'components/.dependencies/utils/is-string/remote-scope/0.0.1/src/utils/is-string';
                    var relativeDest = (0, (_path2 || _load_path2()).pathRelativeLinux)(linkResult.linkPath, absoluteDest);
                    (0, (_chai || _load_chai()).expect)(linkResult.linkContent).to.have.string(`require('${relativeDest}')`);
                  });
                  it('should set isEs6 to true as it has ImportSpecifiers', function () {
                    (0, (_chai || _load_chai()).expect)(linkResult.isEs6).to.be.true;
                  });
                });
                describe('link file of the dist', function () {
                  var linkResult = void 0;
                  before(function () {
                    linkResult = linkResults[1];
                  });
                  it('should generate linkPath that consist of dist + component rootDir + importSource + index.js', function () {
                    (0, (_chai || _load_chai()).expect)(linkResult.linkPath).to.equal((_path || _load_path()).default.normalize('dist/components/bar/foo/node_modules/utils/is-string/index.js'));
                  });
                  it('should generate linkContent that points to dependency rootDir + destinationRelativePath (the dist should not be there as it is already inside dist)', function () {
                    (0, (_chai || _load_chai()).expect)(linkResult.linkContent).to.have.string('.dependencies/utils/is-string/remote-scope/0.0.1/src/utils/is-string');
                  });
                  it('should generate linkContent that is relative to the linkPath', function () {
                    var absoluteDest = 'dist/components/.dependencies/utils/is-string/remote-scope/0.0.1/src/utils/is-string';
                    var relativeDest = (0, (_path2 || _load_path2()).pathRelativeLinux)(linkResult.linkPath, absoluteDest);
                    (0, (_chai || _load_chai()).expect)(linkResult.linkContent).to.have.string(`require('${relativeDest}')`);
                  });
                });
                describe('when isLinkToPackage is set to true', function () {
                  before(function () {
                    dependencyFileLinkGenerator.isLinkToPackage = true;
                    linkResults = dependencyFileLinkGenerator.generate();
                  });
                  it('should generate two link files, one for the source and one for the dist', function () {
                    (0, (_chai || _load_chai()).expect)(linkResults).to.have.lengthOf(2);
                  });
                  describe('link file of the source', function () {
                    var linkResult = void 0;
                    before(function () {
                      linkResult = linkResults[0];
                    });
                    it('should generate linkContent that points to the package name instead of a file', function () {
                      (0, (_chai || _load_chai()).expect)(linkResult.linkContent).to.equal("module.exports = require('@bit/remote-scope.utils.is-string');");
                    });
                    it('should generate linkPath that consist of component rootDir + importSource + index.js', function () {
                      (0, (_chai || _load_chai()).expect)(linkResult.linkPath).to.equal((_path || _load_path()).default.normalize('components/bar/foo/node_modules/utils/is-string/index.js'));
                    });
                  });
                  describe('link file of the dist', function () {
                    var linkResult = void 0;
                    before(function () {
                      linkResult = linkResults[1];
                    });
                    it('should generate linkContent that points to the package name instead of a file', function () {
                      (0, (_chai || _load_chai()).expect)(linkResult.linkContent).to.equal("module.exports = require('@bit/remote-scope.utils.is-string');");
                    });
                    it('should generate linkPath that consist of dist + component rootDir + importSource + index.js', function () {
                      (0, (_chai || _load_chai()).expect)(linkResult.linkPath).to.equal((_path || _load_path()).default.normalize('dist/components/bar/foo/node_modules/utils/is-string/index.js'));
                    });
                  });
                });
              });
            });

          case 3:
          case 'end':
            return _context6.stop();
        }
      }
    }, _callee6, undefined);
  })));
});