[Pkg-javascript-commits] [node-stream-http] 08/208: All browsers passing basic test

Bastien Roucariès rouca at moszumanska.debian.org
Sun Aug 13 13:39:23 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 d5fd14e59bcb53dff9cb68630eddcfb18e0cf9ed
Author: John Hiesey <john at hiesey.com>
Date:   Thu Jul 2 00:12:48 2015 -0700

    All browsers passing basic test
    
    However, IE8 still needs a polyfill that should be eliminated
---
 .zuul.yml                      |   8 +--
 README.md                      |   2 +-
 capability.js                  |  28 +----------
 package.json                   |   1 +
 request.js                     |   4 +-
 test/server/index.js           |  18 +++++++
 test/server/static/basic.txt   |  19 +++++++
 test/server/static/polyfill.js | 110 +++++++++++++++++++++++++++++++++++++++++
 test/tests/basic.js            |  37 ++++++++++++++
 test/tests/package.json        |   5 ++
 10 files changed, 199 insertions(+), 33 deletions(-)

diff --git a/.zuul.yml b/.zuul.yml
index 0ffc7f3..83f99f0 100644
--- a/.zuul.yml
+++ b/.zuul.yml
@@ -7,13 +7,13 @@ browsers:
   - name: safari
     version: 5..latest
   - name: ie
-    version: 7..latest
+    version: 8..latest
   - name: opera
     version: 11..latest
   - name: iphone
     version: 4.3..latest
-  - name: ipad
-    version: 4.3..latest
   - name: android
     version: 4.0..latest
-server: ./test/server/index.js
\ No newline at end of file
+server: ./test/server/index.js
+scripts:
+  - "/polyfill.js"
\ No newline at end of file
diff --git a/README.md b/README.md
index 07b6899..509a032 100644
--- a/README.md
+++ b/README.md
@@ -29,7 +29,7 @@ responses, but only for text (FILL IN HERE)
 ## Example
 
 ``` js
-http.get('//bundle.js', function (res) {
+http.get('/bundle.js', function (res) {
 	var div = document.getElementById('result');
 	div.innerHTML += 'GET /beep<br>';
 	
diff --git a/capability.js b/capability.js
index f262d7b..5728241 100644
--- a/capability.js
+++ b/capability.js
@@ -1,6 +1,6 @@
 var util = require('util')
 
-exports.fetch = util.isFunction(window.fetch)
+exports.fetch = util.isFunction(window.fetch) && util.isFunction(window.ReadableByteStream)
 
 var xhr = new window.XMLHttpRequest()
 xhr.open('GET', '/')
@@ -21,29 +21,3 @@ exports.mozchunkedarraybuffer = arrayBufferGood && checkTypeSupport('moz-chunked
 exports.overrideMimeType = util.isFunction(xhr.overrideMimeType)
 
 xhr = null // Help gc
-
-// exports.getMode = function (preferBinary) {
-// 	if (exports.fetch) {
-// 		exports.mode = 'fetch'
-// 	} else if (exports.mozchunkedarraybuffer) {
-// 		exports.mode = 'moz-chunked-arraybuffer'
-// 	} else if (exports.msstream) {
-// 		exports.mode = 'ms-stream'
-// 	} else if (exports.arraybuffer && preferBinary) {
-// 		exports.mode = 'arraybuffer'
-// 	} else {
-// 		exports.mode = 'text'
-// 	}
-// }
-
-/*
-// correctness: might need binary
-// speed: might want binary
-
-// normally, stream if correctness not affected. If force stream, . If force, ignore correctness
-
-// force stream 			Use text
-// prefer stream 			Use text if overridemimetype is available
-// force binary (speedy)	Use binary
-
-*/
\ No newline at end of file
diff --git a/package.json b/package.json
index c573a2e..944b37c 100644
--- a/package.json
+++ b/package.json
@@ -10,6 +10,7 @@
   "author": "John Hiesey",
   "license": "MIT",
   "dependencies": {
+    "brfs": "^1.4.0",
     "browserify": "^10.2.4",
     "express": "^4.13.0",
     "tape": "^4.0.0",
diff --git a/request.js b/request.js
index 0b776a9..71c6632 100644
--- a/request.js
+++ b/request.js
@@ -58,7 +58,9 @@ var ClientRequest = module.exports = function (opts) {
 	}
 	self._mode = decideMode(preferBinary)
 
-	self.on('finish', self._onFinish.bind(self))
+	self.on('finish', function () {
+		self._onFinish()
+	})
 }
 
 util.inherits(ClientRequest, stream.Writable)
diff --git a/test/server/index.js b/test/server/index.js
new file mode 100644
index 0000000..2bd067b
--- /dev/null
+++ b/test/server/index.js
@@ -0,0 +1,18 @@
+var express = require('express')
+var http = require('http')
+var path = require('path')
+
+var app = express()
+var server = http.createServer(app)
+
+app.use(function (req, res, next) {
+  res.header('Access-Control-Allow-Origin', '*')
+
+  next()
+})
+
+app.use(express.static(path.join(__dirname, 'static')))
+
+var port = parseInt(process.env.ZUUL_PORT) || 8199
+console.log('server listening on port', port)
+server.listen(port)
diff --git a/test/server/static/basic.txt b/test/server/static/basic.txt
new file mode 100644
index 0000000..aa7a0cc
--- /dev/null
+++ b/test/server/static/basic.txt
@@ -0,0 +1,19 @@
+Mary had a little lamb,
+His fleece was white as snow,
+And everywhere that Mary went,
+The lamb was sure to go.
+
+He followed her to school one day,
+Which was against the rule,
+It made the children laugh and play
+To see a lamb at school.
+
+And so the teacher turned it out,
+But still it lingered near,
+And waited patiently about,
+Till Mary did appear.
+
+"Why does the lamb love Mary so?"
+The eager children cry.
+"Why, Mary loves the lamb, you know."
+The teacher did reply.
diff --git a/test/server/static/polyfill.js b/test/server/static/polyfill.js
new file mode 100644
index 0000000..a02b56a
--- /dev/null
+++ b/test/server/static/polyfill.js
@@ -0,0 +1,110 @@
+// From https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys
+if (!Object.keys) {
+  Object.keys = (function() {
+    'use strict';
+    var hasOwnProperty = Object.prototype.hasOwnProperty,
+        hasDontEnumBug = !({ toString: null }).propertyIsEnumerable('toString'),
+        dontEnums = [
+          'toString',
+          'toLocaleString',
+          'valueOf',
+          'hasOwnProperty',
+          'isPrototypeOf',
+          'propertyIsEnumerable',
+          'constructor'
+        ],
+        dontEnumsLength = dontEnums.length;
+
+    return function(obj) {
+      if (typeof obj !== 'object' && (typeof obj !== 'function' || obj === null)) {
+        throw new TypeError('Object.keys called on non-object');
+      }
+
+      var result = [], prop, i;
+
+      for (prop in obj) {
+        if (hasOwnProperty.call(obj, prop)) {
+          result.push(prop);
+        }
+      }
+
+      if (hasDontEnumBug) {
+        for (i = 0; i < dontEnumsLength; i++) {
+          if (hasOwnProperty.call(obj, dontEnums[i])) {
+            result.push(dontEnums[i]);
+          }
+        }
+      }
+      return result;
+    };
+  }());
+}
+
+// Production steps of ECMA-262, Edition 5, 15.4.4.18
+// Reference: http://es5.github.io/#x15.4.4.18
+if (!Array.prototype.forEach) {
+
+  Array.prototype.forEach = function(callback, thisArg) {
+
+    var T, k;
+
+    if (this == null) {
+      throw new TypeError(' this is null or not defined');
+    }
+
+    // 1. Let O be the result of calling ToObject passing the |this| value as the argument.
+    var O = Object(this);
+
+    // 2. Let lenValue be the result of calling the Get internal method of O with the argument "length".
+    // 3. Let len be ToUint32(lenValue).
+    var len = O.length >>> 0;
+
+    // 4. If IsCallable(callback) is false, throw a TypeError exception.
+    // See: http://es5.github.com/#x9.11
+    if (typeof callback !== "function") {
+      throw new TypeError(callback + ' is not a function');
+    }
+
+    // 5. If thisArg was supplied, let T be thisArg; else let T be undefined.
+    if (arguments.length > 1) {
+      T = thisArg;
+    }
+
+    // 6. Let k be 0
+    k = 0;
+
+    // 7. Repeat, while k < len
+    while (k < len) {
+
+      var kValue;
+
+      // a. Let Pk be ToString(k).
+      //   This is implicit for LHS operands of the in operator
+      // b. Let kPresent be the result of calling the HasProperty internal method of O with argument Pk.
+      //   This step can be combined with c
+      // c. If kPresent is true, then
+      if (k in O) {
+
+        // i. Let kValue be the result of calling the Get internal method of O with argument Pk.
+        kValue = O[k];
+
+        // ii. Call the Call internal method of callback with T as the this value and
+        // argument list containing kValue, k, and O.
+        callback.call(T, kValue, k, O);
+      }
+      // d. Increase k by 1.
+      k++;
+    }
+    // 8. return undefined
+  };
+}
+
+if (!String.prototype.trim) {
+  (function() {
+    // Make sure we trim BOM and NBSP
+    var rtrim = /^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g;
+    String.prototype.trim = function() {
+      return this.replace(rtrim, '');
+    };
+  })();
+}
diff --git a/test/tests/basic.js b/test/tests/basic.js
new file mode 100644
index 0000000..1294727
--- /dev/null
+++ b/test/tests/basic.js
@@ -0,0 +1,37 @@
+var test = require('tape')
+// var crypto = require('crypto')
+var hashes = require('./hashes.json')
+var Buffer = require('buffer').Buffer
+// var sha1 = require('simple-sha1')
+
+var fs = require('fs');
+var reference = fs.readFileSync(__dirname + '/../server/static/basic.txt');
+
+var http = require('../..')
+
+test('basic functionality', function (t) {
+	// var hash = crypto.createHash('sha256')
+	// hash.setEncoding('hex')
+
+	http.get('/basic.txt', function (res) {
+		// var hash = crypto.createHash('sha256')
+		// hash.setEncoding('hex')
+
+		var buffers = []
+
+		res.on('end', function () {
+			// console.warn('end')
+			// hash.end()
+			t.ok(reference.equals(Buffer.concat(buffers)), 'contents match')
+			t.end()
+		})
+
+		res.on('data', function (data) {
+			// console.warn('data')
+			// console.log(data.toString('utf-8'))
+			buffers.push(data)
+		})
+
+		// res.pipe(hash)
+	})
+})
\ No newline at end of file
diff --git a/test/tests/package.json b/test/tests/package.json
new file mode 100644
index 0000000..05963fb
--- /dev/null
+++ b/test/tests/package.json
@@ -0,0 +1,5 @@
+{
+	"browserify":{
+		"transform": [ "brfs" ]
+	}
+}

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