-
-
Notifications
You must be signed in to change notification settings - Fork 933
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Base logic moved into event-emitter and all APIs wrapped around it * read-all-stream combined into one place - less code duplication * Unzip stream now inherits all properties and function from response and returned instead of response Closes #66
- Loading branch information
Showing
9 changed files
with
323 additions
and
243 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
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
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,90 @@ | ||
'use strict'; | ||
|
||
var test = require('tap').test; | ||
var from2Array = require('from2-array'); | ||
var got = require('../'); | ||
var server = require('./server.js'); | ||
var s = server.createServer(); | ||
|
||
s.on('/', function (req, res) { | ||
res.end('ok'); | ||
}); | ||
|
||
s.on('/post', function (req, res) { | ||
req.pipe(res); | ||
}); | ||
|
||
s.on('/redirect', function (req, res) { | ||
res.writeHead(302, { | ||
location: s.url | ||
}); | ||
res.end(); | ||
}); | ||
|
||
test('setup', function (t) { | ||
s.listen(s.port, function () { | ||
t.end(); | ||
}); | ||
}); | ||
|
||
test('json option can not be used in stream mode', function (t) { | ||
t.throws(function () { | ||
got.stream(s.url, {json: true}); | ||
}, 'got can not be used as stream when options.json is used'); | ||
t.end(); | ||
}); | ||
|
||
test('return readable stream', function (t) { | ||
got.stream(s.url) | ||
.on('data', function (data) { | ||
t.equal(data.toString(), 'ok'); | ||
t.end(); | ||
}); | ||
}); | ||
|
||
test('return writeable stream', function (t) { | ||
t.plan(1); | ||
got.stream(s.url + '/post', {method: 'POST'}) | ||
.on('data', function (data) { | ||
t.equal(data.toString(), 'wow'); | ||
}) | ||
.end('wow'); | ||
}); | ||
|
||
test('throws on write to stream with body specified', function (t) { | ||
t.throws(function () { | ||
got.stream(s.url, {body: 'wow'}).write('wow'); | ||
}, 'got\'s stream is not writable when options.body is used'); | ||
|
||
// wait for request to end | ||
setTimeout(t.end.bind(t), 10); | ||
}); | ||
|
||
test('request event', function (t) { | ||
got.stream(s.url) | ||
.on('request', function (req) { | ||
t.ok(req); | ||
t.end(); | ||
}); | ||
}); | ||
|
||
test('redirect event', function (t) { | ||
got.stream(s.url + '/redirect') | ||
.on('redirect', function (res, opts) { | ||
t.equal(res.headers.location, s.url); | ||
t.end(); | ||
}); | ||
}); | ||
|
||
test('response event', function (t) { | ||
got.stream(s.url) | ||
.on('response', function (res) { | ||
t.equal(res.statusCode, 200); | ||
t.end(); | ||
}); | ||
}); | ||
|
||
test('cleanup', function (t) { | ||
s.close(); | ||
t.end(); | ||
}); |