[Pkg-javascript-commits] [sockjs-client] 141/350: Fix ws tests through zuul
tonnerre at ancient-solutions.com
tonnerre at ancient-solutions.com
Fri Aug 5 01:03:55 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 afd24d079549542106d131cc64c00519a723848a
Author: Bryce Kahle <bkahle at gmail.com>
Date: Wed Oct 15 16:53:29 2014 -0400
Fix ws tests through zuul
---
.eslintrc | 3 ++-
lib/main.js | 2 +-
lib/transport/iframe.js | 3 ++-
lib/version.js | 1 +
package.json | 2 +-
tests/browser.js | 1 +
tests/lib/iframe.js | 11 +----------
tests/lib/main-node.js | 5 ++---
tests/lib/main.js | 32 ++++++++------------------------
tests/lib/receivers.js | 13 +++++++++++++
tests/lib/senders.js | 16 +++++-----------
tests/lib/test-utils.js | 20 ++++++++++----------
tests/lib/transports.js | 1 -
tests/support/sockjs_server.js | 3 ++-
14 files changed, 49 insertions(+), 64 deletions(-)
diff --git a/.eslintrc b/.eslintrc
index 59c08d6..2bbe258 100644
--- a/.eslintrc
+++ b/.eslintrc
@@ -13,6 +13,7 @@
"globals": {
"describe": true,
"before": true,
- "it": true
+ "it": true,
+ "after": true
}
}
diff --git a/lib/main.js b/lib/main.js
index f851652..814cdf2 100644
--- a/lib/main.js
+++ b/lib/main.js
@@ -145,7 +145,7 @@ SockJS.prototype.send = function(data) {
this._transport.send(escape.quote(data));
};
-SockJS.version = '1.0.0-alpha1';
+SockJS.version = require('./version');
SockJS.CONNECTING = 0;
SockJS.OPEN = 1;
diff --git a/lib/transport/iframe.js b/lib/transport/iframe.js
index c78b6fa..989344a 100644
--- a/lib/transport/iframe.js
+++ b/lib/transport/iframe.js
@@ -11,6 +11,7 @@
var util = require('util')
, JSON3 = require('json3')
, EventEmitter = require('events').EventEmitter
+ , version = require('../version')
, originUtils = require('../utils/origin')
, iframeUtils = require('../utils/iframe')
, eventUtils = require('../utils/event')
@@ -78,7 +79,7 @@ IframeTransport.prototype._message = function(e) {
this.iframeObj.loaded();
// window global dependency
this.postMessage('s', JSON3.stringify([
- global.SockJS.version
+ version
, this.transport
, this.transUrl
, this.baseUrl
diff --git a/lib/version.js b/lib/version.js
new file mode 100644
index 0000000..f66632a
--- /dev/null
+++ b/lib/version.js
@@ -0,0 +1 @@
+module.exports = '1.0.0-alpha1';
diff --git a/package.json b/package.json
index 7dbc908..e81db5c 100644
--- a/package.json
+++ b/package.json
@@ -40,7 +40,7 @@
"proxyquire": "~1.0.1",
"sockjs": "^0.3.9",
"vinyl-source-stream": "^0.1.1",
- "zuul": "^1.11.2"
+ "zuul": "git://github.com/brycekahle/zuul#fix-ws"
},
"homepage": "http://sockjs.org",
"keywords": [
diff --git a/tests/browser.js b/tests/browser.js
index b18645c..c0d9d5d 100644
--- a/tests/browser.js
+++ b/tests/browser.js
@@ -4,6 +4,7 @@ require('../lib/shims');
// prevent global leak warnings on this
global._jp = {};
+global._sockjs_global = null;
require('./lib/main');
require('./lib/utils');
diff --git a/tests/lib/iframe.js b/tests/lib/iframe.js
index 30910c5..d5aafca 100644
--- a/tests/lib/iframe.js
+++ b/tests/lib/iframe.js
@@ -7,13 +7,6 @@ var expect = require('expect.js')
, IframeTransport = require('../../lib/transport/iframe')
;
-var originUrl;
-if (global.location) {
- originUrl = global.location.origin;
-} else {
- originUrl = 'http://localhost:8081';
-}
-
function onunloadTest (code, done) {
var hook = testUtils.createIframe();
var i = 0;
@@ -39,7 +32,6 @@ describe('iframe', function () {
}
it('onunload', function (done) {
- this.runnable().globals(['_sockjs_global']);
this.timeout(5000);
onunloadTest("function attachEvent(event, listener) {" +
" if (typeof window.addEventListener !== 'undefined') {" +
@@ -64,7 +56,6 @@ describe('iframe', function () {
});
it('onmessage', function (done) {
- this.runnable().globals(['_sockjs_global']);
var hook = testUtils.createIframe();
var i = 0;
hook.open = function () {
@@ -94,7 +85,7 @@ describe('iframe', function () {
case 's':
hook.iobj.loaded();
i++;
- hook.iobj.post(hook.id + ' ' + 's', originUrl);
+ hook.iobj.post(hook.id + ' ' + 's', testUtils.getOriginUrl());
break;
case 'e':
expect(i).to.equal(2);
diff --git a/tests/lib/main-node.js b/tests/lib/main-node.js
index 92ea0b7..e125db3 100644
--- a/tests/lib/main-node.js
+++ b/tests/lib/main-node.js
@@ -3,7 +3,6 @@
var expect = require('expect.js')
, proxyquire = require('proxyquire')
, SecurityError = require('../../lib/error/securityerror')
- , SockJS = require('../../lib/entry')
;
describe('SockJS', function() {
@@ -16,7 +15,7 @@ describe('SockJS', function() {
}});
var sjs = proxyquire('../../lib/entry', { './main': main });
expect(function () {
- sjs('http://sockjs.org');
+ sjs('http://localhost');
}).to.throwException(function (e) {
expect(e).to.be.a(SecurityError);
});
@@ -24,4 +23,4 @@ describe('SockJS', function() {
});
});
-});
\ No newline at end of file
+});
diff --git a/tests/lib/main.js b/tests/lib/main.js
index bb046ea..169e63b 100644
--- a/tests/lib/main.js
+++ b/tests/lib/main.js
@@ -3,21 +3,19 @@
'use strict';
var expect = require('expect.js')
- // , proxyquire = require('proxyquire')
- // , SecurityError = require('../../lib/error/securityerror')
, SockJS = require('../../lib/entry')
;
describe('SockJS', function() {
describe('Constructor', function () {
it('should support construction without new', function () {
- var s = SockJS('http://sockjs.org');
+ var s = SockJS('http://localhost');
expect(s).to.be.a(SockJS);
});
it('create a valid WebSocket object', function () {
- var s = new SockJS('http://sockjs.org');
- expect(s).to.have.property('url', 'http://sockjs.org');
+ var s = new SockJS('http://localhost');
+ expect(s).to.have.property('url', 'http://localhost');
expect(s).to.have.property('readyState', SockJS.CONNECTING);
expect(s).to.have.property('extensions', '');
expect(s).to.have.property('protocol', '');
@@ -26,7 +24,7 @@ describe('SockJS', function() {
describe('WebSocket specification step #1', function () {
it('should throw SyntaxError for an invalid url', function () {
expect(function () {
- new SockJS('//sockjs.org');
+ new SockJS('//localhost');
}).to.throwException(function (e) {
expect(e).to.be.a(SyntaxError);
});
@@ -40,13 +38,13 @@ describe('SockJS', function() {
it('should throw SyntaxError when the url contains a querystring or fragment', function () {
expect(function () {
- new SockJS('http://sockjs.org/?test');
+ new SockJS('http://localhost/?test');
}).to.throwException(function (e) {
expect(e).to.be.a(SyntaxError);
});
expect(function () {
- new SockJS('http://sockjs.org/#test');
+ new SockJS('http://localhost/#test');
}).to.throwException(function (e) {
expect(e).to.be.a(SyntaxError);
});
@@ -54,31 +52,17 @@ describe('SockJS', function() {
it('should throw SyntaxError for an invalid protocol', function () {
expect(function () {
- new SockJS('ftp://sockjs.org');
+ new SockJS('ftp://localhost');
}).to.throwException(function (e) {
expect(e).to.be.a(SyntaxError);
});
});
});
- // describe('WebSocket specification step #2', function () {
- // it('should throw SecurityError for an insecure url from a secure page', function () {
- // var main = proxyquire('../../lib/main', { './polyfills/location': {
- // protocol: 'https'
- // }});
- // var sjs = proxyquire('../../lib/entry', { './main': main });
- // expect(function () {
- // sjs('http://sockjs.org');
- // }).to.throwException(function (e) {
- // expect(e).to.be.a(SecurityError);
- // });
- // });
- // });
-
describe('WebSocket specification step #5', function () {
it('should throw SyntaxError for duplicated protocols', function () {
expect(function () {
- new SockJS('http://sockjs.org', ['test', 'test']);
+ new SockJS('http://localhost', ['test', 'test']);
}).to.throwException(function (e) {
expect(e).to.be.a(SyntaxError);
});
diff --git a/tests/lib/receivers.js b/tests/lib/receivers.js
index ea159ce..2f223c5 100644
--- a/tests/lib/receivers.js
+++ b/tests/lib/receivers.js
@@ -9,10 +9,18 @@ var expect = require('expect.js')
describe('Receivers', function () {
describe('jsonp', function () {
+ var oldTimeout = JsonpReceiver.timeout;
+ var oldScriptTimeout = JsonpReceiver.scriptErrorTimeout;
+ var scriptFunc = JsonpReceiver.prototype._createScript;
before(function () {
JsonpReceiver.prototype._createScript = function () {};
JsonpReceiver.timeout = 300;
});
+ after(function () {
+ JsonpReceiver.timeout = oldTimeout;
+ JsonpReceiver.scriptErrorTimeout = oldScriptTimeout;
+ JsonpReceiver.prototype._createScript = scriptFunc;
+ });
it('receives data', function (done) {
JsonpReceiver.prototype._createScript = function () {
@@ -120,9 +128,14 @@ describe('Receivers', function () {
});
describe('xhr', function () {
+ var oldTimeout;
before(function () {
+ oldTimeout = XhrFake.timeout;
XhrFake.timeout = 100;
});
+ after(function () {
+ XhrFake.timeout = oldTimeout;
+ });
it('emits multiple messages for multi-line response', function (done) {
var xhr = new XhrReceiver('test', XhrFake);
diff --git a/tests/lib/senders.js b/tests/lib/senders.js
index 3faa432..80edf88 100644
--- a/tests/lib/senders.js
+++ b/tests/lib/senders.js
@@ -1,20 +1,14 @@
'use strict';
var expect = require('expect.js')
+ , testUtils = require('./test-utils')
, XhrLocal = require('../../lib/transport/sender/xhr-local')
, Xdr = require('../../lib/transport/sender/xdr')
;
-var originUrl;
-if (global.location) {
- originUrl = global.location.origin;
-} else {
- originUrl = 'http://localhost:8081';
-}
-
function ajaxSimple (Obj) {
it('simple', function (done) {
- var x = new Obj('GET', originUrl + '/simple.txt', null);
+ var x = new Obj('GET', testUtils.getOriginUrl() + '/simple.txt', null);
x.on('finish', function (status, text) {
expect(text.length).to.equal(2051);
expect(text.slice(-2)).to.equal('b\n');
@@ -25,7 +19,7 @@ function ajaxSimple (Obj) {
function ajaxStreaming (Obj) {
it('streaming', function (done) {
- var x = new Obj('GET', originUrl + '/streaming.txt', null);
+ var x = new Obj('GET', testUtils.getOriginUrl() + '/streaming.txt', null);
x.on('chunk', function (status, text) {
expect(status).to.equal(200);
expect(text.length).to.be.lessThan(2050);
@@ -72,7 +66,7 @@ describe('Senders', function () {
ajaxSimple(XhrLocal);
ajaxStreaming(XhrLocal);
wrongPort(XhrLocal);
- wrongUrl(XhrLocal, originUrl + '/wrong_url_indeed.txt', [0, 404]);
+ wrongUrl(XhrLocal, testUtils.getOriginUrl() + '/wrong_url_indeed.txt', [0, 404]);
});
describe('xdr', function () {
@@ -83,6 +77,6 @@ describe('Senders', function () {
ajaxSimple(Xdr);
ajaxStreaming(Xdr);
wrongPort(Xdr);
- wrongUrl(Xdr, originUrl + '/wrong_url_indeed.txt', [0]);
+ wrongUrl(Xdr, testUtils.getOriginUrl() + '/wrong_url_indeed.txt', [0]);
});
});
diff --git a/tests/lib/test-utils.js b/tests/lib/test-utils.js
index eb1f771..62c098d 100644
--- a/tests/lib/test-utils.js
+++ b/tests/lib/test-utils.js
@@ -5,18 +5,18 @@ var SockJS = require('../../lib/entry')
, random = require('../../lib/utils/random')
;
-var originUrl;
-if (global.location) {
- originUrl = global.location.origin;
-} else {
- originUrl = 'http://localhost:8081';
-}
-
var MPrefix = '_sockjs_global';
module.exports = {
- getUrl: function (path) {
- return /^http/.test(path) ? path : originUrl + path;
+ getOriginUrl: function () {
+ if (global.location) {
+ return global.location.origin;
+ }
+ return 'http://localhost:8081';
+ }
+
+, getUrl: function (path) {
+ return /^http/.test(path) ? path : this.getOriginUrl() + path;
}
, newSockJs: function (path, transport) {
@@ -25,7 +25,7 @@ module.exports = {
, createHook: function () {
var windowId = 'a' + random.string(8);
- if (!(MPrefix in global)) {
+ if (!global[MPrefix]) {
var map = {};
global[MPrefix] = function(windowId) {
if (!(windowId in map)) {
diff --git a/tests/lib/transports.js b/tests/lib/transports.js
index 2c7b971..656c13e 100644
--- a/tests/lib/transports.js
+++ b/tests/lib/transports.js
@@ -9,7 +9,6 @@ var expect = require('expect.js')
function echoFactory(transport, messages) {
return function (done) {
this.timeout(10000);
- this.runnable().globals(['_sockjs_global']);
var msgs = messages.slice(0);
var sjs = testUtils.newSockJs('/echo', transport);
diff --git a/tests/support/sockjs_server.js b/tests/support/sockjs_server.js
index 71b17c0..3010738 100644
--- a/tests/support/sockjs_server.js
+++ b/tests/support/sockjs_server.js
@@ -50,7 +50,7 @@ server.addListener('request', function(req, res) {
}
res.setHeader('content-type', 'application/javascript');
res.writeHead(200);
- res.end('var client_opts = ' +
+ res.end('var clientOptions = ' +
JSON.stringify(clientOptions) + ';');
} else if (req.url === '/domain.js') {
res.setHeader('content-type', 'application/javascript');
@@ -61,6 +61,7 @@ server.addListener('request', function(req, res) {
}
});
server.addListener('upgrade', function(req, res){
+ console.log('upgrade kill');
res.end();
});
--
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