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

145 lines (120 loc) 4.36 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); function _bluebird() { const data = require("bluebird"); _bluebird = function () { return data; }; return data; } function _chai() { const data = require("chai"); _chai = function () { return data; }; return data; } function _withCompiler() { const data = _interopRequireDefault(require("../../../fixtures/consumer-components/with-compiler/with-compiler.json")); _withCompiler = function () { return data; }; return data; } function _consumerComponent() { const data = _interopRequireDefault(require("./consumer-component")); _consumerComponent = function () { return data; }; return data; } function _compilerExtension() { const data = _interopRequireDefault(require("../../legacy-extensions/compiler-extension")); _compilerExtension = function () { return data; }; return data; } function _sources() { const data = require("./sources"); _sources = function () { return data; }; return data; } // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX! describe('ConsumerComponent', function () { this.timeout(0); describe('fromString()', () => { describe('component with compiler', () => { let component; before( /*#__PURE__*/(0, _bluebird().coroutine)(function* () { component = yield _consumerComponent().default.fromString(JSON.stringify(_withCompiler().default)); })); it('should not crash and return a ConsumerComponent Object', /*#__PURE__*/(0, _bluebird().coroutine)(function* () { (0, _chai().expect)(component).to.be.instanceOf(_consumerComponent().default); })); it('should convert the compiler object to a Compiler instance', () => { (0, _chai().expect)(component.compiler).to.be.instanceOf(_compilerExtension().default); }); }); }); describe('docs', () => { const componentProps = { name: 'is-string', mainFile: 'is-string.js', // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX! files: [new (_sources().SourceFile)({ base: '.', path: 'is-string.js', contents: Buffer.from(''), test: false })] }; it('should return an empty array when there is no docs', () => { // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX! const component = new (_consumerComponent().default)(componentProps); (0, _chai().expect)(component.docs).to.deep.equal([]); }); it('should return the docs when a file has a jsdoc block', /*#__PURE__*/(0, _bluebird().coroutine)(function* () { const src = `/** * is a given variable a string */ function isString() {}`; // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX! const sourceFile = new (_sources().SourceFile)({ base: '.', path: 'is-string.js', contents: Buffer.from(src), test: false }); componentProps.files = [sourceFile]; // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX! const component = new (_consumerComponent().default)(componentProps); yield component.recalculateDocs(); const docs = component.docs; (0, _chai().expect)(docs).to.have.lengthOf(1); (0, _chai().expect)(docs[0].description).to.equal('is a given variable a string'); })); it('should return the docs only for non-test files with jsdocs', /*#__PURE__*/(0, _bluebird().coroutine)(function* () { const src = `/** * is a given variable a string */ function isString() {}`; // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX! const sourceFile = new (_sources().SourceFile)({ base: '.', path: 'is-string.js', contents: Buffer.from(src), test: false }); // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX! const sourceFileSpec = new (_sources().SourceFile)({ base: '.', path: 'is-string.spec.js', contents: Buffer.from(src), test: true }); componentProps.files = [sourceFile, sourceFileSpec]; // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX! const component = new (_consumerComponent().default)(componentProps); yield component.recalculateDocs(); (0, _chai().expect)(component.docs).to.have.lengthOf(1); })); }); });