diff --git a/test.js b/test.js index e7ff2db..fe0791f 100644 --- a/test.js +++ b/test.js @@ -22,8 +22,6 @@ tap.test(function singleStreak (t) { displayColumn: 0 }) - console.log(result) - t.equal(result.length, 1) t.equal(result[0].start, '2017-01-02') @@ -141,3 +139,71 @@ tap.test(function rowSatisfiesCriteriaFalse (t) { t.notOk(lib.rowSatisfiesCriteria({row, criteria})) t.end() }) + +const cp = require('child_process') + +tap.test(function cliWithMax (t) { + const inputData = JSON.stringify([ + ['2017-01-01', 3], + ['2017-01-02', 5], + ['2017-01-03', 0], + ['2017-01-04', 0], + ['2017-01-05', 9], + ['2017-01-06', 0], + ['2017-01-07', 0], + ['2017-01-08', 5] + ]) + + const cmd = `echo -n '${inputData}' | ./cli.js --label 0 --column 1 --max 0` + + cp.exec(cmd, { + shell: 'bash' + }, (err, stdout, stderr) => { + t.ifErr(err) + + let outputData + try { + outputData = JSON.parse(stdout) + } catch (e) { + t.fail(e) + } + + t.equal(outputData.length, 2) + t.end() + }) +}) + +tap.test(function cliHelp (t) { + const cmd = `./cli.js --help` + + cp.exec(cmd, { + shell: 'bash' + }, (err, stdout, stderr) => { + t.ifErr(err) + t.ok(stdout.length > 0) + t.end() + }) +}) + +tap.test(function cliVersion (t) { + const cmd = `./cli.js --version` + + cp.exec(cmd, { + shell: 'bash' + }, (err, stdout, stderr) => { + t.ifErr(err) + t.ok(stdout.length > 0) + t.end() + }) +}) + +tap.test(function cliVersion (t) { + const cmd = `echo -n '[a1]' | ./cli.js` + + cp.exec(cmd, { + shell: 'bash' + }, (err, stdout, stderr) => { + t.equal(err.code, 1) + t.end() + }) +})