Permalink
Browse files

Merge branch 'cons_without_new' of https://github.com/squaremo/sockjs…

  • Loading branch information...
2 parents e900174 + ec1632f commit b1d3b559b72c49f848e777c8bd5d87ee49f24cd2 @majek majek committed Dec 29, 2012
Showing with 17 additions and 4 deletions.
  1. +1 −1 lib/sockjs.js
  2. +16 −3 tests/html/src/tests.coffee
View
2 lib/sockjs.js
@@ -7,7 +7,7 @@
*/
var SockJS = function(url, dep_protocols_whitelist, options) {
- if (this === _window) {
+ if (!(this instanceof SockJS)) {
// makes `new` optional
return new SockJS(url, dep_protocols_whitelist, options);
}
View
19 tests/html/src/tests.coffee
@@ -8,18 +8,26 @@ protocols = ['websocket',
'iframe-xhr-polling',
'jsonp-polling']
-newSockJS = (path, protocol) ->
+url_and_options = (path, protocol) ->
url = if /^http/.test(path) then path else client_opts.url + path
options = jQuery.extend({}, client_opts.sockjs_opts)
if protocol
options.protocols_whitelist = [protocol]
+ [url, options]
+
+newSockJS = (path, protocol) ->
+ [url, options] = url_and_options(path, protocol)
return new SockJS(url, null, options)
-echo_factory_factory = (protocol, messages) ->
+cons_without_new = (path, protocol) ->
+ [url, options] = url_and_options(path, protocol)
+ return SockJS(url, null, options)
+
+echo_factory_factory = (protocol, messages, cons = newSockJS) ->
return ->
expect(2 + messages.length)
a = messages.slice(0)
- r = newSockJS('/echo', protocol)
+ r = cons('/echo', protocol)
r.onopen = (e) ->
#log('onopen ' + e)
ok(true)
@@ -47,6 +55,10 @@ echo_factory_factory = (protocol, messages) ->
ok(true)
start()
+factor_echo_without_new = (protocol) ->
+ messages = [ 'data' ]
+ return echo_factory_factory(protocol, messages, cons_without_new)
+
factor_echo_basic = (protocol) ->
messages = [ 'data' ]
return echo_factory_factory(protocol, messages)
@@ -290,6 +302,7 @@ test_protocol_messages = (protocol) ->
test "[disabled by config]", ->
log('Disabled by config: "' + protocol + '"')
else
+ asyncTest("echo0", factor_echo_without_new(protocol))
asyncTest("echo1", factor_echo_basic(protocol))
asyncTest("echo2", factor_echo_rich(protocol))
asyncTest("unicode", factor_echo_unicode(protocol))

0 comments on commit b1d3b55

Please sign in to comment.