[Pkg-javascript-commits] [node-stream-http] 19/208: Add text streaming test

Bastien Roucariès rouca at moszumanska.debian.org
Sun Aug 13 13:39:24 UTC 2017


This is an automated email from the git hooks/post-receive script.

rouca pushed a commit to branch master
in repository node-stream-http.

commit a29ea0ccab2621bb338387d8f325fe63d68a5aa0
Author: John Hiesey <john at hiesey.com>
Date:   Thu Jul 2 22:01:32 2015 -0700

    Add text streaming test
---
 .gitignore              |  3 ++-
 lib/request.js          | 19 ++++---------------
 test/tests/binary.js    |  5 ++---
 test/tests/streaming.js | 20 ++++++++++++++++----
 4 files changed, 24 insertions(+), 23 deletions(-)

diff --git a/.gitignore b/.gitignore
index 40179e4..807464b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,5 @@
-**/.DS_Store
+.DS_Store
 bundle.js
 node_modules
+npm-debug.log
 .zuulrc
diff --git a/lib/request.js b/lib/request.js
index 9124cbf..3e5afac 100644
--- a/lib/request.js
+++ b/lib/request.js
@@ -9,17 +9,6 @@ var util = require('util')
 var IncomingMessage = response.IncomingMessage
 var rStates = response.readyStates
 
-// function copy (to, from) {
-// 	if (!Array.isArray(from))
-// 		from = [from]
-// 	from.forEach(function (obj) {
-// 		Object.keys(function (key), {
-// 			to[key] = from[key]
-// 		})
-// 	})
-// 	return to
-// }
-
 function decideMode (preferBinary) {
 	if (capability.fetch) {
 		return 'fetch'
@@ -48,7 +37,7 @@ var ClientRequest = module.exports = function (opts) {
 	})
 
 	var preferBinary
-	if (opts.mode === 'prefer-stream') {
+	if (opts.mode === 'prefer-streaming') {
 		// If streaming is a high priority but binary compatibility isn't
 		preferBinary = false
 	} else if (opts.mode === 'prefer-binary') {
@@ -149,10 +138,10 @@ ClientRequest.prototype._onFinish = function () {
 
 		xhr.onreadystatechange = function () {
 			switch (xhr.readyState) {
-				case rStates.HEADERS_RECEIVED:
-					self._connect()
-					break
 				case rStates.LOADING:
+					if (!self._response)
+						self._connect()
+					// falls through
 				case rStates.DONE:
 					self._response._onXHRReadyStateChange()
 					break
diff --git a/test/tests/binary.js b/test/tests/binary.js
index cceced3..0dd8eae 100644
--- a/test/tests/binary.js
+++ b/test/tests/binary.js
@@ -16,11 +16,10 @@ test('binary download', function (t) {
 		var buffers = []
 
 		res.on('end', function () {
-			if (skipVerification) {
+			if (skipVerification)
 				t.skip('binary data not preserved on IE <= 8')
-			} else {
+			else
 				t.ok(reference.equals(Buffer.concat(buffers)), 'contents match')
-			}
 			t.end()
 		})
 
diff --git a/test/tests/streaming.js b/test/tests/streaming.js
index 41de46c..4a56615 100644
--- a/test/tests/streaming.js
+++ b/test/tests/streaming.js
@@ -1,21 +1,33 @@
 var Buffer = require('buffer').Buffer
 var fs = require('fs');
 var test = require('tape')
+var UAParser = require('ua-parser-js')
 
-var copies = 1000
+var browserType = (new UAParser()).setUA(navigator.userAgent).getBrowser()
+// Streaming doesn't work in IE8 or below
+var skipStreamingCheck = (browserType.name === 'IE' && browserType.major <= 8)
+
+var COPIES = 1000
+var MIN_PIECES = 5
 
 var referenceOnce = fs.readFileSync(__dirname + '/../server/static/basic.txt');
-var reference = new Buffer(referenceOnce.length * 1000)
+var reference = new Buffer(referenceOnce.length * COPIES)
 reference.fill(referenceOnce)
 
 var http = require('../..')
 
 test('text streaming', function (t) {
-	http.get('/basic.txt?copies=1000', function (res) {
+	http.get({
+		path: '/basic.txt?copies=' + COPIES,
+		mode: 'prefer-streaming'
+	}, function (res) {
 		var buffers = []
 
 		res.on('end', function () {
-			t.ok(buffers.length > 5, 'received in multiple parts')
+			if (skipStreamingCheck)
+				t.skip('streaming not available on IE <= 8')
+			else
+				t.ok(buffers.length >= MIN_PIECES, 'received in multiple parts')
 			t.ok(reference.equals(Buffer.concat(buffers)), 'contents match')
 			t.end()
 		})

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-stream-http.git



More information about the Pkg-javascript-commits mailing list