소스 검색

Found a bug in jasmine

which after being fixed removes the need for the sleep() command because you
can set the execution speed via jasmine's updateInterval attr
JC Brand 12 년 전
부모
커밋
b1ecdfdadc
2개의 변경된 파일9개의 추가작업 그리고 27개의 파일을 삭제
  1. 9 3
      Libraries/jasmine-1.3.1/jasmine.js
  2. 0 24
      spec/MainSpec.js

+ 9 - 3
Libraries/jasmine-1.3.1/jasmine.js

@@ -2080,11 +2080,17 @@ jasmine.Queue.prototype.next_ = function() {
         self.index++;
         self.index++;
 
 
         var now = new Date().getTime();
         var now = new Date().getTime();
-        if (self.env.updateInterval && now - self.env.lastUpdate > self.env.updateInterval) {
-          self.env.lastUpdate = now;
+        if (self.env.updateInterval) {
+            var timeout;
+            if (now - self.env.lastUpdate > self.env.updateInterval) {
+                timeout = 0;
+            } else {
+                timeout = self.env.updateInterval;
+            }
           self.env.setTimeout(function() {
           self.env.setTimeout(function() {
+            self.env.lastUpdate = now;
             self.next_();
             self.next_();
-          }, 0);
+          }, timeout);
         } else {
         } else {
           if (jasmine.Queue.LOOP_DONT_RECURSE && completedSynchronously) {
           if (jasmine.Queue.LOOP_DONT_RECURSE && completedSynchronously) {
             goAgain = true;
             goAgain = true;

+ 0 - 24
spec/MainSpec.js

@@ -71,19 +71,6 @@
         this.onConnected(mock_connection);
         this.onConnected(mock_connection);
         this.animate = false; // don't use animations
         this.animate = false; // don't use animations
 
 
-        // The timeout is used to slow down the tests so that one can see
-        // visually what is happening in the page.
-        var timeout = 0;
-        var sleep = function (delay) {
-            // Yes this is blocking and stupid, but these are tests and this is
-            // the easiest way to delay execution without having to use
-            // callbacks.
-            var start = new Date().getTime();
-            while (new Date().getTime() < start + delay) {
-                continue;
-            }
-        };
-
         describe("The Contacts Roster", $.proxy(function () {
         describe("The Contacts Roster", $.proxy(function () {
             it("is not shown by default", $.proxy(function () {
             it("is not shown by default", $.proxy(function () {
                 expect(this.rosterview.$el.is(':visible')).toEqual(false);
                 expect(this.rosterview.$el.is(':visible')).toEqual(false);
@@ -124,7 +111,6 @@
                         t = this.rosterview.$el.find('dt#pending-xmpp-contacts').siblings('dd.pending-xmpp-contact').text();
                         t = this.rosterview.$el.find('dt#pending-xmpp-contacts').siblings('dd.pending-xmpp-contact').text();
                         expect(t).toEqual(pend_names.slice(0,i+1).sort().join(''));
                         expect(t).toEqual(pend_names.slice(0,i+1).sort().join(''));
                     }
                     }
-                    sleep(timeout);
                 }, xmppchat));
                 }, xmppchat));
 
 
                 it("will have their own heading once they have been added", $.proxy(function () {
                 it("will have their own heading once they have been added", $.proxy(function () {
@@ -153,7 +139,6 @@
                         t = this.rosterview.$el.find('dt#xmpp-contacts').siblings('dd.current-xmpp-contact.offline').find('a.open-chat').text();
                         t = this.rosterview.$el.find('dt#xmpp-contacts').siblings('dd.current-xmpp-contact.offline').find('a.open-chat').text();
                         expect(t).toEqual(cur_names.slice(0,i+1).sort().join(''));
                         expect(t).toEqual(cur_names.slice(0,i+1).sort().join(''));
                     }
                     }
-                    sleep(timeout);
                 }, xmppchat));
                 }, xmppchat));
 
 
                 it("will have their own heading once they have been added", $.proxy(function () {
                 it("will have their own heading once they have been added", $.proxy(function () {
@@ -175,7 +160,6 @@
                         // Check that they are sorted alphabetically
                         // Check that they are sorted alphabetically
                         t = this.rosterview.$el.find('dt#xmpp-contacts').siblings('dd.current-xmpp-contact.online').find('a.open-chat').text();
                         t = this.rosterview.$el.find('dt#xmpp-contacts').siblings('dd.current-xmpp-contact.online').find('a.open-chat').text();
                         expect(t).toEqual(cur_names.slice(0,i+1).sort().join(''));
                         expect(t).toEqual(cur_names.slice(0,i+1).sort().join(''));
-                        sleep(timeout);
                     }
                     }
                 }, xmppchat));
                 }, xmppchat));
 
 
@@ -193,7 +177,6 @@
                         // Check that they are sorted alphabetically
                         // Check that they are sorted alphabetically
                         t = this.rosterview.$el.find('dt#xmpp-contacts').siblings('dd.current-xmpp-contact.dnd').find('a.open-chat').text();
                         t = this.rosterview.$el.find('dt#xmpp-contacts').siblings('dd.current-xmpp-contact.dnd').find('a.open-chat').text();
                         expect(t).toEqual(cur_names.slice(5,i+1).sort().join(''));
                         expect(t).toEqual(cur_names.slice(5,i+1).sort().join(''));
-                        sleep(timeout);
                     }
                     }
                 }, xmppchat));
                 }, xmppchat));
 
 
@@ -212,7 +195,6 @@
                         // Check that they are sorted alphabetically
                         // Check that they are sorted alphabetically
                         t = this.rosterview.$el.find('dt#xmpp-contacts').siblings('dd.current-xmpp-contact.away').find('a.open-chat').text();
                         t = this.rosterview.$el.find('dt#xmpp-contacts').siblings('dd.current-xmpp-contact.away').find('a.open-chat').text();
                         expect(t).toEqual(cur_names.slice(10,i+1).sort().join(''));
                         expect(t).toEqual(cur_names.slice(10,i+1).sort().join(''));
-                        sleep(timeout);
                     }
                     }
                 }, xmppchat));
                 }, xmppchat));
 
 
@@ -231,7 +213,6 @@
                         // Check that they are sorted alphabetically
                         // Check that they are sorted alphabetically
                         t = this.rosterview.$el.find('dt#xmpp-contacts').siblings('dd.current-xmpp-contact.unavailable').find('a.open-chat').text();
                         t = this.rosterview.$el.find('dt#xmpp-contacts').siblings('dd.current-xmpp-contact.unavailable').find('a.open-chat').text();
                         expect(t).toEqual(cur_names.slice(15, i+1).sort().join(''));
                         expect(t).toEqual(cur_names.slice(15, i+1).sort().join(''));
-                        sleep(timeout);
                     }
                     }
                 }, xmppchat));
                 }, xmppchat));
 
 
@@ -290,7 +271,6 @@
                         // be opened.
                         // be opened.
                         expect(this.showControlBox).toHaveBeenCalled();
                         expect(this.showControlBox).toHaveBeenCalled();
                     }
                     }
-                    sleep(timeout);
                 }, xmppchat));
                 }, xmppchat));
 
 
                 it("will have their own heading once they have been added", $.proxy(function () {
                 it("will have their own heading once they have been added", $.proxy(function () {
@@ -310,7 +290,6 @@
                     accept_button.click();
                     accept_button.click();
                     expect(view.acceptRequest).toHaveBeenCalled();
                     expect(view.acceptRequest).toHaveBeenCalled();
                     expect(this.connection.roster.authorize).toHaveBeenCalled();
                     expect(this.connection.roster.authorize).toHaveBeenCalled();
-                    sleep(timeout);
                 }, xmppchat));
                 }, xmppchat));
 
 
                 it("can have their requests denied by the user", $.proxy(function () {
                 it("can have their requests denied by the user", $.proxy(function () {
@@ -327,7 +306,6 @@
                     expect(this.connection.roster.unauthorize).toHaveBeenCalled();
                     expect(this.connection.roster.unauthorize).toHaveBeenCalled();
                     // There should now be one less contact
                     // There should now be one less contact
                     expect(this.roster.length).toEqual(num_contacts-1); 
                     expect(this.roster.length).toEqual(num_contacts-1); 
-                    sleep(timeout);
                 }, xmppchat));
                 }, xmppchat));
             }, xmppchat));
             }, xmppchat));
 
 
@@ -396,7 +374,6 @@
                     $el.click();
                     $el.click();
                     expect(view.openChat).toHaveBeenCalled();
                     expect(view.openChat).toHaveBeenCalled();
                     expect(this.chatboxes.length).toEqual(i+2);
                     expect(this.chatboxes.length).toEqual(i+2);
-                    sleep(timeout);
                 }
                 }
             }, xmppchat));
             }, xmppchat));
 
 
@@ -430,7 +407,6 @@
                     view.delegateEvents(); // We need to rebind all events otherwise our spy won't be called
                     view.delegateEvents(); // We need to rebind all events otherwise our spy won't be called
                     view.$el.find('.close-chatbox-button').click();
                     view.$el.find('.close-chatbox-button').click();
                     expect(view.closeChat).toHaveBeenCalled();
                     expect(view.closeChat).toHaveBeenCalled();
-                    sleep(timeout);
                 }
                 }
             }, xmppchat));
             }, xmppchat));