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
163 lines (138 loc) • 4.02 kB
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getTestCase = getTestCase;
function _bluebird() {
const data = require("bluebird");
_bluebird = function () {
return data;
};
return data;
}
function _fsExtra() {
const data = require("fs-extra");
_fsExtra = function () {
return data;
};
return data;
}
function _chai() {
const data = require("chai");
_chai = 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 = function () {
return data;
};
return data;
}
describe('task', function () {
this.afterAll( /*#__PURE__*/(0, _bluebird().coroutine)(function* () {
return (0, _fsExtra().remove)('/tmp/@bit-test');
}));
describe('should run bash commands', function () {
it('with stdout', /*#__PURE__*/(0, _bluebird().coroutine)(function* () {
const message = 'hello-world';
const stream = yield runTask(`echo ${message}`);
return expectMessage(stream, message);
}));
it('with stderr', /*#__PURE__*/(0, _bluebird().coroutine)(function* () {
const message = 'hello-world';
const stream = yield runTask(`1>&2 echo ${message} && false`);
return expectMessage(stream, message, 'task:stderr', 1);
}));
});
describe('should run module', function () {
it('with stdout and result', /*#__PURE__*/(0, _bluebird().coroutine)(function* () {
const stream = yield runTask('@bit/extension', '@bit-test/button0', createModuleTestCase);
return expectMessage(stream, 'hello-module', 'task:stdout', 0, {
message: 'hello-module'
});
}));
it('with stderr and result', /*#__PURE__*/(0, _bluebird().coroutine)(function* () {
const stream = yield runTask('@bit/ext-err', '@bit-test/button1', getErrorCase);
return expectMessage(stream, 'hello-module', 'task:stderr', 0, {
message: 'hello-module'
});
}));
});
});
function expectMessage(stream, message, pipeName = 'task:stdout', code = 0, value = null) {
let out = '';
return new Promise(resolve => stream.subscribe({
next(data) {
if (data.type === pipeName) {
out += data.value.toString();
} else if (data.type === 'result') {
(0, _chai().expect)(data.code).to.equal(code);
(0, _chai().expect)(data.value).to.deep.equal(value);
}
},
complete() {
(0, _chai().expect)(out).to.equal(`${message}\n`);
resolve();
}
}));
}
function runTask(_x) {
return _runTask.apply(this, arguments);
}
function _runTask() {
_runTask = (0, _bluebird().coroutine)(function* (task, id = '@bit-test/button', getter = getTestCase) {
const test = getter(id);
const capsule = yield (0, _createCapsule().createFakeCapsule)(test, id);
const stream = (0, _task().executeTask)(task, capsule);
return stream;
});
return _runTask.apply(this, arguments);
}
function getTestCase(name, main = 'src/index.js') {
return {
[main]: `console.log('hello-world')`,
'package.json': JSON.stringify({
main,
name
}, null, 2)
};
}
function createModuleTestCase(name) {
const testCase = getTestCase(name);
const main = 'node_modules/@bit/extension/index.js';
testCase['node_modules/@bit/extension/index.js'] = `
module.exports = function helloModule() {
console.log('hello-module')
return {
message: 'hello-module'
}
}
`;
testCase['node_modules/@bit/extension/package.json'] = JSON.stringify({
main,
name
}, null, 2);
return testCase;
}
function getErrorCase(id) {
const testCase = getTestCase(id);
testCase['node_modules/@bit/ext-err/index.js'] = `
module.exports = function printErr() {
console.error('hello-module')
return {
message: 'hello-module'
}
}
`;
return testCase;
}
;