[Pkg-javascript-commits] [sockjs-client] 92/434: Better, more powerful configuration for tests.
Tonnerre Lombard
tonnerre-guest at moszumanska.debian.org
Wed Jan 8 00:47:06 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 9a44ed988db930441bc6696a154f344d9862979e
Author: Marek Majkowski <majek04 at gmail.com>
Date: Fri Aug 19 17:58:52 2011 +0100
Better, more powerful configuration for tests.
---
tests/config.js | 11 ++++++++---
tests/html/example-cursors.html | 4 +---
tests/html/smoke-reconnect.html | 5 +----
tests/html/smoke-throughput.html | 5 +----
tests/html/src/tests.coffee | 39 +++++++++++++++++++++++++--------------
tests/server.js | 4 ++--
6 files changed, 38 insertions(+), 30 deletions(-)
diff --git a/tests/config.js b/tests/config.js
index a0d18c8..427c248 100644
--- a/tests/config.js
+++ b/tests/config.js
@@ -5,7 +5,12 @@ exports.config = {
port: 8080,
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'
+ client_opts: {
+ // May be set to empty string if you don't need to test
+ // cross-domain features. In other case set it to a full
+ // url, like: "http://localhost:8080"
+ url: 'http://localhost:8080',
+ disabled_transports: [],
+ sockjs_opts: {devel:true}
+ }
};
diff --git a/tests/html/example-cursors.html b/tests/html/example-cursors.html
index 0b5bf87..7eb577b 100644
--- a/tests/html/example-cursors.html
+++ b/tests/html/example-cursors.html
@@ -29,8 +29,6 @@
</code>
<script>
- sockjs_url += '/broadcast';
-
function log(a) {
if ('console' in window && 'log' in window.console) {
console.log(a);
@@ -41,7 +39,7 @@
}
- var sjs = new SockJS(sockjs_url);
+ var sjs = new SockJS(client_opts.url + '/broadcast', undefined, client_opts.sockjs_opts);
sjs.onopen = function() {
log('connected ' + sjs.protocol);
};
diff --git a/tests/html/smoke-reconnect.html b/tests/html/smoke-reconnect.html
index efe5ea5..e1f2011 100644
--- a/tests/html/smoke-reconnect.html
+++ b/tests/html/smoke-reconnect.html
@@ -40,9 +40,6 @@
</code>
<script>
- sockjs_url += '/echo';
- sockjs_opts = {devel:true, debug:false};
-
function log(a) {
if ('console' in window && 'log' in window.console) {
console.log(a);
@@ -66,7 +63,7 @@
function onclose(e) {
if (started && e.status === 1000) {
t0 = (new Date()).getTime();
- sjs = new SockJS(sockjs_url, protocol, sockjs_opts);
+ sjs = new SockJS(client_opts.url + '/echo', protocol, client_opts.sockjs_opts);
sjs.onopen = onopen
sjs.onclose = onclose;
} else {
diff --git a/tests/html/smoke-throughput.html b/tests/html/smoke-throughput.html
index 709ed8b..4a11bd4 100644
--- a/tests/html/smoke-throughput.html
+++ b/tests/html/smoke-throughput.html
@@ -40,9 +40,6 @@
</code>
<script>
- sockjs_url += '/echo';
- sockjs_opts = {devel:true, debug:true};
-
function log(a) {
if ('console' in window && 'log' in window.console) {
console.log(a);
@@ -80,7 +77,7 @@
$('#disconnect').attr('disabled', false);
var protocol = $('#transport').val() || undefined;
log('[connecting] ' + protocol);
- sjs = new SockJS(sockjs_url, protocol, sockjs_opts);
+ sjs = new SockJS(client_opts.url + '/echo', protocol, client_opts.sockjs_opts);
sjs.onopen = onopen
sjs.onclose = onclose;
sjs.onmessage = onmessage;
diff --git a/tests/html/src/tests.coffee b/tests/html/src/tests.coffee
index 8f2eb44..815e747 100644
--- a/tests/html/src/tests.coffee
+++ b/tests/html/src/tests.coffee
@@ -1,8 +1,12 @@
+newSockJS = (path, protocol) ->
+ url = if /^http/.test(path) then path else client_opts.url + path
+ return new SockJS(url, [protocol], client_opts.sockjs_opts)
+
echo_factory_factory = (protocol, messages) ->
return ->
expect(2 + messages.length)
a = messages.slice(0)
- r = new SockJS(sockjs_url + '/echo', [protocol])
+ r = newSockJS('/echo', protocol)
r.onopen = (e) ->
log('onopen ' + e)
ok(true)
@@ -94,7 +98,7 @@ factor_echo_large_message = (protocol) ->
batch_factory_factory = (protocol, messages) ->
return ->
expect(3 + messages.length)
- r = new SockJS(sockjs_url + '/echo', [protocol])
+ r = newSockJS('/echo', protocol)
ok(r)
counter = 0
r.onopen = (e) ->
@@ -127,7 +131,7 @@ factor_batch_large = (protocol) ->
factor_user_close = (protocol) ->
return ->
expect(4)
- r = new SockJS(sockjs_url + '/echo', [protocol])
+ r = newSockJS('/echo', protocol)
ok(r)
counter = 0
r.onopen = (e) ->
@@ -147,7 +151,7 @@ factor_user_close = (protocol) ->
factor_server_close = (protocol) ->
return ->
expect(4)
- r = new SockJS(sockjs_url + '/close', [protocol])
+ r = newSockJS('/close', protocol)
ok(r)
r.onopen = (e) ->
ok(true)
@@ -161,7 +165,7 @@ factor_server_close = (protocol) ->
test_invalid_url_404 = (protocol) ->
return ->
expect(2)
- r = new SockJS(sockjs_url + '/invalid_url', [protocol])
+ r = newSockJS('/invalid_url', protocol)
ok(r)
counter =
r.onopen = (e) ->
@@ -176,7 +180,7 @@ test_invalid_url_404 = (protocol) ->
test_invalid_url_500 = (protocol) ->
return ->
expect(2)
- r = new SockJS(sockjs_url + '/500_error', [protocol])
+ r = newSockJS('/500_error', protocol)
ok(r)
r.onopen = (e) ->
fail(true)
@@ -188,7 +192,8 @@ test_invalid_url_500 = (protocol) ->
test_invalid_url_port = (protocol) ->
return ->
expect(2)
- r = new SockJS("http://127.0.0.1:1079", [protocol])
+ dl = document.location
+ r = newSockJS(dl.protocol + '//' + dl.hostname + ':1079', protocol)
ok(r)
r.onopen = (e) ->
fail(true)
@@ -198,16 +203,24 @@ test_invalid_url_port = (protocol) ->
start()
-
-
+# IE doesn't do array.indexOf...
+arrIndexOf = (arr, obj) ->
+ for i in [0...arr.length]
+ if arr[i] is obj
+ return i
+ return -1
test_protocol = (protocol) ->
module(protocol)
if not SockJS[protocol] or not SockJS[protocol].enabled()
- test "[unsupported]", ->
- log('Unsupported protocol: "' + protocol + '"')
+ test "[unsupported by client]", ->
+ log('Unsupported protocol (by client): "' + protocol + '"')
+ else if client_opts.disabled_transports and
+ arrIndexOf(client_opts.disabled_transports, protocol) isnt -1
+ test "[unsupported by server]", ->
+ log('Unsupported protocol (by server): "' + protocol + '"')
else
- asyncTest("echo", factor_echo_basic(protocol))
+ asyncTest("echo1", factor_echo_basic(protocol))
asyncTest("echo2", factor_echo_rich(protocol))
asyncTest("unicode", factor_echo_unicode(protocol))
asyncTest("special_chars", factor_echo_special_chars(protocol))
@@ -230,8 +243,6 @@ for protocol in protocols
test_protocol(protocol)
-
-
module('other')
test "amending url", ->
diff --git a/tests/server.js b/tests/server.js
index d321c21..b16b302 100644
--- a/tests/server.js
+++ b/tests/server.js
@@ -13,8 +13,8 @@ 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 + '";');
+ res.end('var client_opts = ' +
+ JSON.stringify(config.client_opts) + ';');
} else{
static_directory.serve(req, res);
}
--
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