[Pkg-javascript-commits] [sockjs-client] 36/350: Tests can now run independently.

tonnerre at ancient-solutions.com tonnerre at ancient-solutions.com
Fri Aug 5 01:03:39 UTC 2016


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

tonnerre-guest pushed a commit to branch upstream
in repository sockjs-client.

commit 1628dcc1b00e21abdb8e3b7b8dc419e92c94b4dd
Author: Bryce Kahle <bryce.kahle at mlssoccer.com>
Date:   Tue May 6 17:01:20 2014 -0400

    Tests can now run independently.
    
    Using zuul for automated browser testing.
---
 .travis.yml                         |  9 +++-
 .zuul.yml                           | 23 ++++++++++
 Makefile                            |  3 +-
 package.json                        | 57 ++++++++++++++++---------
 tests/html/lib/.placeholder         |  0
 tests/html/src/domtests.coffee      | 12 +-----
 tests/html/src/endtoendtests.coffee | 42 +++++++++---------
 tests/html/src/protocols.coffee     | 12 ++++++
 tests/html/src/tests.coffee         | 50 +++++++++++-----------
 tests/html/src/unittests.coffee     |  2 +-
 tests/sockjs_app.js                 | 85 +++++++++++++++++++++++++++++++++++++
 tests/sockjs_server.js              | 64 ++++++++++++++++++++++++++++
 12 files changed, 279 insertions(+), 80 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index 87f8cd9..4b6c285 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,3 +1,10 @@
 language: node_js
 node_js:
-  - "0.10"
\ No newline at end of file
+- '0.10'
+before_script:
+- "make build_tests"
+- "node tests/sockjs_server.js"
+env:
+  global:
+  - secure: L36j3mbU1U2FiOhxYZrTZ7apVnb56gE+QFixsYyDpCRBrVW0q8WR9LTMJx+aPNdlzhRS5FT4gfInujPTnZeb+EvqEoYwtT+CeNG15XtGkfJDkfBFjBa4IZpJAjIwJB+0kKkZr9R7lQEEgy7H9FvLHY2N2WgdzuG8WZwiVRnkwVw=
+  - secure: K6NxT5qIzV/4Ce1HqoYMdpFtqxx5S5Ua/sKp1bbHCXTCft6gLBR3mrf1RR14Wj9AwcM9QY6YbNF/dXGmBdMNtiJN+a2nvcfIoPTGJ3UpK4r2xI5w/U+uhRQMxD55SkWaxUIPvEfgvwyETSpFZRYACnNkpxeQWMkdc14vk74Feu0=
diff --git a/.zuul.yml b/.zuul.yml
new file mode 100644
index 0000000..5f0bb5f
--- /dev/null
+++ b/.zuul.yml
@@ -0,0 +1,23 @@
+ui: qunit
+scripts:
+  - "http://cdnjs.cloudflare.com/ajax/libs/jquery/1.7.1/jquery.min.js"
+  - "config.js"
+  - "domain.js"
+  - "lib/sockjs.js"
+  - "lib/tests.js"
+server: ./tests/sockjs_server.js
+browsers:
+  - name: chrome
+    version: latest
+  - name: firefox
+    version: latest
+  - name: opera
+    version: 11..latest
+  - name: safari
+    version: 5..latest
+  - name: ie
+    version: 6..latest
+  - name: iphone
+    version: 4..latest
+  - name: android
+    version: 4.0..latest
\ No newline at end of file
diff --git a/Makefile b/Makefile
index 95957f4..9448b71 100644
--- a/Makefile
+++ b/Makefile
@@ -23,11 +23,12 @@ tests/html/lib/sockjs.js: sockjs.js
 
 tests/html/lib/%.js: tests/html/src/%.coffee
 	@$(COFFEE) -v > /dev/null
+	mkdir -p tests/html/lib
 	$(COFFEE) -o tests/html/lib/ -c --bare $<
 
 build_tests: tests/html/lib/sockjs.js tests/html/lib/tests.js \
 		tests/html/lib/unittests.js tests/html/lib/domtests.js \
-		tests/html/lib/endtoendtests.js
+		tests/html/lib/endtoendtests.js tests/html/lib/protocols.js
 
 test: tests
 tests: build_tests
diff --git a/package.json b/package.json
index 27b7569..c999ebc 100644
--- a/package.json
+++ b/package.json
@@ -1,22 +1,39 @@
 {
-	"name"        : "sockjs-client",
-	"author"      : "Marek Majkowski",
-    "version"     : "0.0.0-unreleasable",
-    "license"     : "MIT",
-    "description" : "SockJS-client is a browser JavaScript library that provides a WebSocket-like object. SockJS gives you a coherent, cross-browser, Javascript API which creates a low latency, full duplex, cross-domain communication channel between the browser and the web server.",
-    "keywords"    : ["websockets", "websocket"],
-    "homepage"    : "http://sockjs.org",
-
-    "repository": {"type" : "git",
-                   "url" : "https://github.com/sockjs/sockjs-client.git"},
-    "devDependencies": {
-        "uglify-js"     : "1.2.5",
-        "coffee-script" : "1.2.x",
-        "optimist"      : "0.3.5",
-        "node-static"   : "0.5.9"
-    },
-    "scripts": {
-        "test": ""
-    },
-    "private": true
+  "name": "sockjs-client",
+  "description": "SockJS-client is a browser JavaScript library that provides a WebSocket-like object. SockJS gives you a coherent, cross-browser, Javascript API which creates a low latency, full duplex, cross-domain communication channel between the browser and the web server.",
+  "version": "0.3.4",
+  "author": "Marek Majkowski",
+  "bugs": {
+    "url": "https://github.com/sockjs/sockjs-client/issues"
+  },
+  "contributors": [
+    {
+      "name": "Bryce Kahle",
+      "email": "bkahle at gmail.com"
+    }
+  ],
+  "devDependencies": {
+    "coffee-script": "1.2.x",
+    "node-static": "0.5.9",
+    "optimist": "0.3.5",
+    "sockjs": "^0.3.8",
+    "uglify-js": "1.2.5",
+    "mocha": "^1.18.2",
+    "zuul": "^1.6.4"
+  },
+  "homepage": "http://sockjs.org",
+  "keywords": [
+    "websockets",
+    "websocket"
+  ],
+  "license": "MIT",
+  "private": true,
+  "repository": {
+    "type": "git",
+    "url": "https://github.com/sockjs/sockjs-client.git"
+  },
+  "scripts": {
+    "test": "./node_modules/zuul/bin/zuul -- tests/html/lib/unittests.js tests/html/lib/domtests.js tests/html/lib/endtoendtests.js tests/html/lib/protocols.js",
+    "test_local": "./node_modules/zuul/bin/zuul --local 9090 --ui qunit -- tests/html/lib/unittests.js tests/html/lib/domtests.js tests/html/lib/endtoendtests.js tests/html/lib/protocols.js"
+  }
 }
diff --git a/tests/html/lib/.placeholder b/tests/html/lib/.placeholder
deleted file mode 100644
index e69de29..0000000
diff --git a/tests/html/src/domtests.coffee b/tests/html/src/domtests.coffee
index 0043cce..d5ed0e7 100644
--- a/tests/html/src/domtests.coffee
+++ b/tests/html/src/domtests.coffee
@@ -1,17 +1,7 @@
-module('Dom')
+QUnit.module('Dom')
 
 u = SockJS.getUtils()
 
-newIframe = (path = '/iframe.html') ->
-    # Requires to put:
-    #     document.domain = document.domain
-    # in HEAD, for IE7
-    hook = u.createHook()
-    err = ->
-        log('iframe error. bad.')
-    hook.iobj = u.createIframe(path + '?a=' + Math.random() + '#' + hook.id, err)
-    return hook
-
 onunload_test_factory = (code) ->
     return ->
         expect(3)
diff --git a/tests/html/src/endtoendtests.coffee b/tests/html/src/endtoendtests.coffee
index 91211a1..1a8d7db 100644
--- a/tests/html/src/endtoendtests.coffee
+++ b/tests/html/src/endtoendtests.coffee
@@ -1,10 +1,12 @@
-module('End to End')
+u = SockJS.getUtils()
+
+QUnit.module('End to End')
 
 factory_body_check = (protocol) ->
     if not SockJS[protocol] or not SockJS[protocol].enabled(client_opts.sockjs_opts)
         n = " " + protocol + " [unsupported by client]"
         test n, ->
-            log('Unsupported protocol (by client): "' + protocol + '"')
+            u.log('Unsupported protocol (by client): "' + protocol + '"')
     else
         asyncTest protocol, ->
             expect(5)
@@ -41,7 +43,7 @@ factory_body_check = (protocol) ->
                 hook.del()
                 start()
 
-# module('sockjs in head')
+# QUnit.module('sockjs in head')
 # body_protocols = ['iframe-eventsource',
 #             'iframe-htmlfile',
 #             'iframe-xhr-polling',
@@ -50,7 +52,7 @@ factory_body_check = (protocol) ->
 #     factory_body_check(protocol)
 
 
-module('connection errors')
+QUnit.module('connection errors')
 asyncTest "invalid url 404", ->
     expect(4)
     r = newSockJS('/invalid_url', 'jsonp-polling')
@@ -61,13 +63,13 @@ asyncTest "invalid url 404", ->
         ok(false)
     r.onclose = (e) ->
         if u.isXHRCorsCapable() < 4
-            equals(e.code, 1002)
-            equals(e.reason, 'Can\'t connect to server')
+            equal(e.code, 1002)
+            equal(e.reason, 'Can\'t connect to server')
         else
             # IE 7 doesn't look at /info, unfortunately
-            equals(e.code, 2000)
-            equals(e.reason, 'All transports failed')
-        equals(e.wasClean, false)
+            equal(e.code, 2000)
+            equal(e.reason, 'All transports failed')
+        equal(e.wasClean, false)
         start()
 
 asyncTest "invalid url port", ->
@@ -79,13 +81,13 @@ asyncTest "invalid url port", ->
         ok(false)
     r.onclose = (e) ->
         if u.isXHRCorsCapable() < 4
-            equals(e.code, 1002)
-            equals(e.reason, 'Can\'t connect to server')
+            equal(e.code, 1002)
+            equal(e.reason, 'Can\'t connect to server')
         else
             # IE 7 doesn't look at /info, unfortunately
-            equals(e.code, 2000)
-            equals(e.reason, 'All transports failed')
-        equals(e.wasClean, false)
+            equal(e.code, 2000)
+            equal(e.reason, 'All transports failed')
+        equal(e.wasClean, false)
         start()
 
 asyncTest "disabled websocket test", ->
@@ -96,9 +98,9 @@ asyncTest "disabled websocket test", ->
         r.onmessage = (e) ->
             ok(false)
         r.onclose = (e) ->
-            equals(e.code, 2000)
-            equals(e.reason, "All transports failed")
-            equals(e.wasClean, false)
+            equal(e.code, 2000)
+            equal(e.reason, "All transports failed")
+            equal(e.wasClean, false)
             start()
 
 asyncTest "close on close", ->
@@ -109,9 +111,9 @@ asyncTest "close on close", ->
     r.onmessage = (e) ->
         ok(false)
     r.onclose = (e) ->
-        equals(e.code, 3000)
-        equals(e.reason, "Go away!")
-        equals(e.wasClean, true)
+        equal(e.code, 3000)
+        equal(e.reason, "Go away!")
+        equal(e.wasClean, true)
         r.onclose = ->
             ok(false)
         r.close()
diff --git a/tests/html/src/protocols.coffee b/tests/html/src/protocols.coffee
new file mode 100644
index 0000000..8a72866
--- /dev/null
+++ b/tests/html/src/protocols.coffee
@@ -0,0 +1,12 @@
+protocols = ['websocket',
+        'xdr-streaming',
+        'xhr-streaming',
+        'iframe-eventsource',
+        'iframe-htmlfile',
+        'xdr-polling',
+        'xhr-polling',
+        'iframe-xhr-polling',
+        'jsonp-polling']
+
+for protocol in protocols
+    test_protocol_messages(protocol)
\ No newline at end of file
diff --git a/tests/html/src/tests.coffee b/tests/html/src/tests.coffee
index 3c2cd86..78bbff5 100755
--- a/tests/html/src/tests.coffee
+++ b/tests/html/src/tests.coffee
@@ -1,12 +1,14 @@
-protocols = ['websocket',
-        'xdr-streaming',
-        'xhr-streaming',
-        'iframe-eventsource',
-        'iframe-htmlfile',
-        'xdr-polling',
-        'xhr-polling',
-        'iframe-xhr-polling',
-        'jsonp-polling']
+u = SockJS.getUtils()
+
+newIframe = (path = '/iframe.html') ->
+    # Requires to put:
+    #     document.domain = document.domain
+    # in HEAD, for IE7
+    hook = u.createHook()
+    err = ->
+        u.log('iframe error. bad.')
+    hook.iobj = u.createIframe(path + '?a=' + Math.random() + '#' + hook.id, err)
+    return hook
 
 newSockJS = (path, protocol) ->
     url = if /^http/.test(path) then path else client_opts.url + path
@@ -21,18 +23,18 @@ echo_factory_factory = (protocol, messages) ->
         a = messages.slice(0)
         r = newSockJS('/echo', protocol)
         r.onopen = (e) ->
-            #log('onopen ' + e)
+            #u.log('onopen ' + e)
             ok(true)
             r.send(a[0])
         r.onmessage = (e) ->
-            #log('onmessage ' + e);
+            #u.log('onmessage ' + e);
             x = ''+a[0]
             if e.data != x
                 for i in [0...e.data.length]
                     if e.data.charCodeAt(i) != x.charCodeAt(i)
                         xx1 = ('0000' + x.charCodeAt(i).toString(16)).slice(-4)
                         xx2 = ('0000' + e.data.charCodeAt(i).toString(16)).slice(-4)
-                        log('source: \\u' + xx1 + ' differs from: \\u' + xx2)
+                        u.log('source: \\u' + xx1 + ' differs from: \\u' + xx2)
                         break
             equal(e.data, '' + a[0])
             a.shift()
@@ -195,7 +197,7 @@ batch_factory_factory = (protocol, messages) ->
             for msg in messages
                 r.send(msg)
         r.onmessage = (e) ->
-            equals(e.data, messages[counter])
+            equal(e.data, messages[counter])
             counter += 1
             if counter is messages.length
                 r.close()
@@ -229,7 +231,7 @@ batch_factory_factory_amp = (protocol, messages) ->
             for msg in messages
                 r.send(''+msg)
         r.onmessage = (e) ->
-            equals(e.data.length, Math.pow(2, messages[counter]), e.data)
+            equal(e.data.length, Math.pow(2, messages[counter]), e.data)
             counter += 1
             if counter is messages.length
                 r.close()
@@ -293,8 +295,8 @@ factor_user_close = (protocol) ->
             counter += 1
         r.onclose = (e) ->
             counter += 1
-            log('user_close ' + e.code + ' ' + e.reason)
-            equals(e.wasClean, true)
+            u.log('user_close ' + e.code + ' ' + e.reason)
+            equal(e.wasClean, true)
             ok(counter is 2)
             start()
 
@@ -308,9 +310,9 @@ factor_server_close = (protocol) ->
         r.onmessage = (e) ->
             ok(false)
         r.onclose = (e) ->
-            equals(e.code, 3000)
-            equals(e.reason, "Go away!")
-            equals(e.wasClean, true)
+            equal(e.code, 3000)
+            equal(e.reason, "Go away!")
+            equal(e.wasClean, true)
             start()
 
 # IE doesn't do array.indexOf...
@@ -321,14 +323,14 @@ arrIndexOf = (arr, obj) ->
      return -1
 
 test_protocol_messages = (protocol) ->
-    module(protocol)
+    QUnit.module(protocol)
     if not SockJS[protocol] or not SockJS[protocol].enabled()
         test "[unsupported by client]", ->
-                log('Unsupported protocol (by client): "' + protocol + '"')
+                ok(true, 'Unsupported protocol (by client): "' + protocol + '"')
     else if client_opts.disabled_transports and
           arrIndexOf(client_opts.disabled_transports, protocol) isnt -1
         test "[disabled by config]", ->
-                log('Disabled by config: "' + protocol + '"')
+                ok(true, 'Disabled by config: "' + protocol + '"')
     else
         asyncTest("echo1", factor_echo_basic(protocol))
         asyncTest("echo2", factor_echo_rich(protocol))
@@ -346,7 +348,3 @@ test_protocol_messages = (protocol) ->
 
         asyncTest("user close", factor_user_close(protocol))
         asyncTest("server close", factor_server_close(protocol))
-
-
-for protocol in protocols
-    test_protocol_messages(protocol)
diff --git a/tests/html/src/unittests.coffee b/tests/html/src/unittests.coffee
index cf7b340..79f1e1e 100644
--- a/tests/html/src/unittests.coffee
+++ b/tests/html/src/unittests.coffee
@@ -1,4 +1,4 @@
-module('Utils')
+QUnit.module('Utils')
 
 u = SockJS.getUtils()
 
diff --git a/tests/sockjs_app.js b/tests/sockjs_app.js
new file mode 100644
index 0000000..5a876bc
--- /dev/null
+++ b/tests/sockjs_app.js
@@ -0,0 +1,85 @@
+var sockjs = require('sockjs');
+
+exports.install = function(opts, server) {
+  var sjs_echo = sockjs.createServer(opts);
+  sjs_echo.on('connection', function(conn) {
+    console.log('    [+] echo open    ' + conn);
+    conn.on('close', function() {
+      console.log('    [-] echo close   ' + conn);
+    });
+    conn.on('data', function(m) {
+      var d  = JSON.stringify(m);
+      console.log('    [ ] echo message ' + conn,
+                  d.slice(0,64)+
+                  ((d.length > 64) ? '...' : ''));
+      conn.write(m);
+    });
+  });
+
+  var sjs_close = sockjs.createServer(opts);
+  sjs_close.on('connection', function(conn) {
+    console.log('    [+] clos open    ' + conn);
+    conn.close(3000, "Go away!");
+    conn.on('close', function() {
+      console.log('    [-] clos close   ' + conn);
+    });
+  });
+
+  var sjs_ticker = sockjs.createServer(opts);
+  sjs_ticker.on('connection', function(conn) {
+    console.log('    [+] ticker open   ' + conn);
+    var tref;
+    var schedule = function() {
+      conn.write('tick!');
+      tref = setTimeout(schedule, 1000);
+    };
+    tref = setTimeout(schedule, 1000);
+    conn.on('close', function() {
+      clearTimeout(tref);
+      console.log('    [-] ticker close   ' + conn);
+    });
+  });
+
+  var broadcast = {};
+  var sjs_broadcast = sockjs.createServer(opts);
+  sjs_broadcast.on('connection', function(conn) {
+    console.log('    [+] broadcast open ' + conn);
+    broadcast[conn.id] = conn;
+    conn.on('close', function() {
+      delete broadcast[conn.id];
+      console.log('    [-] broadcast close' + conn);
+    });
+    conn.on('data', function(m) {
+      console.log('    [-] broadcast message', m);
+      for(var id in broadcast) {
+          broadcast[id].write(m);
+      }
+    });
+  });
+
+  var sjs_amplify = sockjs.createServer(opts);
+  sjs_amplify.on('connection', function(conn) {
+    console.log('    [+] amp open    ' + conn);
+    conn.on('close', function() {
+      console.log('    [-] amp close   ' + conn);
+    });
+    conn.on('data', function(m) {
+      var n = Math.floor(Number(m));
+      n = (n > 0 && n < 19) ? n : 1;
+      console.log('    [ ] amp message: 2^' + n);
+      conn.write(Array(Math.pow(2, n)+1).join('x'));
+    });
+  });
+
+
+  sjs_echo.installHandlers(server, {prefix:'/echo',
+                                    response_limit: 4096});
+  sjs_echo.installHandlers(server, {prefix:'/disabled_websocket_echo',
+                                    websocket: false});
+  sjs_echo.installHandlers(server, {prefix:'/cookie_needed_echo',
+                                    jsessionid: true});
+  sjs_close.installHandlers(server, {prefix:'/close'});
+  sjs_ticker.installHandlers(server, {prefix:'/ticker'});
+  sjs_amplify.installHandlers(server, {prefix:'/amplify'});
+  sjs_broadcast.installHandlers(server, {prefix:'/broadcast'});
+};
diff --git a/tests/sockjs_server.js b/tests/sockjs_server.js
new file mode 100644
index 0000000..4a5a757
--- /dev/null
+++ b/tests/sockjs_server.js
@@ -0,0 +1,64 @@
+var http = require('http');
+var node_static = require('node-static');
+var sockjs_app = require('./sockjs_app');
+
+var port = process.env.ZUUL_PORT || 8081;
+var client_opts = {
+  // Address of a sockjs test server.
+  url: 'http://localhost:'+port,
+  sockjs_opts: {
+      devel: true,
+      debug: true,
+      // websocket:false
+      info: {cookie_needed:false}
+  }
+};
+
+var static_directory = new node_static.Server(__dirname + '/html');
+
+var server = http.createServer();
+server.addListener('request', function(req, res) {
+  if ( /\/slow-script.js/.test(req.url) ) {
+    res.setHeader('content-type', 'application/javascript');
+    res.writeHead(200);
+    setTimeout(function() {
+        res.end('var a = 1;\n');
+    }, 500);
+  } else if ( /\/streaming.txt/.test(req.url) ) {
+    res.setHeader('content-type', 'text/plain');
+    res.setHeader('Access-Control-Allow-Origin', '*');
+
+    res.writeHead(200);
+    res.write(Array(2049).join('a') + '\n');
+    setTimeout(function() {
+        res.end('b\n');
+    }, 250);
+  } else if ( /\/simple.txt/.test(req.url) ) {
+    res.setHeader('content-type', 'text/plain');
+    res.setHeader('Access-Control-Allow-Origin', '*');
+    res.writeHead(200);
+    res.end(Array(2049).join('a') + '\nb\n');
+  } else if (req.url === '/config.js') {
+    res.setHeader('content-type', 'application/javascript');
+    res.writeHead(200);
+    res.end('var client_opts = ' +
+            JSON.stringify(client_opts) + ';');
+  } else if (req.url === '/domain.js') {
+    res.setHeader('content-type', 'application/javascript');
+    res.writeHead(200);
+    res.end('document.domain = document.domain;');
+  } else {
+    static_directory.serve(req, res);
+  }
+});
+server.addListener('upgrade', function(req, res){
+  res.end();
+});
+
+sockjs_app.install({
+  sockjs_url: 'http://localhost:'+port+'/lib/sockjs.js',
+  websocket: true
+}, server);
+
+console.log(" [*] Listening on", port);
+server.listen(port);

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



More information about the Pkg-javascript-commits mailing list