Skip to content

Commit

Permalink
add stdin unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacs committed Oct 30, 2017
1 parent 60b7541 commit e6ee1f8
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/stdin.js
Expand Up @@ -6,8 +6,8 @@ const domain = require('domain')
class Stdin extends Base {
constructor (options) {
options = options || {}
super(options)
options.name = ownOr(options, 'name', '/dev/stdin')
super(options)

// This has to be here for node 0.10's wonky streams
this.stream = ownOr(options, 'tapStream', process.stdin)
Expand Down
79 changes: 79 additions & 0 deletions unit/stdin.js
@@ -0,0 +1,79 @@
const t = require('../')
const Stdin = require('../lib/stdin.js')
const MP = require('minipass')

t.test('uses stdin if no stream provided', t => {
const s = new Stdin()
t.equal(s.stream, process.stdin)
t.equal(s.name, '/dev/stdin')
t.end()
})

t.test('basic test', t => {
const stream = new MP()
const s = new Stdin({
tapStream: stream,
name: 'foo',
buffered: true
})
t.equal(s.stream, stream)
t.equal(s.name, 'foo')

s.main(_ => {
t.match(s.results, {
ok: true,
count: 1,
pass: 1,
fail: 0,
bailout: false,
plan: {
start: 1,
end: 1,
skipAll: false
},
failures: []
})
t.end()
})

s.stream.end(`TAP version 13
1..1
ok 1 - this is fine
`)
})

t.test('failure test', t => {
const stream = new MP()
const s = new Stdin({
tapStream: stream
})

s.main(_ => {
t.match(s.results, {
ok: false,
count: 2,
pass: 1,
fail: 1,
bailout: false,
todo: 0,
skip: 0,
plan: {
start: 1,
end: 2,
skipAll: false
},
failures: [{
ok: false,
id: 2,
name: 'oops'
}]
})
t.end()
})

s.stream.write(`TAP version 13
ok 1 - this is fine
`)

s.threw(new Error('oops'))
})

0 comments on commit e6ee1f8

Please sign in to comment.