From 471ea472b0da8c934bf7944a074c426ddc702d57 Mon Sep 17 00:00:00 2001 From: apla Date: Wed, 26 Apr 2017 18:10:42 +0300 Subject: [PATCH] catch android failures --- src/test.js | 49 +++++++++++++++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 18 deletions(-) diff --git a/src/test.js b/src/test.js index 414a0c0..b6c1f61 100644 --- a/src/test.js +++ b/src/test.js @@ -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; @@ -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 () { @@ -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) { @@ -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) { @@ -108,11 +121,11 @@ 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 @@ -120,7 +133,7 @@ for (var testK in tests) { 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 ++; @@ -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) { @@ -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]);