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

168 lines (136 loc) 4.04 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.createTestNetworkStream = createTestNetworkStream; exports.createGetGraphFn = createGetGraphFn; function _bluebird() { const data = require("bluebird"); _bluebird = function () { return data; }; return data; } function _graphlib() { const data = require("graphlib"); _graphlib = function () { return data; }; return data; } function _component() { const data = require("../../component"); _component = function () { return data; }; return data; } function _network() { const data = require("../network"); _network = function () { return data; }; return data; } function _bitId() { const data = require("../../../bit-id"); _bitId = function () { return data; }; return data; } function _createCapsule() { const data = require("./create-capsule"); _createCapsule = function () { return data; }; return data; } function _flow() { const data = require("../flow"); _flow = function () { return data; }; return data; } /* eslint-disable @typescript-eslint/no-unused-vars */ function createTestNetworkStream(_x) { return _createTestNetworkStream.apply(this, arguments); } function _createTestNetworkStream() { _createTestNetworkStream = (0, _bluebird().coroutine)(function* (testCase) { const fakeGetGraph = createGetGraphFn(testCase); const fakeWorkSpace = createFakeWorkSpace(fakeGetGraph); const ids = testCase.input.map(val => new (_component().ComponentID)(_bitId().BitId.parse(val))); const getFlow = id => Promise.resolve(new (_flow().Flow)([`echo hello-${id.component.id}`])); const network = new (_network().Network)(fakeWorkSpace, ids, getFlow, fakeGetGraph); return network.execute(testCase.options); }); return _createTestNetworkStream.apply(this, arguments); } function createFakeWorkSpace(fakeGetGraph) { return { getMany: ids => { return Promise.resolve(ids.map(id => { return { id: { toString: () => typeof id === 'string' ? id : id.toString() } }; })); }, loadCapsules: function () { var _ref = (0, _bluebird().coroutine)(function* (ids) { const graph = yield fakeGetGraph({}); return Promise.all(ids.map(id => createFakeCapsuleInGraph(id, graph))); }); return function loadCapsules(_x2) { return _ref.apply(this, arguments); }; }() }; } function createGetGraphFn(testCase) { return _consumer => { const res = Object.entries(testCase.graph).reduce((accum, [key, value]) => { accum.setNode(key); value.forEach(val => { accum.setNode(val); accum.setEdge(key, val); }); return accum; }, new (_graphlib().Graph)()); return Promise.resolve(res); }; } function createFakeCapsuleInGraph(_x3, _x4) { return _createFakeCapsuleInGraph.apply(this, arguments); } function _createFakeCapsuleInGraph() { _createFakeCapsuleInGraph = (0, _bluebird().coroutine)(function* (name, graph) { const main = 'src/index.js'; const dependencies = (graph.predecessors(name) || []).reduce((accum, dependency) => { accum[dependency] = `file://${(0, _createCapsule().getFakeCapsuleLocation)(name)}`; return accum; }, {}); const fs = { [main]: ` ${Object.keys(dependencies).map(dependency => `const ${dependency.split('/')[1]} = require('${dependency}')`).join('\n')} function printMe(){ console.log('${Object.keys(dependencies).map(dependency => `${dependency.split('/')[1]}()` || ['hello', 'world']).join('+')}') } module.exports = function () { return '${name}' } `, 'package.json': JSON.stringify({ main, name, dependencies }, null, 2) }; const fakeCapsule = yield (0, _createCapsule().createFakeCapsule)(fs, name); return fakeCapsule; }); return _createFakeCapsuleInGraph.apply(this, arguments); }