[Pkg-javascript-commits] [sockjs-client] 232/350: Handle async errors better in tests

tonnerre at ancient-solutions.com tonnerre at ancient-solutions.com
Fri Aug 5 01:04:25 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 69832c2e5e71a865c8994232bc1b552715a42a2f
Author: Bryce Kahle <bkahle at gmail.com>
Date:   Fri Oct 24 14:19:25 2014 -0400

    Handle async errors better in tests
---
 tests/lib/batch-tests.js |  50 ++++++++++++++---
 tests/lib/echo-tests.js  |  55 ++++++++++++++-----
 tests/lib/end-to-end.js  |  81 +++++++++++++++++++++------
 tests/lib/iframe.js      |  76 ++++++++++++++++---------
 tests/lib/receivers.js   | 140 +++++++++++++++++++++++++++++++++++++++++------
 tests/lib/senders.js     |  51 ++++++++++++++---
 tests/lib/transports.js  |  51 +++++++++++++----
 7 files changed, 402 insertions(+), 102 deletions(-)

diff --git a/tests/lib/batch-tests.js b/tests/lib/batch-tests.js
index dd03420..e70f9a3 100644
--- a/tests/lib/batch-tests.js
+++ b/tests/lib/batch-tests.js
@@ -6,7 +6,8 @@ var expect = require('expect.js')
 
 function batchFactory(transport, messages, url) {
   return function(done) {
-    var title = this.runnable().fullTitle();
+    var test = this.runnable();
+    var title = test.fullTitle();
     debug('start', title);
     this.timeout(10000);
     var sjs = testUtils.newSockJs(url + '/echo', transport);
@@ -17,15 +18,31 @@ function batchFactory(transport, messages, url) {
       });
     };
     sjs.onmessage = function (e) {
-      expect(e.data).to.eql(messages[counter]);
+      try {
+        expect(e.data).to.eql(messages[counter]);
+      } catch (e) {
+        done(e);
+        sjs.close();
+        return;
+      }
+
       counter++;
       if (counter === messages.length) {
         sjs.close();
       }
     };
     sjs.onclose = function (e) {
-      expect(e.code).to.equal(1000);
-      expect(counter).to.equal(messages.length);
+      if (test.timedOut || test.duration) {
+        return;
+      }
+
+      try {
+        expect(e.code).to.equal(1000);
+        expect(counter).to.equal(messages.length);
+      } catch (e) {
+        done(e);
+        return;
+      }
       done();
       debug('end', title);
     };
@@ -39,7 +56,8 @@ module.exports.largeMessage = function(url, transport) {
 
 function amplifyFactory(transport, messages, url) {
   return function(done) {
-    var title = this.runnable().fullTitle();
+    var test = this.runnable();
+    var title = test.fullTitle();
     debug('start', title);
     this.timeout(10000);
     var sjs = testUtils.newSockJs(url + '/amplify', transport);
@@ -50,15 +68,31 @@ function amplifyFactory(transport, messages, url) {
       });
     };
     sjs.onmessage = function (e) {
-      expect(e.data).to.have.length(Math.pow(2, messages[counter]));
+      try {
+        expect(e.data).to.have.length(Math.pow(2, messages[counter]));
+      } catch (e) {
+        done(e);
+        sjs.close();
+        return;
+      }
       counter++;
       if (counter === messages.length) {
         sjs.close();
       }
     };
     sjs.onclose = function (e) {
-      expect(e.code).to.equal(1000);
-      expect(counter).to.equal(messages.length);
+      if (test.timedOut || test.duration) {
+        return;
+      }
+
+      try {
+        expect(e.code).to.equal(1000);
+        expect(counter).to.equal(messages.length);
+      } catch (e) {
+        done(e);
+        return;
+      }
+
       done();
       debug('end', title);
     };
diff --git a/tests/lib/echo-tests.js b/tests/lib/echo-tests.js
index 08e45f2..5096ab3 100644
--- a/tests/lib/echo-tests.js
+++ b/tests/lib/echo-tests.js
@@ -18,11 +18,18 @@ function echoFactory(transport, messages, url) {
       sjs.send(msgs[0]);
     };
     sjs.onmessage = function (e) {
-      if (test.timedOut) {
+      if (test.timedOut || test.duration) {
         return;
       }
       // TODO don't like having to force the element toString here
-      expect(e.data).to.eql('' + msgs[0]);
+      try {
+        expect(e.data).to.eql('' + msgs[0]);
+      } catch (e) {
+        done(e);
+        sjs.close();
+        return;
+      }
+
       msgs.shift();
       if (typeof msgs[0] === 'undefined') {
         sjs.close();
@@ -31,12 +38,18 @@ function echoFactory(transport, messages, url) {
       }
     };
     sjs.onclose = function (e) {
-      if (test.timedOut) {
+      if (test.timedOut || test.duration) {
+        return;
+      }
+
+      try {
+        expect(e.code).to.equal(1000);
+        expect(msgs).to.have.length(0);
+      } catch (e) {
+        done(e);
         return;
       }
 
-      expect(e.code).to.equal(1000);
-      expect(msgs).to.have.length(0);
       done();
       debug('end', title);
     };
@@ -109,7 +122,8 @@ module.exports.echoFromChild = function echoFromChild(url, transport) {
   it('echo from child', function (done) {
     this.timeout(10000);
 
-    var title = this.runnable().fullTitle();
+    var test = this.runnable();
+    var title = test.fullTitle();
     debug('start', title);
     var hook = testUtils.createIframe('/sockjs-in-parent.html');
     var sjs = testUtils.newSockJs(url + '/echo', transport);
@@ -127,7 +141,7 @@ module.exports.echoFromChild = function echoFromChild(url, transport) {
     hook.onsend = function () {
       debug('hook onsend');
       timeout = setTimeout(function() {
-        expect().fail('echo timeout');
+        done(new Error('echo timeout'));
         sjs.close();
         debug('end', title);
       }, 1000);
@@ -143,13 +157,28 @@ module.exports.echoFromChild = function echoFromChild(url, transport) {
     sjs.onmessage = function(e) {
       debug('hook sjs message, e.data');
       clearTimeout(timeout);
-      expect(e.data).to.equal('a');
-      expect(i).to.equal(2);
-      hook.iobj.cleanup();
-      hook.del();
-      sjs.close();
+      try {
+        expect(e.data).to.equal('a');
+        expect(i).to.equal(2);
+      } catch (e) {
+        done(e);
+      } finally {
+        hook.iobj.cleanup();
+        hook.del();
+        sjs.close();
+      }
     };
-    sjs.onclose = function() {
+    sjs.onclose = function(e) {
+      if (test.timedOut || test.duration) {
+        return;
+      }
+
+      try {
+        expect(e.code).to.equal(1000);
+      } catch (e) {
+        done(e);
+        return;
+      }
       debug('hook sjs close');
       done();
       debug('end', title);
diff --git a/tests/lib/end-to-end.js b/tests/lib/end-to-end.js
index 0e7194a..544f518 100644
--- a/tests/lib/end-to-end.js
+++ b/tests/lib/end-to-end.js
@@ -13,15 +13,27 @@ describe('End to End', function () {
 
   describe('Connection Errors', function () {
     it('invalid url 404', function (done) {
+      var test = this.runnable();
       var sjs = testUtils.newSockJs('/invalid_url', 'jsonp-polling');
       expect(sjs).to.be.ok();
       sjs.onopen = sjs.onmessage = function () {
-        expect().fail('Open/Message event should not fire for an invalid url');
+        done(new Error('Open/Message event should not fire for an invalid url'));
+        sjs.close();
       };
       sjs.onclose = function (e) {
-        expect(e.code).to.equal(1002);
-        expect(e.reason).to.equal('Cannot connect to server');
-        expect(e.wasClean).to.equal(false);
+        if (test.timedOut || test.duration) {
+          return;
+        }
+
+        try {
+          expect(e.code).to.equal(1002);
+          expect(e.reason).to.equal('Cannot connect to server');
+          expect(e.wasClean).to.equal(false);
+        } catch (e) {
+          done(e);
+          return;
+        }
+
         done();
       };
     });
@@ -33,6 +45,7 @@ describe('End to End', function () {
       return;
     } else {
       it('invalid url port', function (done) {
+        var test = this.runnable();
         var badUrl;
         if (global.location) {
           badUrl = global.location.protocol + '//' + global.location.hostname + ':1079';
@@ -43,46 +56,80 @@ describe('End to End', function () {
         var sjs = testUtils.newSockJs(badUrl, 'jsonp-polling');
         expect(sjs).to.be.ok();
         sjs.onopen = sjs.onmessage = function () {
-          expect().fail('Open/Message event should not fire for an invalid port');
+          done(new Error('Open/Message event should not fire for an invalid port'));
+          sjs.close();
         };
         sjs.onclose = function (e) {
-          expect(e.code).to.equal(1002);
-          expect(e.reason).to.equal('Cannot connect to server');
-          expect(e.wasClean).to.equal(false);
+          if (test.timedOut || test.duration) {
+            return;
+          }
+
+          try {
+            expect(e.code).to.equal(1002);
+            expect(e.reason).to.equal('Cannot connect to server');
+            expect(e.wasClean).to.equal(false);
+          } catch (e) {
+            done(e);
+            return;
+          }
+
           done();
         };
       });
     }
 
     it('disabled websocket test', function (done) {
+      var test = this.runnable();
       var sjs = testUtils.newSockJs('/disabled_websocket_echo', 'websocket');
       expect(sjs).to.be.ok();
       sjs.onopen = sjs.onmessage = function () {
-        expect().fail('Open/Message event should not fire for disabled websockets');
+        done(new Error('Open/Message event should not fire for disabled websockets'));
+        sjs.close();
       };
       sjs.onclose = function (e) {
-        expect(e.code).to.equal(2000);
-        expect(e.reason).to.equal('All transports failed');
-        expect(e.wasClean).to.equal(false);
+        if (test.timedOut || test.duration) {
+          return;
+        }
+
+        try {
+          expect(e.code).to.equal(2000);
+          expect(e.reason).to.equal('All transports failed');
+          expect(e.wasClean).to.equal(false);
+        } catch (e) {
+          done(e);
+          return;
+        }
         done();
       };
     });
 
     it('close on close', function (done) {
+      var test = this.runnable();
       var sjs = testUtils.newSockJs('/close');
       expect(sjs).to.be.ok();
       sjs.onopen = function () {
         expect(true).to.be.ok();
       };
       sjs.onmessage = function () {
-        expect().fail('Message should not be emitted');
+        done(new Error('Message should not be emitted'));
+        sjs.close();
       };
       sjs.onclose = function (e) {
-        expect(e.code).to.equal(3000);
-        expect(e.reason).to.equal('Go away!');
-        expect(e.wasClean).to.equal(true);
+        if (test.timedOut || test.duration) {
+          return;
+        }
+
+        try {
+          expect(e.code).to.equal(3000);
+          expect(e.reason).to.equal('Go away!');
+          expect(e.wasClean).to.equal(true);
+        } catch (e) {
+          done(e);
+          return;
+        }
+
         sjs.onclose = function () {
-          expect().fail();
+          done(new Error());
         };
         sjs.close();
         setTimeout(function () {
diff --git a/tests/lib/iframe.js b/tests/lib/iframe.js
index fc9ac20..3105949 100644
--- a/tests/lib/iframe.js
+++ b/tests/lib/iframe.js
@@ -3,6 +3,7 @@
 
 var expect = require('expect.js')
   , eventUtils = require('../../lib/utils/event')
+  , browser = require('../../lib/utils/browser')
   , transportList = require('../../lib/transport-list')
   , testUtils = require('./test-utils')
   , echoTests = require('./echo-tests')
@@ -18,10 +19,19 @@ function onunloadTest (code, done) {
   };
   hook.load = function () {
     i++;
-    return setTimeout(function () { hook.iobj.cleanup(); }, 1);
+    return setTimeout(function () {
+      hook.iobj.cleanup();
+    }, 1);
   };
   hook.unload = function () {
-    expect(i).to.equal(2);
+    try {
+      expect(i).to.equal(2);
+    } catch (e) {
+      done(e);
+      hook.del();
+      return;
+    }
+
     hook.del();
     done();
   };
@@ -29,33 +39,37 @@ function onunloadTest (code, done) {
 
 describe('iframe', function () {
   if (!IframeTransport.enabled()) {
-    it('[unsupported]', function () { expect(true).to.be.ok(); });
+    it('[unsupported]');
     return;
   }
 
-  it('onunload', function (done) {
-    this.timeout(5000);
-    onunloadTest("function attachEvent(event, listener) {" +
-      "    if (typeof window.addEventListener !== 'undefined') {" +
-      "        window.addEventListener(event, listener, false);" +
-      "    } else {" +
-      "        document.attachEvent('on' + event, listener);" +
-      "        window.attachEvent('on' + event, listener);" +
-      "    }" +
-      "}" +
-      "attachEvent('load', function(){" +
-      "    hook.load();" +
-      "});" +
-      "var w = 0;" +
-      "var run = function(){" +
-      "    if(w === 0) {" +
-      "        w = 1;" +
-      "        hook.unload();" +
-      "    }" +
-      "};" +
-      "attachEvent('beforeunload', run);" +
-      "attachEvent('unload', run);", done);
-  });
+  if (browser.isOpera()) {
+    it('onunload [unsupported]');
+  } else {
+    it('onunload', function (done) {
+      this.timeout(5000);
+      onunloadTest("function attachEvent(event, listener) {" +
+        "    if (typeof window.addEventListener !== 'undefined') {" +
+        "        window.addEventListener(event, listener, false);" +
+        "    } else {" +
+        "        document.attachEvent('on' + event, listener);" +
+        "        window.attachEvent('on' + event, listener);" +
+        "    }" +
+        "}" +
+        "attachEvent('load', function(){" +
+        "    hook.load();" +
+        "});" +
+        "var w = 0;" +
+        "var run = function(){" +
+        "    if(w === 0) {" +
+        "        w = 1;" +
+        "        hook.unload();" +
+        "    }" +
+        "};" +
+        "attachEvent('beforeunload', run);" +
+        "attachEvent('unload', run);", done);
+    });
+  }
 
   it('onmessage', function (done) {
     var hook = testUtils.createIframe();
@@ -90,7 +104,15 @@ describe('iframe', function () {
             hook.iobj.post(hook.id + ' ' + 's', testUtils.getSameOriginUrl());
             break;
           case 'e':
-            expect(i).to.equal(2);
+            try {
+              expect(i).to.equal(2);
+            } catch (e) {
+              done(e);
+              hook.iobj.cleanup();
+              hook.del();
+              return;
+            }
+
             hook.iobj.cleanup();
             hook.del();
             done();
diff --git a/tests/lib/receivers.js b/tests/lib/receivers.js
index 3c7b62e..823c969 100644
--- a/tests/lib/receivers.js
+++ b/tests/lib/receivers.js
@@ -23,6 +23,7 @@ describe('Receivers', function () {
     });
 
     it('receives data', function (done) {
+      var test = this.runnable();
       JsonpReceiver.prototype._createScript = function () {
         var self = this;
         setTimeout(function () {
@@ -31,16 +32,32 @@ describe('Receivers', function () {
       };
       var jpr = new JsonpReceiver('test');
       jpr.on('close', function (code, reason) {
-        expect(reason).to.equal('network');
+        if (test.timedOut || test.duration) {
+          return;
+        }
+
+        try {
+          expect(reason).to.equal('network');
+        } catch (e) {
+          done(e);
+          return;
+        }
         done();
       });
       jpr.on('message', function (msg) {
-        expect(msg).to.equal('datadata');
+        try {
+          expect(msg).to.equal('datadata');
+        } catch (e) {
+          done(e);
+          jpr.abort();
+          return;
+        }
       });
     });
 
     it('will timeout', function (done) {
       this.timeout(500);
+      var test = this.runnable();
       JsonpReceiver.prototype._createScript = function () {
         var self = this;
         setTimeout(function () {
@@ -52,15 +69,26 @@ describe('Receivers', function () {
 
       var jpr = new JsonpReceiver('test');
       jpr.on('close', function (code, reason) {
-        expect(reason).to.contain('timeout');
+        if (test.timedOut || test.duration) {
+          return;
+        }
+
+        try {
+          expect(reason).to.contain('timeout');
+        } catch (e) {
+          done(e);
+          return;
+        }
         done();
       });
       jpr.on('message', function () {
-        expect().fail('No message should be sent');
+        done(new Error('No message should be sent'));
+        jpr.abort();
       });
     });
 
     it('aborts without sending a message', function (done) {
+      var test = this.runnable();
       JsonpReceiver.prototype._createScript = function () {
         var self = this;
         setTimeout(function () {
@@ -71,17 +99,28 @@ describe('Receivers', function () {
       };
       var jpr = new JsonpReceiver('test');
       jpr.on('close', function (code, reason) {
-        expect(reason).to.contain('aborted');
+        if (test.timedOut || test.duration) {
+          return;
+        }
+
+        try {
+          expect(reason).to.contain('aborted');
+        } catch (e) {
+          done(e);
+          return;
+        }
         done();
       });
       jpr.on('message', function () {
-        expect().fail('No message should be sent');
+        done(new Error('No message should be sent'));
+        jpr.abort();
       });
       jpr.abort();
     });
 
     it('will not report error if onerror triggered right before onreadystatechange (IE9)', function (done) {
       JsonpReceiver.scriptErrorTimeout = 300;
+      var test = this.runnable();
       JsonpReceiver.prototype._createScript = function () {
         var self = this;
         // simulate a normal JSONP response
@@ -93,11 +132,24 @@ describe('Receivers', function () {
 
       var jpr = new JsonpReceiver('test');
       jpr.on('close', function (code, reason) {
-        expect(reason).to.equal('network');
+        if (test.timedOut || test.duration) {
+          return;
+        }
+        try {
+          expect(reason).to.equal('network');
+        } catch (e) {
+          done(e);
+          return;
+        }
         done();
       });
       jpr.on('message', function (msg) {
-        expect(msg).to.equal('datadata');
+        try {
+          expect(msg).to.equal('datadata');
+        } catch (e) {
+          done(e);
+          jpr.abort();
+        }
       });
 
       // simulate script error
@@ -106,6 +158,7 @@ describe('Receivers', function () {
 
     it('will not report error if onerror triggered right after onreadystatechange (IE9)', function (done) {
       JsonpReceiver.scriptErrorTimeout = 100;
+      var test = this.runnable();
       JsonpReceiver.prototype._createScript = function () {
         var self = this;
         // simulate a normal JSONP response
@@ -117,11 +170,24 @@ describe('Receivers', function () {
 
       var jpr = new JsonpReceiver('test');
       jpr.on('close', function (code, reason) {
-        expect(reason).to.equal('network');
+        if (test.timedOut || test.duration) {
+          return;
+        }
+        try {
+          expect(reason).to.equal('network');
+        } catch (e) {
+          done(e);
+          return;
+        }
         done();
       });
       jpr.on('message', function (msg) {
-        expect(msg).to.equal('datadata');
+        try {
+          expect(msg).to.equal('datadata');
+        } catch (e) {
+          done(e);
+          jpr.abort();
+        }
       });
 
       // simulate script error
@@ -142,41 +208,81 @@ describe('Receivers', function () {
     });
 
     it('emits multiple messages for multi-line response', function (done) {
+      var test = this.runnable();
       var xhr = new XhrReceiver('test', XhrFake);
       var i = 0, responses = ['test', 'multiple', 'lines', '{}'];
       xhr.on('message', function (msg) {
-        expect(msg).to.equal(responses[i]);
+        try {
+          expect(msg).to.equal(responses[i]);
+        } catch (e) {
+          done(e);
+          xhr.abort();
+          return;
+        }
         i++;
       });
       xhr.on('close', function (code, reason) {
-        expect(reason).to.equal('network');
+        if (test.timedOut || test.duration) {
+          return;
+        }
+        try {
+          expect(reason).to.equal('network');
+        } catch (e) {
+          done(e);
+          return;
+        }
         done();
       });
       xhr._chunkHandler(200, 'test\nmultiple\nlines');
     });
 
     it('emits no messages for an empty string response', function (done) {
+      var test = this.runnable();
       var xhr = new XhrReceiver('test', XhrFake);
       var i = 0, responses = ['{}'];
       xhr.on('message', function (msg) {
-        expect(i).to.be.lessThan(responses.length);
-        expect(msg).to.equal(responses[i]);
+        try {
+          expect(i).to.be.lessThan(responses.length);
+          expect(msg).to.equal(responses[i]);
+        } catch (e) {
+          done(e);
+          xhr.abort();
+          return;
+        }
         i++;
       });
       xhr.on('close', function (code, reason) {
-        expect(reason).to.equal('network');
+        if (test.timedOut || test.duration) {
+          return;
+        }
+        try {
+          expect(reason).to.equal('network');
+        } catch (e) {
+          done(e);
+          return;
+        }
         done();
       });
       xhr._chunkHandler(200, '');
     });
 
     it('aborts without sending a message', function (done) {
+      var test = this.runnable();
       var xhr = new XhrReceiver('test', XhrFake);
       xhr.on('message', function () {
-        expect().fail();
+        done(new Error());
+        xhr.abort();
       });
       xhr.on('close', function (code, reason) {
-        expect(reason).to.equal('user');
+        if (test.timedOut || test.duration) {
+          return;
+        }
+        try {
+          expect(reason).to.equal('user');
+        } catch (e) {
+          done(e);
+          return;
+        }
         done();
       });
       xhr.abort();
diff --git a/tests/lib/senders.js b/tests/lib/senders.js
index 063be73..868f6e6 100644
--- a/tests/lib/senders.js
+++ b/tests/lib/senders.js
@@ -9,10 +9,16 @@ var expect = require('expect.js')
 
 function ajaxSimple (Obj) {
   it('simple', function (done) {
+    var test = this.runnable();
     var x = new Obj('GET', testUtils.getSameOriginUrl() + '/simple.txt', null);
     x.on('finish', function (status, text) {
-      expect(text.length).to.equal(2051);
-      expect(text.slice(-2)).to.equal('b\n');
+      try {
+        expect(text.length).to.equal(2051);
+        expect(text.slice(-2)).to.equal('b\n');
+      } catch (e) {
+        done(e);
+        return;
+      }
       done();
     });
   });
@@ -25,18 +31,34 @@ function ajaxStreaming (Obj) {
   }
 
   it('streaming', function (done) {
+    var test = this.runnable();
     var x = new Obj('GET', testUtils.getSameOriginUrl() + '/streaming.txt', null);
     var i = 0;
     x.on('chunk', function (status, text) {
-      expect(status).to.equal(200);
+      try {
+        expect(status).to.equal(200);
+      } catch (e) {
+        done(e);
+        x.abort();
+        return;
+      }
       i++;
       // 2051 because of transparent proxies
       //expect([2049, 2051]).to.contain(text.length);
     });
     x.on('finish', function (status, text) {
-      expect(i).to.be.greaterThan(0);
-      expect(status).to.equal(200);
-      expect(text.slice(-4)).to.equal('a\nb\n');
+      if (test.timedOut || test.duration) {
+        return;
+      }
+
+      try {
+        expect(i).to.be.greaterThan(0);
+        expect(status).to.equal(200);
+        expect(text.slice(-4)).to.equal('a\nb\n');
+      } catch (e) {
+        done(e);
+        return;
+      }
       done();
     });
   });
@@ -44,15 +66,26 @@ function ajaxStreaming (Obj) {
 
 function wrongUrl(Obj, url, statuses) {
   it('wrong url ' + url, function (done) {
+    var test = this.runnable();
     // Selenium has a long timeout for when it can't connect to the port
     this.timeout(30000);
     var x = new Obj('GET', url, null);
     x.on('chunk', function (status, text) {
-      expect().fail('No chunk should be received: ' + status + ', ' + text);
+      done(new Error('No chunk should be received: ' + status + ', ' + text));
+      x.abort();
     });
     x.on('finish', function (status, text) {
-      expect(statuses).to.contain(status);
-      expect(text).not.to.be(undefined);
+      if (test.timedOut || test.duration) {
+        return;
+      }
+
+      try {
+        expect(statuses).to.contain(status);
+        expect(text).not.to.be(undefined);
+      } catch (e) {
+        done(e);
+        return;
+      }
       done();
     });
   });
diff --git a/tests/lib/transports.js b/tests/lib/transports.js
index 4e393f7..ab2b7af 100644
--- a/tests/lib/transports.js
+++ b/tests/lib/transports.js
@@ -75,24 +75,41 @@ function runTests(url, transport) {
 
 function userClose(url, transport) {
   it('user close', function (done) {
+    var test = this.runnable();
+    this.timeout(10000);
     var sjs = new SockJS(url + '/echo', null, transport);
     expect(sjs).to.be.ok();
     var counter = 0;
 
     sjs.onopen = function() {
       counter++;
-      expect(counter).to.equal(1);
-      sjs.close(3000, 'User message');
-      expect(counter).to.equal(1);
+      try {
+        expect(counter).to.equal(1);
+        sjs.close(3000, 'User message');
+        expect(counter).to.equal(1);
+      } catch (e) {
+        done(e);
+      }
     };
     sjs.onmessage = function() {
-      expect().fail();
+      done(new Error());
+      sjs.close();
       counter++;
     };
     sjs.onclose = function(e) {
+      if (test.timedOut || test.duration) {
+        return;
+      }
+
       counter++;
-      expect(e.wasClean).to.equal(true);
-      expect(counter).to.equal(2);
+      try {
+        expect(e.wasClean).to.equal(true);
+        expect(counter).to.equal(2);
+      } catch (e) {
+        done(e);
+        return;
+      }
+
       done();
     };
   });
@@ -100,6 +117,8 @@ function userClose(url, transport) {
 
 function serverClose(url, transport) {
   it('server close', function (done) {
+    var test = this.runnable();
+    this.timeout(10000);
     var sjs = new SockJS(url + '/close', null, transport);
     expect(sjs).to.be.ok();
     var i = 0;
@@ -107,13 +126,23 @@ function serverClose(url, transport) {
       i++;
     };
     sjs.onmessage = function() {
-      expect().fail();
+      done(new Error());
+      sjs.close();
     };
     sjs.onclose = function(e) {
-      expect(i).to.equal(1);
-      expect(e.code).to.equal(3000);
-      expect(e.reason).to.equal('Go away!');
-      expect(e.wasClean).to.equal(true);
+      if (test.timedOut || test.duration) {
+        return;
+      }
+
+      try {
+        expect(i).to.equal(1);
+        expect(e.code).to.equal(3000);
+        expect(e.reason).to.equal('Go away!');
+        expect(e.wasClean).to.equal(true);
+      } catch (e) {
+        done(e);
+        return;
+      }
       done();
     };
   });

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