[Pkg-javascript-commits] [node-stream-http] 26/208: Add http-browserify test and reorg tests

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 35b1c7a58b22bd68c53d756f5cfc349a02cf6c87
Author: John Hiesey <john at hiesey.com>
Date:   Tue Jul 7 13:40:05 2015 -0700

    Add http-browserify test and reorg tests
---
 index.js                                    |  5 +-
 lib/request.js                              |  2 +-
 package.json                                |  6 +-
 test/{tests => browser}/binary-streaming.js |  0
 test/{tests => browser}/binary.js           |  0
 test/{tests => browser}/headers.js          |  0
 test/{tests => browser}/package.json        |  0
 test/{tests => browser}/text-streaming.js   |  0
 test/{tests => browser}/text.js             |  0
 test/node/http-browserify.js                | 97 +++++++++++++++++++++++++++++
 10 files changed, 106 insertions(+), 4 deletions(-)

diff --git a/index.js b/index.js
index ff212dc..304badd 100644
--- a/index.js
+++ b/index.js
@@ -24,7 +24,10 @@ http.request = function (opts, cb) {
 	opts.hostname = opts.hostname || hostHostname || window.location.hostname
 	opts.port = opts.port || hostPort || defaultPort
 
-	// Also valid opts.auth, opts.credentials, opts.mode
+	if (util.isUndefined(opts.withCredentials))
+		opts.withCredentials = true
+
+	// Also valid opts.auth, opts.mode
 
 	var req = new ClientRequest(opts)
 	if (cb)
diff --git a/lib/request.js b/lib/request.js
index 28a874d..a32595c 100644
--- a/lib/request.js
+++ b/lib/request.js
@@ -128,7 +128,7 @@ ClientRequest.prototype._onFinish = function () {
 			xhr.responseType = self._mode.split(':')[0]
 
 		if ('withCredentials' in xhr)
-			xhr.withCredentials = !!opts.credentials
+			xhr.withCredentials = !!opts.withCredentials
 
 		if (self._mode === 'text' && 'overrideMimeType' in xhr)
 			xhr.overrideMimeType('text/plain; charset=x-user-defined')
diff --git a/package.json b/package.json
index fafadb4..05fb501 100644
--- a/package.json
+++ b/package.json
@@ -8,8 +8,10 @@
     "url": "git://github.com/jhiesey/httpstream.git"
   },
   "scripts": {
-    "test": "zuul -- test/tests/*.js",
-    "test-local": "zuul --local 8080 --no-coverage -- test/tests/*.js"
+    "test": "npm run test-node && npm run test-browser",
+    "test-node": "tape test/node/*.js",
+    "test-browser": "zuul -- test/browser/*.js",
+    "test-browser-local": "zuul --local 8080 --no-coverage -- test/browser/*.js"
   },
   "author": "John Hiesey",
   "license": "MIT",
diff --git a/test/tests/binary-streaming.js b/test/browser/binary-streaming.js
similarity index 100%
rename from test/tests/binary-streaming.js
rename to test/browser/binary-streaming.js
diff --git a/test/tests/binary.js b/test/browser/binary.js
similarity index 100%
rename from test/tests/binary.js
rename to test/browser/binary.js
diff --git a/test/tests/headers.js b/test/browser/headers.js
similarity index 100%
rename from test/tests/headers.js
rename to test/browser/headers.js
diff --git a/test/tests/package.json b/test/browser/package.json
similarity index 100%
rename from test/tests/package.json
rename to test/browser/package.json
diff --git a/test/tests/text-streaming.js b/test/browser/text-streaming.js
similarity index 100%
rename from test/tests/text-streaming.js
rename to test/browser/text-streaming.js
diff --git a/test/tests/text.js b/test/browser/text.js
similarity index 100%
rename from test/tests/text.js
rename to test/browser/text.js
diff --git a/test/node/http-browserify.js b/test/node/http-browserify.js
new file mode 100644
index 0000000..670e677
--- /dev/null
+++ b/test/node/http-browserify.js
@@ -0,0 +1,97 @@
+// These tests are teken from http-browserify to ensure compatibility with
+// that module
+var test = require('tape')
+
+global.window = {}
+window.location = {
+		hostname: 'localhost',
+		port: 8081,
+		protocol: 'http:'
+}
+
+var noop = function() {}
+window.XMLHttpRequest = function() {
+	this.open = noop
+	this.send = noop
+	this.withCredentials = false
+}
+
+var moduleName = require.resolve('../../')
+delete require.cache[moduleName]
+var http = require('../../')
+
+test('Test simple url string', function(t) {
+	var url = { path: '/api/foo' }
+	var request = http.get(url, noop)
+
+	t.equal( request._url, 'http://localhost:8081/api/foo', 'Url should be correct')
+	t.end()
+
+})
+
+test('Test full url object', function(t) {
+	var url = {
+		host: "localhost:8081",
+		hostname: "localhost",
+		href: "http://localhost:8081/api/foo?bar=baz",
+		method: "GET",
+		path: "/api/foo?bar=baz",
+		pathname: "/api/foo",
+		port: "8081",
+		protocol: "http:",
+		query: "bar=baz",
+		search: "?bar=baz",
+		slashes: true
+	}
+
+	var request = http.get(url, noop)
+
+	t.equal( request._url, 'http://localhost:8081/api/foo?bar=baz', 'Url should be correct')
+	t.end()
+
+})
+
+test('Test alt protocol', function(t) {
+	var params = {
+		protocol: "foo:",
+		hostname: "localhost",
+		port: "3000",
+		path: "/bar"
+	}
+
+	var request = http.get(params, noop)
+
+	t.equal( request._url, 'foo://localhost:3000/bar', 'Url should be correct')
+	t.end()
+
+})
+
+test('Test string as parameters', function(t) {
+	var url = '/api/foo'
+	var request = http.get(url, noop)
+
+	t.equal( request._url, 'http://localhost:8081/api/foo', 'Url should be correct')
+	t.end()
+
+})
+
+test('Test withCredentials param', function(t) {
+	var url = '/api/foo'
+
+	var request = http.get({ url: url, withCredentials: false }, noop)
+	t.equal( request._xhr.withCredentials, false, 'xhr.withCredentials should be false')
+
+	var request = http.get({ url: url, withCredentials: true }, noop)
+	t.equal( request._xhr.withCredentials, true, 'xhr.withCredentials should be true')
+
+	var request = http.get({ url: url }, noop)
+	t.equal( request._xhr.withCredentials, true, 'xhr.withCredentials should be true')
+
+	t.end()
+})
+
+test('Cleanup', function (t) {
+	delete global.window
+	delete require.cache[moduleName]
+	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