[Pkg-javascript-commits] [sockjs-client] 84/434: Simplified running qunit tests.

Tonnerre Lombard tonnerre-guest at moszumanska.debian.org
Wed Jan 8 00:47:04 UTC 2014


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

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

commit db6be97766554859f75bbb827ede488019a0c288
Author: Marek Majkowski <majek04 at gmail.com>
Date:   Wed Aug 17 15:11:19 2011 +0100

    Simplified running qunit tests.
    
    Instead of two separate ports we now serve everything on one port, the disadvantage is that it doesn't test cross-domain by default. But at least is way simpler and easier to configure.
---
 package.json                |   2 +-
 tests/config.js             |  15 +++--
 tests/config.js.example     |   2 -
 tests/html/config.js        |   2 -
 tests/server.js             |  31 ++++++++--
 tests/simple_http_server.js | 141 --------------------------------------------
 tests/sockjs_test_server.js |  93 -----------------------------
 7 files changed, 33 insertions(+), 253 deletions(-)

diff --git a/package.json b/package.json
index 62fc388..c4526e1 100644
--- a/package.json
+++ b/package.json
@@ -5,7 +5,7 @@
                 "uglify-js": "1.0.6",
                 "coffee-script": "1.1.1",
                 "optparse": "1.0.1",
-                "compress": "0.1.9",
+                "node-static": "0.5.9",
                 "sockjs": "*"
         }
 }
diff --git a/tests/config.js b/tests/config.js
index 90d70b7..a0d18c8 100644
--- a/tests/config.js
+++ b/tests/config.js
@@ -1,12 +1,11 @@
-exports.sockjs = {
+exports.config = {
     opts: {
-        sockjs_url: "http://127.0.0.1:8000/lib/sockjs.js"
+        sockjs_url: "/lib/sockjs.js"
     },
-    port: 9999,
-    host: '0.0.0.0'
-};
+    port: 8080,
+    host: '0.0.0.0',
 
-exports.static = {
-    port: 8000,
-    host: '0.0.0.0'
+    // May be set to empty string if you don't need to test
+    // cross-domain features.
+    sockjs_endpoint_url: 'http://localhost:8080'
 };
diff --git a/tests/config.js.example b/tests/config.js.example
deleted file mode 100644
index 0601c1a..0000000
--- a/tests/config.js.example
+++ /dev/null
@@ -1,2 +0,0 @@
-// by default just change the port to 9999
-var sockjs_url = document.location.protocol + '//' + document.location.hostname + ':9999';
diff --git a/tests/html/config.js b/tests/html/config.js
deleted file mode 100644
index 0601c1a..0000000
--- a/tests/html/config.js
+++ /dev/null
@@ -1,2 +0,0 @@
-// by default just change the port to 9999
-var sockjs_url = document.location.protocol + '//' + document.location.hostname + ':9999';
diff --git a/tests/server.js b/tests/server.js
index 12eafe2..d321c21 100644
--- a/tests/server.js
+++ b/tests/server.js
@@ -1,9 +1,28 @@
-var shs = require('./simple_http_server');
-var sts = require('./sockjs_test_server');
+var http = require('http');
+var node_static = require('node-static');
 
-var config = require('./config');
+var sockjs_app = require('./sockjs_app');
+var config = require('./config').config;
 
-config.static.topdir =  __dirname + '/html';
 
-shs.createServer(config.static);
-sts.createServer(config.sockjs);
+var static_directory = new node_static.Server(__dirname + '/html');
+
+
+var server = http.createServer();
+server.addListener('request', function(req, res) {
+                       if (req.url === '/config.js') {
+                           res.setHeader('content-type', 'application/javascript');
+                           res.writeHead(200);
+                           res.end('var sockjs_url = "' +
+                                   config.sockjs_endpoint_url + '";');
+                       } else{
+                           static_directory.serve(req, res);
+                       }
+                   });
+server.addListener('upgrade', function(req,res){
+                       res.end();
+                   });
+sockjs_app.install(config, server);
+
+console.log(" [*] Listening on", config.host + ':' + config.port);
+server.listen(config.port, config.host);
diff --git a/tests/simple_http_server.js b/tests/simple_http_server.js
deleted file mode 100644
index 158b7ea..0000000
--- a/tests/simple_http_server.js
+++ /dev/null
@@ -1,141 +0,0 @@
-var http = require('http');
-var url = require('url');
-var fs = require('fs');
-var path = require('path');
-var compress = require('compress');
-var crypto = require('crypto');
-
-var mimetypes = {
-    html: 'text/html',
-    htm: 'text/html',
-    js: 'application/javascript',
-    json: 'application/json',
-    css: 'text/css',
-    png: 'image/png',
-    jpeg: 'image/jpeg',
-    jpg: 'image/jpeg',
-    gif: 'image/gif'
-};
-
-var md5_hex = function (data) {
-    return crypto.createHash('md5').update(data).digest('hex');
-};
-
-
-var compressable_ct = ['text', 'application'];
-
-var create_handler = function(options) {
-    var req_fin = function(statusCode, req, res, content, encoding) {
-        var gz = '';
-        if (!encoding) encoding = 'utf-8';
-        if (compress && content &&
-            'accept-encoding' in req.headers &&
-            req.headers['accept-encoding'].split(',').indexOf('gzip') !== -1 &&
-            compressable_ct.indexOf(res.getHeader('Content-Type').split('/')[0]) !== -1) {
-            var gzip = new compress.Gzip;
-            gzip.init();
-            content = gzip.deflate(content, encoding) + gzip.end();
-            res.setHeader('Content-Encoding', 'gzip');
-            gz = '(gzip)';
-            encoding = 'binary';
-        }
-        if (content) {
-            // According to: http://code.google.com/speed/page-speed/docs/caching.html
-            // 'vary' effectively disables caching for IE. IE users are
-            // screwed anyway.
-            res.setHeader('Vary', 'Accept-Encoding');
-        }
-
-        if (options.cacheable) {
-            var cache_for = 365 * 24 * 60 * 60; // one year.
-            // See: http://code.google.com/speed/page-speed/docs/caching.html
-            res.setHeader('Cache-Control', 'public, max-age=' + cache_for);
-            var exp = new Date();
-            exp.setTime(exp.getTime() + cache_for * 1000);
-            res.setHeader('Expires', exp.toGMTString());
-        };
-
-        var cl = '';
-        if (content) {
-            cl = content.length;
-            res.setHeader('Content-Length', content.length);
-        } else {
-            content = '';
-        }
-        try {
-            res.writeHead(statusCode);
-            res.end(content, encoding);
-        } catch (x) {}
-
-        console.log(req.method, req.url, statusCode, cl, gz);
-    };
-
-    var fs_decorator = function(req, res, cb) {
-        return function (err, data) {
-            if (!err) {
-                try {
-                    cb(data);
-                } catch (x) {
-                    err = true;
-                    req_fin(500, req, res);
-                    console.log('error', x.stack);
-                }
-            } else {
-                // file doesn't exist or can't read it.
-                req_fin(404, req, res);
-            }
-        };
-    };
-
-    var handler = function(req, res) {
-        var filename = options.topdir + '/';
-        filename += url.parse(req.url).pathname.slice(1) || 'index.html';
-        var cb1, cb2;
-        cb1 = function(stats) {
-            var last_modified = stats.mtime.toGMTString();
-            if (req.headers['if-modified-since'] === last_modified) {
-                req_fin(304, req, res);
-                return;
-            }
-            if (!options.cacheable) {
-                res.setHeader('Last-Modified', last_modified);
-            }
-            fs.readFile(filename, fs_decorator(req, res, cb2));
-        };
-        cb2 = function (content) {
-            var md5 = '"' + md5_hex(content) + '"';
-            if (req.headers['if-none-match'] === md5) {
-                req_fin(304, req, res);
-                return;
-            }
-            var mimetype = mimetypes[path.extname(filename).slice(1)] || 'text/plain';
-            mimetype += '; charset=UTF-8';
-            res.setHeader('Content-Type', mimetype);
-            res.setHeader('ETag', md5);
-            req_fin(200, req, res, content);
-        };
-        fs.stat(filename, fs_decorator(req, res, cb1));
-    };
-    return handler;
-};
-
-var switches = [
-    ['-p', '--port PORT', 'Port to listen on (default: 8080)'],
-    ['-h', '--host HOST', 'Ip address to bind to (default: 0.0.0.0)'],
-    ['-d', '--dir DIR', 'Directory from which to serve files (default: .)']
-];
-
-exports.createServer = function(options) {
-    if (!options) options = {};
-    options.port = options.port || 8080;
-    options.host = options.host || '0.0.0.0';
-    options.topdir = options.topdir || '.';
-    options.cacheable = options.cacheable || false;
-
-    console.log(' [*] Serving directory:', JSON.stringify(options.topdir),
-                ' on:', options.host + ':' + options.port,
-                ' (cache is:', options.cacheable,')');
-    var server = http.createServer();
-    server.addListener('request', create_handler(options));
-    server.listen(options.port, options.host);
-}
diff --git a/tests/sockjs_test_server.js b/tests/sockjs_test_server.js
deleted file mode 100644
index ae51bee..0000000
--- a/tests/sockjs_test_server.js
+++ /dev/null
@@ -1,93 +0,0 @@
-var http = require('http');
-var url = require('url');
-
-var sockjs = require('sockjs');
-
-
-exports.createServer = function(config) {
-    var sjs_echo = new sockjs.Server(config.opts);
-    sjs_echo.on('open', function(conn){
-                    console.log('    [+] echo open    ' + conn);
-                    conn.on('close', function(e) {
-                                console.log('    [-] echo close   ' + conn, e);
-                            });
-                    conn.on('message', function(e) {
-                                var d  = JSON.stringify(e.data);
-                                console.log('    [ ] echo message ' + conn,
-                                            d.slice(0,64)+
-                                            ((d.length > 64) ? '...' : ''));
-                                conn.send(e.data);
-                            });
-                });
-
-    var sjs_close = new sockjs.Server(config.opts);
-    sjs_close.on('open', function(conn){
-                     console.log('    [+] clos open    ' + conn);
-                     conn.close(3000, "Go away!");
-                     conn.on('close', function(e) {
-                                 console.log('    [-] clos close   ' + conn, e);
-                             });
-                 });
-
-    var sjs_ticker = new sockjs.Server(config.opts);
-    sjs_ticker.on('open', function(conn){
-                      console.log('    [+] ticker open   ' + conn);
-                      var tref;
-                      var schedule = function() {
-                          conn.send('tick!');
-                          tref = setTimeout(schedule, 1000);
-                      };
-                      tref = setTimeout(schedule, 1000);
-                      conn.on('close', function(e) {
-                                  clearTimeout(tref);
-                                  console.log('    [-] ticker close   ' + conn, e);
-                              });
-                  });
-
-    var broadcast = {};
-    var sjs_broadcast = new sockjs.Server(config.opts);
-    sjs_broadcast.on('open', function(conn){
-                         console.log('    [+] broadcast open ' + conn);
-                         broadcast[conn.id] = conn;
-                         conn.on('close', function(e) {
-                                     delete broadcast[conn.id];
-                                     console.log('    [-] broadcast close' + conn, e);
-                                 });
-                         conn.on('message', function(e) {
-                                     console.log('    [-] broadcast message', e);
-                                     for(var id in broadcast) {
-                                         broadcast[id].send(e.data);
-                                     }
-                                 });
-                     });
-
-
-    var default_handler = function(req, res) {
-        res.statusCode = 404;
-        if (url.parse(req.url).pathname === '/500_error') {
-            res.statusCode = 500;
-        }
-        console.log(res.statusCode, req.url);
-        if (res.writeHead) {
-            res.writeHead(res.statusCode);
-            res.end("Error");
-        } else{
-            res.end();
-        }
-    };
-
-    console.log(" [*] config:", config.opts);
-    console.log(" [*] SockJS test server listening on",
-                config.host +':'+config.port);
-    var server = http.createServer();
-    server.addListener('request', default_handler);
-    server.addListener('upgrade', default_handler);
-
-
-    sjs_echo.installHandlers(server, {prefix:'[/]echo'});
-    sjs_close.installHandlers(server, {prefix:'[/]close'});
-    sjs_ticker.installHandlers(server, {prefix:'[/]ticker'});
-    sjs_broadcast.installHandlers(server, {prefix:'[/]broadcast'});
-
-    server.listen(config.port, config.host);
-};

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