[Pkg-javascript-commits] [node-stream-http] 31/208: Test prefer-binary

Bastien Roucariès rouca at moszumanska.debian.org
Sun Aug 13 13:39:25 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 03ba151a6fae5fc9833ef3862103a290754aa3af
Author: John Hiesey <john at hiesey.com>
Date:   Tue Jul 7 18:58:52 2015 -0700

    Test prefer-binary
---
 lib/request.js                   |  2 +-
 test/browser/binary-streaming.js | 20 ++++++++++++++++++++
 test/browser/error.js            | 12 ++++++++++++
 3 files changed, 33 insertions(+), 1 deletion(-)

diff --git a/lib/request.js b/lib/request.js
index ae790cb..6ab69b1 100644
--- a/lib/request.js
+++ b/lib/request.js
@@ -44,7 +44,7 @@ var ClientRequest = module.exports = function (opts) {
 		// If streaming is a high priority but binary compatibility isn't
 		preferBinary = false
 	} else if (opts.mode === 'prefer-binary') {
-		// If binary compatibility is the highest priority
+		// If binary is preferred for speed
 		preferBinary = true
 	} else if (!opts.mode || opts.mode === 'default') {
 		// By default, use binary if text streaming may corrupt data
diff --git a/test/browser/binary-streaming.js b/test/browser/binary-streaming.js
index 0372b07..a69adb6 100644
--- a/test/browser/binary-streaming.js
+++ b/test/browser/binary-streaming.js
@@ -43,4 +43,24 @@ test('binary streaming', function (t) {
 			buffers.push(data)
 		})
 	})
+})
+
+test('large binary request without streaming', function (t) {
+	http.get({
+		path: '/browserify.png?copies=' + COPIES,
+		mode: 'prefer-binary',
+	}, function (res) {
+		var buffers = []
+		res.on('end', function () {
+			if (skipVerification)
+				t.skip('binary data not preserved on IE <= 8')
+			else
+				t.ok(reference.equals(Buffer.concat(buffers)), 'contents match')
+			t.end()
+		})
+
+		res.on('data', function (data) {
+			buffers.push(data)
+		})
+	})
 })
\ No newline at end of file
diff --git a/test/browser/error.js b/test/browser/error.js
new file mode 100644
index 0000000..4a328d6
--- /dev/null
+++ b/test/browser/error.js
@@ -0,0 +1,12 @@
+var Buffer = require('buffer').Buffer
+var test = require('tape')
+
+var http = require('../..')
+
+test('error handling', function (t) {
+	var req = http.get('https://0.0.0.0:0/fail.txt')
+	req.on('error', function (err) {
+		t.ok(err && ('message' in err), 'got error')
+		t.end()
+	})
+})
\ No newline at end of file

-- 
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