cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From omef...@apache.org
Subject cordova-plugin-contacts git commit: CB-10881 Add extra logging to gather more information about tests behavior
Date Tue, 29 Mar 2016 21:42:10 GMT
Repository: cordova-plugin-contacts
Updated Branches:
  refs/heads/master 1c6668ef1 -> 8a08f75ca


CB-10881 Add extra logging to gather more information about tests behavior


Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/commit/8a08f75c
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/tree/8a08f75c
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/diff/8a08f75c

Branch: refs/heads/master
Commit: 8a08f75cad9e6b127884e9e5e2fae3e44225c702
Parents: 1c6668e
Author: Omar Mefire <omefire@gmail.com>
Authored: Tue Mar 29 12:51:46 2016 -0700
Committer: Omar Mefire <omefire@gmail.com>
Committed: Tue Mar 29 14:39:38 2016 -0700

----------------------------------------------------------------------
 tests/tests.js | 100 +++++++++++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 92 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/blob/8a08f75c/tests/tests.js
----------------------------------------------------------------------
diff --git a/tests/tests.js b/tests/tests.js
index 951a284..18def3a 100644
--- a/tests/tests.js
+++ b/tests/tests.js
@@ -49,7 +49,7 @@ exports.defineAutoTests = function() {
         };
 
     var MEDIUM_TIMEOUT = 30000;
-
+    
     var removeContact = function(done) {
         if (!gContactObj) {
             done();
@@ -116,6 +116,24 @@ exports.defineAutoTests = function() {
             removeNext(nextToRemove);
         }, done, obj);
     }
+    
+    // Convert seconds to HH:MM:SS format: http://stackoverflow.com/a/6313008/91607
+    function toHHMMSS(secs) {
+        var sec_num = parseInt(secs, 10); // don't forget the second param
+        var hours   = Math.floor(sec_num / 3600);
+        var minutes = Math.floor((sec_num - (hours * 3600)) / 60);
+        var seconds = sec_num - (hours * 3600) - (minutes * 60);
+
+        if (hours   < 10) {hours   = "0" + hours;}
+        if (minutes < 10) {minutes = "0" + minutes;}
+        if (seconds < 10) {seconds = "0" + seconds;}
+        var time = hours + ':' + minutes  + ':' + seconds;
+        return time;
+    }
+    
+    function getTimeInHHMMSS(date) {
+        return date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds();
+    }
 
     describe("Contacts (navigator.contacts)", function() {
         it("contacts.spec.1 should exist", function() {
@@ -198,7 +216,7 @@ exports.defineAutoTests = function() {
             });
 
             describe("with newly-created contact", function() {
-
+                
                 afterEach(function (done) {
                     removeContact(done);
                 });
@@ -452,6 +470,10 @@ exports.defineAutoTests = function() {
             });
 
             it("contacts.spec.22 update a contact", function(done) {
+
+                var startTime = new Date();
+                console.log("Spec22 - Start Time: " + getTimeInHHMMSS(startTime));
+                
                 // Save method is not supported on Windows platform
                 if (isWindows || isWindowsPhone8 || isIOSPermissionBlocked) {
                     pending();
@@ -477,7 +499,12 @@ exports.defineAutoTests = function() {
                     "birthday": aDay
                 };
 
-                var saveFail = fail.bind(null, done);
+                var saveFail = function() {
+                    var endTime = new Date();
+                    console.log("Spec22 - EndTime: " + getTimeInHHMMSS(endTime));
+                    console.log("Time Elapsed: " + toHHMMSS( (startTime.getTime() / 1000)
- (endTime.getTime() / 1000) ));
+                    fail.bind(null, done);
+                };
 
                 function updateSuccess(obj) {
                     expect(obj).toBeDefined();
@@ -486,6 +513,11 @@ exports.defineAutoTests = function() {
                     expect(obj.birthday.toDateString()).toBe(bDay.toDateString());
                     expect(obj.emails.length).toBe(1);
                     expect(obj.emails[0].value).toBe('here@there.com');
+                    
+                    var endTime = new Date();
+                    console.log("Spec22 - EndTime: " + getTimeInHHMMSS(endTime));
+                    console.log("Time Elapsed: " + toHHMMSS( (startTime.getTime() / 1000)
- (endTime.getTime() / 1000) ));
+                    
                     done();
                 }
 
@@ -511,13 +543,28 @@ exports.defineAutoTests = function() {
             });
 
             it("contacts.spec.23 calling remove on a contact that has an id of null should
return ContactError.UNKNOWN_ERROR", function(done) {
+                var startTime = new Date();
+                console.log("Spec23 - Start Time: " + getTimeInHHMMSS(startTime));
+                
+                var unexpectedSuccess = function() {
+                    var endTime = new Date();
+                    console.log("Spec23 - EndTime: " + getTimeInHHMMSS(endTime));
+                    console.log("Time Elapsed: " + toHHMMSS( (startTime / 1000) - (endTime
/ 1000) ));
+                    
+                    fail.bind(null, done);
+                };
                 var expectedFail = function(result) {
                     expect(result.code).toBe(ContactError.UNKNOWN_ERROR);
+                    
+                    var endTime = new Date();
+                    console.log("Spec23 - EndTime: " + getTimeInHHMMSS(endTime));
+                    console.log("Time Elapsed: " + toHHMMSS( (startTime / 1000) - (endTime
/ 1000) ));
+                    
                     done();
                 };
 
                 var rmContact = new Contact();
-                rmContact.remove(fail.bind(null, done), expectedFail);
+                rmContact.remove(unexpectedSuccess, expectedFail);
             });
 
             it("contacts.spec.24 calling remove on a contact that does not exist should return
ContactError.UNKNOWN_ERROR", function(done) {
@@ -574,6 +621,10 @@ exports.defineAutoTests = function() {
             }, MEDIUM_TIMEOUT);
 
             it("contacts.spec.26 Creating, saving, finding a contact should work, removing
it should work", function(done) {
+                
+                var startTime = new Date();
+                console.log("Spec26 - Start Time: " + getTimeInHHMMSS(startTime));
+                
                 // Save method is not supported on Windows platform
                 if (isWindows || isWindowsPhone8 || isIOSPermissionBlocked) {
                     pending();
@@ -586,14 +637,28 @@ exports.defineAutoTests = function() {
                 saveAndFindBy(contact, ["displayName", "name"], contactName, function() {
                     contact.remove(function() {
                         contact = null;
+                        
+                        var endTime = new Date();
+                        console.log("Spec26 - EndTime: " + getTimeInHHMMSS(endTime));
+                        console.log("Time Elapsed: " + toHHMMSS( (startTime / 1000) - (endTime
/ 1000) ));
+                    
                         done();
                     }, function(e) {
-                        throw ("Newly created contact's remove function invoked error callback.
Test failed.");
+                        
+                        var endTime = new Date();
+                        console.log("Spec26 - EndTime: " + getTimeInHHMMSS(endTime));
+                        console.log("Time Elapsed: " + toHHMMSS( (startTime / 1000) - (endTime
/ 1000) ));
+                        
+                        throw ("Newly created contact's remove function invoked error callback.
Test failed: " + JSON.stringify(e));
                     });
                 });
             }, MEDIUM_TIMEOUT);
 
             it("contacts.spec.27 Should not be able to delete the same contact twice", function(done)
{
+                
+                var startTime = new Date();
+                console.log("Spec27 - Start Time: " + getTimeInHHMMSS(startTime));
+                
                 // Save method is not supported on Windows platform
                 if (isWindows || isWindowsPhone8 || isIOSPermissionBlocked) {
                     pending();
@@ -603,14 +668,33 @@ exports.defineAutoTests = function() {
                 contact.name = new ContactName();
                 contact.name.familyName = contactName;
                 contact.note = "DeleteMe2";
+                
+                var failureHandler = function() {
+                    console.log("Inside failureHandler");
+                    var endTime = new Date();
+                    console.log("Spec27 - EndTime: " + endTime);
+                    console.log("Time Elapsed: " + toHHMMSS( (startTime / 1000) - (endTime
/ 1000) ));
+                };
+                
                 saveAndFindBy(contact, ["displayName", "name"], contactName, function() {
                     contact.remove(function() {
                         var findWin = function(seas) {
                             expect(seas.length).toBe(0);
-                            contact.remove(function() {
-                                throw ("Success callback called after non-existent Contact
object called remove(). Test failed.");
+                            contact.remove(function(e) {
+                                
+                                var endTime = new Date();
+                                console.log("Spec27 - EndTime: " + getTimeInHHMMSS(endTime));
+                                console.log("Time Elapsed: " + toHHMMSS( (startTime / 1000)
- (endTime / 1000) ));
+                                
+                                throw ("Success callback called after non-existent Contact
object called remove(). Test failed: " + JSON.stringify(e));
                             }, function(e) {
                                 contact = null;
+                                
+                                console.log("Inside contact.remove() failure callback");
+                                var endTime = new Date();
+                                console.log("Spec27 - EndTime: " + getTimeInHHMMSS(endTime));
+                                console.log("Time Elapsed: " + toHHMMSS( (startTime / 1000)
- (endTime / 1000) ));
+                        
                                 expect(e.code).toBe(ContactError.UNKNOWN_ERROR);
                                 done();
                             });
@@ -619,7 +703,7 @@ exports.defineAutoTests = function() {
                         obj.filter = contactName;
                         obj.multiple = true;
                         navigator.contacts.find(["displayName", "name", "phoneNumbers", "emails"],
findWin, fail, obj);
-                    }, fail);
+                    }, failureHandler);
                 });
             }, MEDIUM_TIMEOUT);
 


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org


Mime
View raw message