-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
5 changed files
with
261 additions
and
46 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,61 @@ | ||
var Stream = require('stream') | ||
var Readable = Stream.Readable | ||
var Writable = Stream.Writable | ||
|
||
;(function handleStream() { | ||
var runner = require('..').Runner({ stream: true }) | ||
|
||
var outputs = [] | ||
var rs = createReadable([1, 2]) | ||
|
||
return runner.thunkify(function () { | ||
setTimeout(function() { | ||
var ws = createWritable(outputs) | ||
rs.pipe(ws) | ||
}, 0) | ||
return rs | ||
})().then(function (res) { | ||
// [] | ||
console.log(res) | ||
}) | ||
})() | ||
.then(function doNotHandleStream() { | ||
var runner = require('..').Runner({ stream: false }) | ||
|
||
var outputs = [] | ||
var rs = createReadable([1, 2]) | ||
|
||
runner.thunkify(function () { | ||
setTimeout(function() { | ||
var ws = createWritable(outputs) | ||
rs.pipe(ws) | ||
}, 0) | ||
return rs | ||
})().then(function (res) { | ||
// true | ||
console.log(res[0] === rs) | ||
}) | ||
}) | ||
|
||
function createReadable(input) { | ||
var stream = Readable({ objectMode: true }) | ||
var i = 0 | ||
stream._read = function () { | ||
if (i < input.length) { | ||
this.push(input[i++]) | ||
} else { | ||
this.push(null) | ||
} | ||
} | ||
return stream | ||
} | ||
|
||
function createWritable(output) { | ||
var stream = Writable({ objectMode: true }) | ||
var i = 0 | ||
stream._write = function (data, _, next) { | ||
output.push(data) | ||
next() | ||
} | ||
return stream | ||
} |
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
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,48 @@ | ||
var test = require('tap').test | ||
var Runner = require('..').Runner | ||
var Stream = require('./lib/stream') | ||
|
||
test('stream', function(t) { | ||
t.plan(2) | ||
|
||
var runner = Runner({ stream: false }) | ||
var outputs = [] | ||
var rs = Stream.Readable([1, 2]) | ||
runner.thunkify(function () { | ||
setTimeout(function() { | ||
var ws = Stream.Writable(outputs) | ||
rs.pipe(ws) | ||
}, 0) | ||
return rs | ||
})() | ||
.then(function (res) { | ||
t.same(outputs, []) | ||
t.equal(res[0], rs) | ||
}) | ||
}) | ||
|
||
test('promise', function(t) { | ||
t.plan(1) | ||
|
||
var runner = Runner({ promise: false }) | ||
var p = new Promise(function (resolve) { | ||
setTimeout(resolve, 0) | ||
}) | ||
runner.thunkify(function () { | ||
return p | ||
})() | ||
.then(function (res) { | ||
t.equal(res[0], p) | ||
}) | ||
}) | ||
|
||
test('async', function(t) { | ||
t.plan(2) | ||
|
||
var runner = Runner({ async: false }) | ||
runner.thunkify(function (cb) { | ||
t.notOk(cb) | ||
t.equal(arguments.length, 0) | ||
})() | ||
}) | ||
|