bit-bin
Version:
<a href="https://opensource.org/licenses/Apache-2.0"><img alt="apache" src="https://img.shields.io/badge/License-Apache%202.0-blue.svg"></a> <a href="https://github.com/teambit/bit/blob/master/CONTRIBUTING.md"><img alt="prs" src="https://img.shields.io/b
91 lines (78 loc) • 3.91 kB
JavaScript
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
function _chai() {
const data = require("chai");
_chai = function () {
return data;
};
return data;
}
function _pathMap() {
const data = _interopRequireDefault(require("../../../../../fixtures/path-map.json"));
_pathMap = function () {
return data;
};
return data;
}
function _pathMap2() {
const data = require("./path-map");
_pathMap2 = function () {
return data;
};
return data;
}
describe('path-map', () => {
describe('updatePathMapWithLinkFilesData', () => {
it('should return an empty array for an empty pathMap', () => {
const results = (0, _pathMap2().getPathMapWithLinkFilesData)([]);
(0, _chai().expect)(results).to.have.lengthOf(0);
});
it('should throw TypeError for a non array input', () => {
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
(0, _chai().expect)(() => (0, _pathMap2().getPathMapWithLinkFilesData)()).to.throw(TypeError);
});
it('should return the same pathMap when there are no link-files involved', () => {
const fixture = [{
file: 'bar/foo.js',
dependencies: []
}];
const results = (0, _pathMap2().getPathMapWithLinkFilesData)(fixture);
(0, _chai().expect)(results).to.deep.equal(fixture);
});
describe('a file bar/foo require dependencies isString and isArray through two levels of link files', () => {
let results;
let barFooDependency;
before(() => {
results = (0, _pathMap2().getPathMapWithLinkFilesData)(_pathMap().default);
const barFoo = results.find(f => f.file === 'bar/foo.js');
barFooDependency = barFoo.dependencies[0];
});
it('should mark the dependency as a linkFile', () => {
(0, _chai().expect)(barFooDependency).to.have.property('linkFile');
(0, _chai().expect)(barFooDependency.linkFile).to.be.true;
});
it('should add a new attribute realDependencies to the dependency', () => {
(0, _chai().expect)(barFooDependency).to.have.property('realDependencies');
});
it('realDependencies should include the final dependencies skipping multiple links in between', () => {
(0, _chai().expect)(barFooDependency.realDependencies).to.have.lengthOf(2); // ensures that it skips both: utils/index.js and utils/is-string/index.js
(0, _chai().expect)(barFooDependency.realDependencies[0].file).to.equal('utils/is-string/is-string.js'); // ensures that it skips both: utils/index.js and utils/is-array/index.js
(0, _chai().expect)(barFooDependency.realDependencies[1].file).to.equal('utils/is-array/is-array.js');
});
it('realDependencies should have the importSpecifiers.mainFile same as the original file', () => {
const isStringSpecifier = barFooDependency.importSpecifiers.find(i => i.name === 'isString');
const realDepIsStringSpecifier = barFooDependency.realDependencies[0].importSpecifiers[0];
(0, _chai().expect)(realDepIsStringSpecifier.mainFile.name).to.equal(isStringSpecifier.name);
(0, _chai().expect)(realDepIsStringSpecifier.mainFile.isDefault).to.equal(isStringSpecifier.isDefault);
});
it('realDependencies should have the importSpecifiers.linkFile same as the last link file', () => {
const lastLinkFile = 'utils/is-string/index.js';
const lastLink = results.find(f => f.file === lastLinkFile);
const lastLinkSpecifier = lastLink.dependencies[0].importSpecifiers[0];
const realDepIsStringSpecifier = barFooDependency.realDependencies[0].importSpecifiers[0];
(0, _chai().expect)(realDepIsStringSpecifier.linkFile.name).to.equal(lastLinkSpecifier.name);
(0, _chai().expect)(realDepIsStringSpecifier.linkFile.isDefault).to.equal(lastLinkSpecifier.isDefault);
});
});
});
});
;