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

116 lines (95 loc) 3.44 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); function _chai() { const data = require("chai"); _chai = function () { return data; }; return data; } function _sinon() { const data = _interopRequireDefault(require("sinon")); _sinon = function () { return data; }; return data; } function _consumer() { const data = _interopRequireDefault(require("../consumer/consumer")); _consumer = function () { return data; }; return data; } function _exceptions() { const data = require("./bit-map/exceptions"); _exceptions = function () { return data; }; return data; } describe('Consumer', function () { this.timeout(0); let sandbox; const getConsumerInstance = () => { // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX! const consumer = new (_consumer().default)({ projectPath: '', config: {} }); return consumer; }; describe('getComponentIdFromNodeModulesPath', () => { let consumer; before(() => { sandbox = _sinon().default.createSandbox(); // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX! consumer = getConsumerInstance(sandbox); }); after(() => { sandbox.restore(); }); it('should parse the path correctly when a component is not in bitMap and has one dot', () => { const result = consumer.getComponentIdFromNodeModulesPath('../../../node_modules/@bit/q207wrk9-remote.comp/file2.js', '@bit'); (0, _chai().expect)(result.scope).to.equal('q207wrk9-remote'); (0, _chai().expect)(result.name).to.equal('comp'); }); it('should parse the path correctly when a component is not in bitMap and has two dots', () => { const result = consumer.getComponentIdFromNodeModulesPath('../../../node_modules/@bit/q207wrk9-remote.comp.comp2/file2.js', '@bit'); (0, _chai().expect)(result.scope).to.equal('q207wrk9-remote.comp'); (0, _chai().expect)(result.name).to.equal('comp2'); }); it('should parse the path correctly when a component is not in bitMap and has three dots', () => { const result = consumer.getComponentIdFromNodeModulesPath('../../../node_modules/@bit/q207wrk9-remote.comp.comp2.comp3/file2.js', '@bit'); (0, _chai().expect)(result.scope).to.equal('q207wrk9-remote.comp'); (0, _chai().expect)(result.name).to.equal('comp2/comp3'); }); }); describe('getParsedId', () => { let consumer; before(() => { sandbox = _sinon().default.createSandbox(); // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX! consumer = getConsumerInstance(sandbox); }); after(() => { sandbox.restore(); }); it('should throw an error for a missing component', () => { const func = () => consumer.getParsedId('non-exist-comp'); (0, _chai().expect)(func).to.throw(_exceptions().MissingBitMapComponent); }); }); describe('getParsedIdIfExist', () => { let consumer; before(() => { sandbox = _sinon().default.createSandbox(); // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX! consumer = getConsumerInstance(sandbox); }); after(() => { sandbox.restore(); }); it('should throw an error for a missing component', () => { const func = () => consumer.getParsedIdIfExist('non-exist-comp'); (0, _chai().expect)(func).to.not.throw(_exceptions().MissingBitMapComponent); }); }); });