Skip to content

Commit

Permalink
catch android failures
Browse files Browse the repository at this point in the history
  • Loading branch information
apla committed Apr 26, 2017
1 parent af6ba52 commit 471ea47
Showing 1 changed file with 31 additions and 18 deletions.
49 changes: 31 additions & 18 deletions src/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,19 @@ var tests = {
var fail = [];
var pass = 0;


function addFailure (msg) {
var err = new Error (msg);
var errObject = {};
for (var k in err) {
errObject[k] = err[k]
}
errObject.message = err.message;
errObject.location = err.stack.split (/\n/)[1].match (/(\:\d+\:\d+)$/)[1];

fail.push (msg + ';' + errObject.location);
}

var nonExistingKeyName = 'test-key-must-not-exists';

var appp = (typeof AppPreferences !== "undefined") ? new AppPreferences () : plugins.appPreferences;
Expand All @@ -34,7 +47,7 @@ function fetchIncrementStore (keyName) {
pass++;
}, function (err) {
console.error (err);
fail.push ('promise '+keyName+' failed');
addFailure ('promise '+keyName+' failed');
}).then (function () {
appp.store (keyName, testRunCount)
}).then (function () {
Expand All @@ -49,7 +62,7 @@ fetchIncrementStore ("test-run-count");
appp.fetch ("test-promise").then (function () {
pass++;
}, function (err) {
fail.push ('promise fetch failed');
addFailure ('promise fetch failed');
});

appp.fetch (function (ok) {
Expand All @@ -62,39 +75,39 @@ appp.fetch (function (ok) {
if (ok !== null && ok) {
pass++;
} else {
fail.push ('fetch>store>fetch '+nonExistingKeyName);
addFailure ('fetch>store>fetch '+nonExistingKeyName);
}
appp.remove (function (ok) {
pass++;
}, function (err) {
fail.push ('fetch>store>fetch>remove '+nonExistingKeyName + ', error: '+err);
addFailure ('fetch>store>fetch>remove '+nonExistingKeyName + ', error: '+err);
}, nonExistingKeyName);
}, function (err) {
fail.push ('fetch>store>fetch null '+nonExistingKeyName);
addFailure ('fetch>store>fetch null '+nonExistingKeyName);
}, nonExistingKeyName);
}, function (err) {
fail.push ('fetch>store '+nonExistingKeyName);
addFailure ('fetch>store '+nonExistingKeyName);
}, nonExistingKeyName, true);
} else {
appp.remove (function (ok) {
pass++;
}, function (err) {
fail.push ('fetch>remove '+nonExistingKeyName + '="'+err+'"');
addFailure ('fetch>remove '+nonExistingKeyName + '="'+err+'"');
}, nonExistingKeyName);
fail.push ('fetch exists '+nonExistingKeyName + '="'+ok+'"');
addFailure ('fetch exists '+nonExistingKeyName + '="'+ok+'"');
}
}, function (err) {
fail.push ('fetch '+nonExistingKeyName);
addFailure ('fetch '+nonExistingKeyName);
}, nonExistingKeyName);

appp.fetch (function (ok) {
if (ok === null) {
pass++;
} else {
fail.push ('fetch not null '+'dict2.'+nonExistingKeyName + '="'+ok+'"');
addFailure ('fetch not null '+'dict2.'+nonExistingKeyName + '="'+ok+'"');
}
}, function (err) {
fail.push ('fetch '+'dict2.'+nonExistingKeyName);
addFailure ('fetch '+'dict2.'+nonExistingKeyName);
}, "dict2", nonExistingKeyName);

for (var testK in tests) {
Expand All @@ -108,19 +121,19 @@ for (var testK in tests) {
pass ++;
else {
console.error ('fetched incorrect value for ' + testName + ': expected ' + JSON.stringify (testValue) + ' got ' + JSON.stringify (ok));
fail.push ('store>fetch not equal '+testName);
addFailure ('store>fetch not equal '+testName);
}
}, function (err) {
console.error ('fetch value failed for ' + testName + ' and value ' + testValue);
fail.push ('store>fetch '+testName);
addFailure ('store>fetch '+testName);
}, testName);
if ('device' in window && device.platform && nativePlatforms[device.platform]) {
// TODO: replace by localStorage fallback module
var lsValue = localStorage.getItem (testName);
if (lsValue === null) {
pass ++;
} else if (lsValue === testValue) {
fail.push ('store>fetch (localStorage) '+testName);
addFailure ('store>fetch (localStorage) '+testName);
} else {
console.error ('localStorage contains unexpected value: "' + lsValue + '" / "' + testValue + '"');
pass ++;
Expand All @@ -129,7 +142,7 @@ for (var testK in tests) {

}, function (err) {
console.error ('store value failed for ' + testName + ' and value ' + testValue);
fail.push ('store '+testName);
addFailure ('store '+testName);
}, testName, testValue);
console.log ('trying to store', "dict.x" + testName);
appp.store (function (ok) {
Expand All @@ -140,15 +153,15 @@ for (var testK in tests) {
pass ++;
else {
console.error ('fetched incorrect value for dict.x' + testName + ': expected ' + JSON.stringify (testValue) + ' got ' + JSON.stringify (ok));
fail.push ('store>fetch not equal '+'dict.x'+testName);
addFailure ('store>fetch not equal '+'dict.x'+testName);
}
}, function (err) {
console.error ('fetch value failed for ' + "dict.x" + testName + ' and value ' + testValue);
fail.push ('store>fetch '+'dict.x'+testName);
addFailure ('store>fetch '+'dict.x'+testName);
}, "dict", "x" + testName);
}, function (err) {
console.error ('store value failed for ' + "dictx" + testName + ' and value ' + testValue);
fail.push ('store '+'dict.x'+testName);
addFailure ('store '+'dict.x'+testName);
}, "dict", "x" + testName, testValue);

}) (testK, tests[testK]);
Expand Down

0 comments on commit 471ea47

Please sign in to comment.