[Pkg-javascript-commits] [node-randomfill] 14/47: Add fix for phantomjs, also adds travis tests.

Bastien Roucariès rouca at moszumanska.debian.org
Fri Dec 15 09:52:52 UTC 2017


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

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

commit 8e69800aa66577cf6f9a1b0898039863d25c582b
Author: Calvin Metcalf <cmetcalf at appgeo.com>
Date:   Thu Nov 12 16:29:05 2015 -0500

    Add fix for phantomjs, also adds travis tests.
    
    Adds fix for phantomjs and other browsers where
    browserify buffer is not built using a typed
    array.  Adds testing that works with phantomjs
    and sets up testing to run in travis.
---
 .travis.yml  | 15 +++++++++++++++
 .zuul.yml    |  1 +
 README.md    |  2 +-
 browser.js   | 13 ++++++++++---
 package.json |  8 ++++++--
 test.js      | 12 ++++++++----
 6 files changed, 41 insertions(+), 10 deletions(-)

diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..f8eebd8
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,15 @@
+sudo: false
+language: node_js
+matrix:
+  include:
+    - node_js: '0.10'
+      env: TEST_SUITE=test
+    - node_js: '0.12'
+      env: TEST_SUITE=test
+    - node_js: '5'
+      env: TEST_SUITE=test
+    - node_js: '4'
+      env: TEST_SUITE=test
+    - node_js: '4'
+      env: TEST_SUITE=phantom
+script: "npm run-script $TEST_SUITE"
diff --git a/.zuul.yml b/.zuul.yml
new file mode 100644
index 0000000..96d9cfb
--- /dev/null
+++ b/.zuul.yml
@@ -0,0 +1 @@
+ui: tape
diff --git a/README.md b/README.md
index 13e23ff..3bacba4 100644
--- a/README.md
+++ b/README.md
@@ -1,7 +1,7 @@
 randombytes
 ===
 
-[![Version](http://img.shields.io/npm/v/randombytes.svg)](https://www.npmjs.org/package/randombytes)
+[![Version](http://img.shields.io/npm/v/randombytes.svg)](https://www.npmjs.org/package/randombytes) [![Build Status](https://travis-ci.org/crypto-browserify/randombytes.svg?branch=master)](https://travis-ci.org/crypto-browserify/randombytes)
 
 randombytes from node that works in the browser.  In node you just get crypto.randomBytes, but in the browser it uses .crypto/msCrypto.getRandomValues
 
diff --git a/browser.js b/browser.js
index d4fa120..a5490b2 100644
--- a/browser.js
+++ b/browser.js
@@ -13,12 +13,19 @@ if (crypto && crypto.getRandomValues) {
 }
 
 function randomBytes (size, cb) {
-  // in browserify, this is becomes an extended UInt8Array
-  var bytes = new Buffer(size)
+  // phantomjs needs to throw
+  if (size > 65536) {
+    throw new Error('requested too many random bytes')
+  }
+  // in case browserify  isn't use the Uint8Array version
+  var rawBytes = new global.Uint8Array(size)
 
   // This will not work in older browsers.
   // See https://developer.mozilla.org/en-US/docs/Web/API/window.crypto.getRandomValues
-  crypto.getRandomValues(bytes)
+  crypto.getRandomValues(rawBytes)
+
+  // phantomjs doesn't like a buffer being passed here
+  var bytes = new Buffer(rawBytes)
 
   if (typeof cb === 'function') {
     return process.nextTick(function () {
diff --git a/package.json b/package.json
index 6a8617b..941e8be 100644
--- a/package.json
+++ b/package.json
@@ -4,7 +4,9 @@
   "description": "random bytes from browserify stand alone",
   "main": "index.js",
   "scripts": {
-    "test": "standard && node test.js | tspec"
+    "test": "standard && node test.js | tspec",
+    "phantom": "zuul --phantom -- test.js",
+    "local": "zuul --local --no-coverage -- test.js"
   },
   "repository": {
     "type": "git",
@@ -22,8 +24,10 @@
   "homepage": "https://github.com/crypto-browserify/randombytes",
   "browser": "browser.js",
   "devDependencies": {
+    "phantomjs": "^1.9.9",
     "standard": "^3.3.0",
     "tap-spec": "^2.1.2",
-    "tape": "^3.0.3"
+    "tape": "^3.0.3",
+    "zuul": "^3.7.2"
   }
 }
diff --git a/test.js b/test.js
index 9d447e1..5507415 100644
--- a/test.js
+++ b/test.js
@@ -33,13 +33,17 @@ test('async', function (t) {
 if (process.browser) {
   test('requesting to much throws', function (t) {
     t.plan(1)
-    t.throws(randomBytes.bind(null, 65537))
+    t.throws(function () {
+      randomBytes(65537)
+    })
   })
 
   test('requesting to much throws async', function (t) {
     t.plan(1)
-    t.throws(randomBytes.bind(null, 65537, function () {
-      t.ok(false, 'should not get here')
-    }))
+    t.throws(function () {
+      randomBytes(65537, function () {
+        t.ok(false, 'should not get here')
+      })
+    })
   })
 }

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



More information about the Pkg-javascript-commits mailing list