-
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2dc9259
commit e89bea4
Showing
3 changed files
with
29 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import test from 'ava'; | ||
import bufferEquals from 'buffer-equals'; | ||
import fn from './'; | ||
|
||
test.serial('get stdin', async t => { | ||
t.plan(2); | ||
process.stdin.isTTY = false; | ||
|
||
const promise = fn.buffer(); | ||
process.stdin.push(new Buffer('uni')); | ||
process.stdin.push(new Buffer('corns')); | ||
process.stdin.emit('end'); | ||
const data = await promise; | ||
t.true(bufferEquals(data, new Buffer('unicorns'))); | ||
t.is(data.toString(), 'unicorns'); | ||
}); | ||
|
||
test.serial('get empty buffer when no stdin', async t => { | ||
process.stdin.isTTY = true; | ||
t.true(bufferEquals(await fn.buffer(), new Buffer(''))); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,17 @@ | ||
import test from 'ava'; | ||
import bufferEquals from 'buffer-equals'; | ||
import fn from './'; | ||
|
||
test.serial('get stdin', async t => { | ||
t.plan(1); | ||
process.stdin.isTTY = false; | ||
|
||
setImmediate(() => { | ||
process.stdin.push('unicorns'); | ||
process.stdin.emit('end'); | ||
}); | ||
|
||
t.is((await fn()).trim(), 'unicorns'); | ||
const promise = fn(); | ||
process.stdin.push('uni'); | ||
process.stdin.push('corns'); | ||
process.stdin.emit('end'); | ||
t.is((await promise).trim(), 'unicorns'); | ||
}); | ||
|
||
test.serial('get empty string when no stdin', async t => { | ||
process.stdin.isTTY = true; | ||
t.is(await fn(), ''); | ||
}); | ||
|
||
test.serial('get stdin as a buffer', t => { | ||
process.stdin.isTTY = false; | ||
|
||
const promise = fn.buffer(data => { | ||
t.true(bufferEquals(data, new Buffer('unicorns'))); | ||
t.is(data.toString().trim(), 'unicorns'); | ||
}); | ||
|
||
process.stdin.push(new Buffer('unicorns')); | ||
process.stdin.emit('end'); | ||
|
||
return promise; | ||
}); | ||
|
||
test.serial('get empty buffer when no stdin', async t => { | ||
process.stdin.isTTY = true; | ||
|
||
t.true(bufferEquals(await fn.buffer(), new Buffer(''))); | ||
}); |
e89bea4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're welcome! ;)