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

193 lines (160 loc) 5.17 kB
"use strict"; 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 _rxjs() { const data = require("rxjs"); _rxjs = function () { return data; }; return data; } function _fsExtra() { const data = require("fs-extra"); _fsExtra = function () { return data; }; return data; } function _flow() { const data = require("./flow"); _flow = function () { return data; }; return data; } function _createCapsule() { const data = require("../util/create-capsule"); _createCapsule = function () { return data; }; return data; } function _task() { const data = require("../task/task.spec"); _task = function () { return data; }; return data; } /* eslint-disable no-plusplus */ // // qballer TODO - refactor these tests to make them shorter, // they violate the dry principle. describe('flows', function () { it('should support flow with errors', /*#__PURE__*/(0, _bluebird().coroutine)(function* () { const id = '@bit-test2/flow1'; const fakeFS = (0, _task().getTestCase)(id); const fakeCapsule = yield (0, _createCapsule().createFakeCapsule)(fakeFS, id); const stream = new (_flow().Flow)(['1>&2 echo hello-flow && false', 'echo hello-flow2']).execute(fakeCapsule); let started = false; let taskSubject = 0; return new Promise(resolve => stream.subscribe({ next(data) { if (data.type === 'flow:start') { started = true; } data instanceof _rxjs().Subject && ++taskSubject; }, error(err) { (0, _chai().expect)(started, 'started message sent').to.be.true; (0, _chai().expect)(err.value.tasks.length, 'got two results').to.equal(2); (0, _chai().expect)(taskSubject, 'got subject').to.equal(1); resolve(); }, complete() { (0, _chai().expect)(false, 'should have error').to.be.true; } })); })); it('should support flow with several tasks', /*#__PURE__*/(0, _bluebird().coroutine)(function* () { const id = '@bit-test2/flow1'; const fakeFS = (0, _task().getTestCase)(id); const fakeCapsule = yield (0, _createCapsule().createFakeCapsule)(fakeFS, id); const stream = new (_flow().Flow)(['echo hello-flow', 'echo hello-flow2']).execute(fakeCapsule); let started = false; let taskSubject = 0; let result; return new Promise(resolve => stream.subscribe({ next(data) { if (data.type === 'flow:start') { started = true; } else if (data.type === 'flow:result') { result = data.value; } else { data instanceof _rxjs().Subject && ++taskSubject; } }, complete() { (0, _chai().expect)(started, 'started message sent'); (0, _chai().expect)(result.tasks.length, 'got two result exactly').to.equal(2); (0, _chai().expect)(taskSubject, 'got two subjects').to.equal(2); resolve(); } })); })); it('should support flow with single task', /*#__PURE__*/(0, _bluebird().coroutine)(function* () { const id = '@bit-test2/flow1'; const fakeFS = (0, _task().getTestCase)(id); const fakeCapsule = yield (0, _createCapsule().createFakeCapsule)(fakeFS, id); const stream = new (_flow().Flow)(['echo hello-flow']).execute(fakeCapsule); let started = false; let taskSubject = false; let result; return new Promise(resolve => stream.subscribe({ next(data) { if (data.type === 'flow:start') { started = true; } else if (data.type === 'flow:result') { result = data.value; } else { taskSubject = data instanceof _rxjs().Subject; } }, complete() { (0, _chai().expect)(started, 'started message sent'); (0, _chai().expect)(result.tasks.length, 'got one result exactly').to.equal(1); (0, _chai().expect)(taskSubject, 'got subject').to.be.true; resolve(); } })); })); it('should support empty flow', /*#__PURE__*/(0, _bluebird().coroutine)(function* () { const id = '@bit-test2/flow0'; const flow = new (_flow().Flow)([]); const fakeCapsule = yield (0, _createCapsule().createFakeCapsule)({}, id); const stream = flow.execute(fakeCapsule); let gotEmptyResult = false; let started = false; return new Promise(resolve => stream.subscribe({ next(data) { if (data.type === 'flow:start') { started = true; } if (data.type === 'flow:result') { (0, _chai().expect)(data.value.tasks.length).to.equal(0); gotEmptyResult = true; } }, complete() { (0, _chai().expect)(gotEmptyResult, 'should have ended with empty result').to.be.true; (0, _chai().expect)(started, 'got the flow:start message').to.be.true; resolve(); } })); })); this.afterAll(function () { return (0, _fsExtra().remove)('/tmp/@bit-test2'); }); });