UNPKG

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

218 lines (197 loc) 7.47 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); function _chai() { const data = require("chai"); _chai = function () { return data; }; return data; } function _componentsIndex() { const data = _interopRequireDefault(require("./components-index")); _componentsIndex = function () { return data; }; return data; } function _bitId() { const data = require("../../bit-id"); _bitId = function () { return data; }; return data; } function _models() { const data = require("../models"); _models = function () { return data; }; return data; } function _object() { const data = _interopRequireDefault(require("./object")); _object = function () { return data; }; return data; } describe('ComponentsIndex', () => { describe('addOne', () => { let componentsIndex; beforeEach(() => { componentsIndex = new (_componentsIndex().default)('scope-path'); }); it('should add to the index array', () => { // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX! const modelComponent = new (_models().ModelComponent)({ scope: 'my-scope', name: 'is-string' }); componentsIndex.addOne(modelComponent); const allIds = componentsIndex.getIds(); const id = new (_bitId().BitId)({ scope: 'my-scope', name: 'is-string' }); (0, _chai().expect)(allIds[0]).to.deep.equal(id); }); it('should not add the same component multiple times', () => { // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX! const modelComponent = new (_models().ModelComponent)({ scope: 'my-scope', name: 'is-string' }); componentsIndex.addOne(modelComponent); componentsIndex.addOne(modelComponent); componentsIndex.addOne(modelComponent); (0, _chai().expect)(componentsIndex.getIds()).to.have.lengthOf(1); }); it('should not add BitObjects that are not Symlink nor ModelComponent', () => { // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX! const bitObject = new (_object().default)({ scope: 'my-scope', name: 'is-string' }); const result = componentsIndex.addOne(bitObject); (0, _chai().expect)(componentsIndex.getIds()).to.have.lengthOf(0); (0, _chai().expect)(result).to.be.false; }); }); describe('remove', () => { let componentsIndex; beforeEach(() => { componentsIndex = new (_componentsIndex().default)('scope-path'); }); it('should remove from the index array', () => { // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX! const modelComponent = new (_models().ModelComponent)({ scope: 'my-scope', name: 'is-string' }); componentsIndex.addOne(modelComponent); (0, _chai().expect)(componentsIndex.getIds()).to.have.lengthOf(1); componentsIndex.removeOne(modelComponent.hash().toString()); (0, _chai().expect)(componentsIndex.getIds()).to.have.lengthOf(0); }); it('should remove the correct one when there are multiple', () => { // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX! const isStringComponent = new (_models().ModelComponent)({ scope: 'my-scope', name: 'is-string' }); // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX! const isTypeComponent = new (_models().ModelComponent)({ scope: 'my-scope', name: 'is-type' }); componentsIndex.addOne(isStringComponent); componentsIndex.addOne(isTypeComponent); (0, _chai().expect)(componentsIndex.getIds()).to.have.lengthOf(2); componentsIndex.removeOne(isStringComponent.hash().toString()); const allIds = componentsIndex.getIds(); (0, _chai().expect)(allIds).to.have.lengthOf(1); const id = new (_bitId().BitId)({ scope: 'my-scope', name: 'is-type' }); (0, _chai().expect)(allIds[0]).to.deep.equal(id); }); }); describe('removeMany', () => { let componentsIndex; let isStringComponent; let isTypeComponent; beforeEach(() => { componentsIndex = new (_componentsIndex().default)('scope-path'); // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX! isStringComponent = new (_models().ModelComponent)({ name: 'is-string' }); // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX! isTypeComponent = new (_models().ModelComponent)({ name: 'is-type' }); componentsIndex.addMany([isStringComponent, isTypeComponent]); (0, _chai().expect)(componentsIndex.getIds()).to.have.lengthOf(2); }); it('should remove multiple when removing them at the same removeMany call', () => { (0, _chai().expect)(componentsIndex.getIds()).to.have.lengthOf(2); componentsIndex.removeMany([isStringComponent.hash().toString(), isTypeComponent.hash().toString()]); (0, _chai().expect)(componentsIndex.getIds()).to.have.lengthOf(0); }); it('should remove multiple when removing them with separate removeMany calls', () => { (0, _chai().expect)(componentsIndex.getIds()).to.have.lengthOf(2); componentsIndex.removeMany([isStringComponent.hash().toString()]); componentsIndex.removeMany([isTypeComponent.hash().toString()]); (0, _chai().expect)(componentsIndex.getIds()).to.have.lengthOf(0); }); it('should remove multiple when calling them with separate removeMany calls using array.map', () => { (0, _chai().expect)(componentsIndex.getIds()).to.have.lengthOf(2); [isStringComponent.hash().toString(), isTypeComponent.hash().toString()].map(h => componentsIndex.removeMany([h])); (0, _chai().expect)(componentsIndex.getIds()).to.have.lengthOf(0); }); }); describe('getIds', () => { let componentsIndex; beforeEach(() => { componentsIndex = new (_componentsIndex().default)('scope-path'); }); it('should not return symlinks', () => { // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX! const symlink = new (_models().Symlink)({ scope: 'my-scope', name: 'is-type' }); componentsIndex.addOne(symlink); const allIds = componentsIndex.getIds(); (0, _chai().expect)(allIds).to.have.lengthOf(0); }); }); describe('getIdsIncludesSymlinks', () => { let componentsIndex; beforeEach(() => { componentsIndex = new (_componentsIndex().default)('scope-path'); }); it('should return symlinks', () => { // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX! const symlink = new (_models().Symlink)({ scope: 'my-scope', name: 'is-type' }); componentsIndex.addOne(symlink); const allIds = componentsIndex.getIdsIncludesSymlinks(); (0, _chai().expect)(allIds).to.have.lengthOf(1); }); it('should return components and symlinks if both exist', () => { // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX! const symlink = new (_models().Symlink)({ scope: 'my-scope', name: 'is-type' }); // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX! const modelComponent = new (_models().ModelComponent)({ scope: 'my-scope', name: 'is-string' }); componentsIndex.addMany([symlink, modelComponent]); const allIds = componentsIndex.getIdsIncludesSymlinks(); (0, _chai().expect)(allIds).to.have.lengthOf(2); }); }); });