summaryrefslogtreecommitdiff
path: root/deps/npm/node_modules/npm-registry-client/test/fetch-streaming.js
diff options
context:
space:
mode:
Diffstat (limited to 'deps/npm/node_modules/npm-registry-client/test/fetch-streaming.js')
-rw-r--r--deps/npm/node_modules/npm-registry-client/test/fetch-streaming.js58
1 files changed, 58 insertions, 0 deletions
diff --git a/deps/npm/node_modules/npm-registry-client/test/fetch-streaming.js b/deps/npm/node_modules/npm-registry-client/test/fetch-streaming.js
new file mode 100644
index 0000000000..72aeea0beb
--- /dev/null
+++ b/deps/npm/node_modules/npm-registry-client/test/fetch-streaming.js
@@ -0,0 +1,58 @@
+var test = require('tap').test
+var concat = require('concat-stream')
+
+var server = require('./lib/server.js')
+var common = require('./lib/common.js')
+var client = common.freshClient()
+
+var testData = JSON.stringify({test: true})
+var errorData = JSON.stringify({error: 'it went bad'})
+
+test('streaming fetch', function (t) {
+ server.expect('/test', function (req, res) {
+ t.equal(req.method, 'GET', 'got expected method')
+
+ res.writeHead(200, {
+ 'content-type': 'application/json'
+ })
+
+ res.end(testData)
+ })
+
+ server.expect('/error', function (req, res) {
+ t.equal(req.method, 'GET', 'got expected method')
+
+ res.writeHead(401, {
+ 'content-type': 'application/json'
+ })
+
+ res.end(errorData)
+ })
+
+ client.fetch(
+ 'http://localhost:1337/test',
+ { streaming: true },
+ function (er, res) {
+ t.ifError(er, 'loaded successfully')
+
+ var sink = concat(function (data) {
+ t.deepEqual(data.toString(), testData)
+ client.fetch(
+ 'http://localhost:1337/error',
+ { streaming: true },
+ function (er, res) {
+ t.ok(er, 'got an error')
+ server.close()
+ t.end()
+ }
+ )
+ })
+
+ res.on('error', function (error) {
+ t.ifError(error, 'no errors on stream')
+ })
+
+ res.pipe(sink)
+ }
+ )
+})