reactors-cli
Version:
Command line utility for reactors
363 lines (286 loc) • 11.2 kB
JavaScript
;
var _colors = require('colors');
var _colors2 = _interopRequireDefault(_colors);
var _path2 = require('path');
var _path3 = _interopRequireDefault(_path2);
var _should = require('should');
var _should2 = _interopRequireDefault(_should);
require('babel-polyfill');
var _fs = require('fs');
var _fs2 = _interopRequireDefault(_fs);
var _lodash = require('lodash');
var _lodash2 = _interopRequireDefault(_lodash);
var _std = require('../util/std');
var _std2 = _interopRequireDefault(_std);
var _exec = require('../util/exec');
var _exec2 = _interopRequireDefault(_exec);
var _read = require('../util/read');
var _read2 = _interopRequireDefault(_read);
var _package = require('../../package.json');
var _config = require('../config');
var _config2 = _interopRequireDefault(_config);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; } /* global describe it after */
function cbToPromise(fn) {
return new Promise(function (resolve, reject) {
fn(function (error, result) {
if (error) {
return reject(error);
}
resolve(result);
});
});
}
function stat() {
var _this = this;
for (var _len = arguments.length, paths = Array(_len), _key = 0; _key < _len; _key++) {
paths[_key] = arguments[_key];
}
return new Promise(function () {
var _ref = _asyncToGenerator(regeneratorRuntime.mark(function _callee(resolve, reject) {
var _path;
return regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
_context.prev = 0;
_path = _path3.default.join.apply(_path3.default, paths);
_context.t0 = resolve;
_context.next = 5;
return cbToPromise(_fs2.default.stat.bind(null, _path));
case 5:
_context.t1 = _context.sent;
(0, _context.t0)(_context.t1);
_context.next = 12;
break;
case 9:
_context.prev = 9;
_context.t2 = _context['catch'](0);
reject(_context.t2);
case 12:
case 'end':
return _context.stop();
}
}
}, _callee, _this, [[0, 9]]);
}));
return function (_x, _x2) {
return _ref.apply(this, arguments);
};
}());
}
var APP_NAME = 'InitReactorsApp';
var CONTAINER_PATH = '/tmp';
var PROJECT_PATH = _path3.default.join(CONTAINER_PATH, APP_NAME);
var APP_PATH = _path3.default.join(PROJECT_PATH, 'app');
var DESKTOP_PATH = _path3.default.join(PROJECT_PATH, 'desktop');
var output = '';
describe('Init', function () {
describe('Command', function () {
it('should init app', _asyncToGenerator(regeneratorRuntime.mark(function _callee3() {
var _this2 = this;
return regeneratorRuntime.wrap(function _callee3$(_context3) {
while (1) {
switch (_context3.prev = _context3.next) {
case 0:
this.timeout(1000 * 60 * 5);
return _context3.abrupt('return', new Promise(function () {
var _ref3 = _asyncToGenerator(regeneratorRuntime.mark(function _callee2(resolve, reject) {
var binPath, io;
return regeneratorRuntime.wrap(function _callee2$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
try {
binPath = _path3.default.resolve(__dirname, '../..', _package.bin.reactors);
io = (0, _std2.default)('node ' + binPath + ' init ' + APP_NAME, { cwd: CONTAINER_PATH });
io.on('error', reject);
io.on('message', function (message) {
if (message.std === 'err') {
console.log(_colors2.default.yellow(message.data.yellow));
} else {
console.log(_colors2.default.yellow(message.data.grey));
}
});
io.on('done', function (_ref4) {
var out = _ref4.out;
output = out;
resolve();
});
} catch (error) {
reject(error);
}
case 1:
case 'end':
return _context2.stop();
}
}
}, _callee2, _this2);
}));
return function (_x3, _x4) {
return _ref3.apply(this, arguments);
};
}()));
case 2:
case 'end':
return _context3.stop();
}
}
}, _callee3, this);
})));
});
describe('Output', function () {
it('should have displayed init ok message', function () {
(0, _should2.default)(output.trim()).endWith(_config2.default.INIT_OK_MSG);
});
});
describe('Project', function () {
it('should have created project directory', _asyncToGenerator(regeneratorRuntime.mark(function _callee4() {
var stats;
return regeneratorRuntime.wrap(function _callee4$(_context4) {
while (1) {
switch (_context4.prev = _context4.next) {
case 0:
_context4.next = 2;
return stat(PROJECT_PATH);
case 2:
stats = _context4.sent;
(0, _should2.default)(stats.isDirectory()).eql(true);
case 4:
case 'end':
return _context4.stop();
}
}
}, _callee4, undefined);
})));
});
describe('Abstract App', function () {
describe('Directory', function () {
it('should have created app directory', _asyncToGenerator(regeneratorRuntime.mark(function _callee5() {
var stats;
return regeneratorRuntime.wrap(function _callee5$(_context5) {
while (1) {
switch (_context5.prev = _context5.next) {
case 0:
_context5.next = 2;
return stat(APP_PATH);
case 2:
stats = _context5.sent;
(0, _should2.default)(stats.isDirectory()).eql(true);
case 4:
case 'end':
return _context5.stop();
}
}
}, _callee5, undefined);
})));
});
describe('Package.json', function () {
var source = void 0,
json = void 0;
it('should get package', _asyncToGenerator(regeneratorRuntime.mark(function _callee6() {
return regeneratorRuntime.wrap(function _callee6$(_context6) {
while (1) {
switch (_context6.prev = _context6.next) {
case 0:
_context6.next = 2;
return (0, _read2.default)(_path3.default.join(APP_PATH, 'package.json'));
case 2:
source = _context6.sent;
case 3:
case 'end':
return _context6.stop();
}
}
}, _callee6, undefined);
})));
it('should be an object', function () {
json = JSON.parse(source);
});
it('should have the right name', function () {
(0, _should2.default)(json.name).eql(APP_NAME);
});
it('should have the right version', function () {
(0, _should2.default)(json.version).eql('0.0.0');
});
it('should have the right dev dependencies', function () {
(0, _should2.default)(_lodash2.default.keys(json.devDependencies)).eql(_config2.default.APP_DEV_DEPS);
});
it('should have the right dependencies', function () {
(0, _should2.default)(_lodash2.default.keys(json.dependencies)).eql(_config2.default.APP_DEPS);
});
});
describe('SRC Directory', function () {
it('should have created src directory', _asyncToGenerator(regeneratorRuntime.mark(function _callee7() {
var stats;
return regeneratorRuntime.wrap(function _callee7$(_context7) {
while (1) {
switch (_context7.prev = _context7.next) {
case 0:
_context7.next = 2;
return stat(APP_PATH, 'src');
case 2:
stats = _context7.sent;
(0, _should2.default)(stats.isDirectory()).eql(true);
case 4:
case 'end':
return _context7.stop();
}
}
}, _callee7, undefined);
})));
it('should have created App entry', _asyncToGenerator(regeneratorRuntime.mark(function _callee8() {
var stats;
return regeneratorRuntime.wrap(function _callee8$(_context8) {
while (1) {
switch (_context8.prev = _context8.next) {
case 0:
_context8.next = 2;
return stat(APP_PATH, 'src/App.js');
case 2:
stats = _context8.sent;
(0, _should2.default)(stats.isFile()).eql(true);
case 4:
case 'end':
return _context8.stop();
}
}
}, _callee8, undefined);
})));
});
});
describe('Desktop native app', function () {
it('should have created desktop directory', _asyncToGenerator(regeneratorRuntime.mark(function _callee9() {
var stats;
return regeneratorRuntime.wrap(function _callee9$(_context9) {
while (1) {
switch (_context9.prev = _context9.next) {
case 0:
_context9.next = 2;
return stat(DESKTOP_PATH);
case 2:
stats = _context9.sent;
(0, _should2.default)(stats.isDirectory()).eql(true);
case 4:
case 'end':
return _context9.stop();
}
}
}, _callee9, undefined);
})));
});
after('remove project', _asyncToGenerator(regeneratorRuntime.mark(function _callee10() {
return regeneratorRuntime.wrap(function _callee10$(_context10) {
while (1) {
switch (_context10.prev = _context10.next) {
case 0:
_context10.next = 2;
return (0, _exec2.default)('rm -rf ' + PROJECT_PATH);
case 2:
case 'end':
return _context10.stop();
}
}
}, _callee10, undefined);
})));
});