[Pkg-javascript-commits] [node-stream-http] 92/208: Add WebWorker test using webworkify

Bastien Roucariès rouca at moszumanska.debian.org
Sun Aug 13 13:39:32 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 bde26be949b1038a446edab7c1325cf7ed630569
Author: John Hiesey <john at hiesey.com>
Date:   Mon Sep 14 17:16:45 2015 -0700

    Add WebWorker test using webworkify
---
 package.json                         |  3 ++-
 test/browser/lib/webworker-worker.js | 20 ++++++++++++++++++++
 test/browser/webworker.js            | 32 ++++++++++++++++++++++++++++++++
 3 files changed, 54 insertions(+), 1 deletion(-)

diff --git a/package.json b/package.json
index ab282a8..d99ae9f 100644
--- a/package.json
+++ b/package.json
@@ -10,7 +10,7 @@
   "scripts": {
     "test": "npm run test-node && npm run test-browser",
     "test-node": "tape test/node/*.js",
-    "test-browser": "zuul -- test/browser/*.js",
+    "test-browser": "zuul --no-coverage -- test/browser/*.js",
     "test-browser-local": "zuul --local 8080 --no-coverage -- test/browser/*.js"
   },
   "author": "John Hiesey",
@@ -37,6 +37,7 @@
     "express": "^4.13.0",
     "tape": "^4.0.0",
     "ua-parser-js": "^0.7.7",
+    "webworkify": "^1.0.2",
     "zuul": "^3.1.0"
   }
 }
diff --git a/test/browser/lib/webworker-worker.js b/test/browser/lib/webworker-worker.js
new file mode 100644
index 0000000..a194de4
--- /dev/null
+++ b/test/browser/lib/webworker-worker.js
@@ -0,0 +1,20 @@
+var Buffer = require('buffer').Buffer
+
+var http = require('../../..')
+
+module.exports = function (self) {
+	self.addEventListener('message', function (ev) {
+		var url = ev.data
+		http.get(url, function (res) {
+			var buffers = []
+
+			res.on('end', function () {
+				self.postMessage(Buffer.concat(buffers).toArrayBuffer())
+			})
+
+			res.on('data', function (data) {
+				buffers.push(data)
+			})
+		})
+	})
+}
\ No newline at end of file
diff --git a/test/browser/webworker.js b/test/browser/webworker.js
new file mode 100644
index 0000000..b1df064
--- /dev/null
+++ b/test/browser/webworker.js
@@ -0,0 +1,32 @@
+var fs = require('fs')
+var test = require('tape')
+var UAParser = require('ua-parser-js')
+var url = require('url')
+var work = require('webworkify')
+
+var browser = (new UAParser()).setUA(navigator.userAgent).getBrowser()
+var browserName = browser.name
+var browserVersion = browser.major
+// Skip browsers with poor or nonexistant WebWorker support
+var skip = ((browserName === 'Opera' && browserVersion <= 12) ||
+	(browserName === 'IE' && browserVersion <= 10) ||
+	(browserName === 'Safari' && browserVersion <= 5) ||
+	(browserName === 'WebKit' && browserVersion <= 534) || // Old mobile safari
+	(browserName === 'Android Browser' && browserVersion <= 4))
+
+var reference = fs.readFileSync(__dirname + '/../server/static/browserify.png')
+
+test('binary download in WebWorker', {
+	skip: skip
+}, function (t) {
+	// We have to use a global url, since webworkify puts the worker in a Blob,
+	// which doesn't have a proper location
+	var testUrl = url.resolve(global.location.href, '/browserify.png')
+	var worker = work(require('./lib/webworker-worker.js'))
+	worker.addEventListener('message', function (ev) {
+		var data = new Buffer(new Uint8Array(ev.data))
+		t.ok(reference.equals(data), 'contents match')
+		t.end()
+	})
+	worker.postMessage(testUrl)
+})
\ 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