UNPKG

1.66 kBJavaScriptView Raw
1/* jshint expr: true */
2
3var exec = require('child_process').exec;
4var bin = './bin/hicat';
5
6/**
7 * runs(): runs
8 *
9 * describe('running', function () {
10 * run('--help');
11 * success();
12 * });
13 */
14
15exports.run = function (args) {
16 before(function (next) {
17 exec(bin + ' ' + args, function (_exit, _cout, _cerr) {
18 global.result = {
19 code: _exit && _exit.code || 0,
20 error: _exit,
21 out: _cout,
22 stripped: _cout.replace(/\033\[[^m]*m/g, ''),
23 stderr: _cerr
24 };
25 next();
26 });
27 });
28
29 after(function () {
30 delete global.result;
31 });
32};
33
34/**
35 * success(): asserts success
36 *
37 * describe('running', function () {
38 * run('--help');
39 * success();
40 * });
41 */
42
43exports.success = function () {
44 it('is successful', function () {
45 expect(global.result.code).eql(0);
46 expect(global.result.error).falsy;
47 });
48};
49
50/**
51 * pipe(): runs and pipes things into stdin
52 *
53 * describe('pipes', function () {
54 * pipe('var x = 2', ['--no-pager'])
55 * success();
56 * });
57 */
58
59exports.pipe = function (input, args) {
60 before(function (next) {
61 var spawn = require('child_process').spawn;
62 var child = spawn(bin, args || [], { stdio: 'pipe' });
63 var result = global.result = { out: '', stderr: '' };
64
65 if (input) {
66 child.stdin.write(input);
67 child.stdin.end();
68 }
69
70 child.stdout.on('data', function (data) { result.out += data; });
71 child.stderr.on('data', function (data) { result.stderr += data; });
72 child.on('close', function (code) {
73 result.code = code;
74 next();
75 });
76 });
77
78 after(function () {
79 delete global.result;
80 });
81};