Skip to content

Commit

Permalink
Merge pull request #4 from tphummel/cli-tests
Browse files Browse the repository at this point in the history
add first cli tests
  • Loading branch information
tphummel authored Mar 8, 2018
2 parents bf28392 + ea7cfd1 commit 0a19279
Showing 1 changed file with 68 additions and 2 deletions.
70 changes: 68 additions & 2 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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()
})
})

0 comments on commit 0a19279

Please sign in to comment.