You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by sg...@apache.org on 2015/03/20 15:37:26 UTC
cordova-plugin-geolocation git commit: CB-8681 Fixed occasional test
failures
Repository: cordova-plugin-geolocation
Updated Branches:
refs/heads/master 973014e43 -> 90aeac681
CB-8681 Fixed occasional test failures
github close #41
Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-geolocation/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-geolocation/commit/90aeac68
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-geolocation/tree/90aeac68
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-geolocation/diff/90aeac68
Branch: refs/heads/master
Commit: 90aeac681c764a314b9b3f8f9de98b1a0f3c8b02
Parents: 973014e
Author: alsorokin <al...@akvelon.com>
Authored: Fri Mar 20 17:31:00 2015 +0300
Committer: sgrebnov <v-...@microsoft.com>
Committed: Fri Mar 20 17:37:04 2015 +0300
----------------------------------------------------------------------
tests/tests.js | 81 +++++++++++++++++++++++++++++++++++++----------------
1 file changed, 57 insertions(+), 24 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-geolocation/blob/90aeac68/tests/tests.js
----------------------------------------------------------------------
diff --git a/tests/tests.js b/tests/tests.js
index 89fc957..0105196 100644
--- a/tests/tests.js
+++ b/tests/tests.js
@@ -19,18 +19,41 @@
*
*/
exports.defineAutoTests = function () {
- var fail = function (done) {
- expect(true).toBe(false);
- done();
- },
- succeed = function (done) {
- expect(true).toBe(true);
- // callback could be called sync so we invoke done async to make sure we know watcher id to .clear in afterEach
- setTimeout(function () {
- done();
- });
- };
- var isWindowsStore = (cordova.platformId == "windows8") || (cordova.platformId == "windows" && !WinJS.Utilities.isPhone);
+ var fail = function (done, context, message) {
+ // prevents done() to be called several times
+ if (context) {
+ if (context.done) return;
+ context.done = true;
+ }
+
+ if (message) {
+ expect(false).toBe(true, message);
+ } else {
+ expect(false).toBe(true);
+ }
+
+ // watchPosition could call its callback sync (before returning the value)
+ // so we invoke done async to make sure we know watcher id to .clear in afterEach
+ setTimeout(function () {
+ done();
+ });
+ },
+ succeed = function (done, context) {
+ // prevents done() to be called several times
+ if (context) {
+ if (context.done) return;
+ context.done = true;
+ }
+
+ expect(true).toBe(true);
+
+ // watchPosition could call its callback sync (before returning the value)
+ // so we invoke done async to make sure we know watcher id to .clear in afterEach
+ setTimeout(function () {
+ done();
+ });
+ },
+ isWindowsStore = (cordova.platformId == "windows8") || (cordova.platformId == "windows" && !WinJS.Utilities.isPhone);
describe('Geolocation (navigator.geolocation)', function () {
@@ -65,6 +88,7 @@ exports.defineAutoTests = function () {
if (isWindowsStore) {
pending();
}
+
navigator.geolocation.getCurrentPosition(
fail.bind(null, done),
succeed.bind(null, done),
@@ -84,6 +108,7 @@ exports.defineAutoTests = function () {
if (isWindowsStore) {
pending();
}
+
navigator.geolocation.getCurrentPosition(function (p) {
expect(p.coords).toBeDefined();
expect(p.timestamp).toBeDefined();
@@ -91,16 +116,23 @@ exports.defineAutoTests = function () {
},
fail.bind(null, done),
{
- maximumAge: 300000 // 5 minutes maximum age of cached position
+ maximumAge: (5 * 60 * 1000) // 5 minutes maximum age of cached position
});
- });
-
+ }, 25000); // first geolocation call can take several seconds on some devices
});
});
describe('watchPosition method', function () {
+ beforeEach(function(done) {
+ // This timeout is set to lessen the load on platform's geolocation services
+ // which were causing occasional test failures
+ setTimeout(function() {
+ done();
+ }, 100);
+ });
+
describe('error callback', function () {
var errorWatch = null;
@@ -114,9 +146,11 @@ exports.defineAutoTests = function () {
if (isWindowsStore) {
pending();
}
+
+ var context = this;
errorWatch = navigator.geolocation.watchPosition(
- fail.bind(null, done),
- succeed.bind(null, done),
+ fail.bind(null, done, context, 'Unexpected win'),
+ succeed.bind(null, done, context),
{
maximumAge: 0,
timeout: 0
@@ -138,26 +172,25 @@ exports.defineAutoTests = function () {
if (isWindowsStore) {
pending();
}
- var self = this;
+
+ var context = this;
successWatch = navigator.geolocation.watchPosition(
function (p) {
// prevents done() to be called several times
- if (self.done) return;
- self.done = true;
+ if (context.done) return;
+ context.done = true;
expect(p.coords).toBeDefined();
expect(p.timestamp).toBeDefined();
// callback could be called sync so we invoke done async to make sure we know watcher id to .clear in afterEach
setTimeout(function () {
done();
- })
-
+ });
},
- fail.bind(null, done),
+ fail.bind(null, done, context, 'Unexpected fail callback'),
{
maximumAge: (5 * 60 * 1000) // 5 minutes maximum age of cached position
});
-
});
});
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org