diff --git a/browser-version/test/testPersistence.html b/browser-version/test/testPersistence.html index 50d2d7e..2a1d857 100644 --- a/browser-version/test/testPersistence.html +++ b/browser-version/test/testPersistence.html @@ -6,7 +6,7 @@ -
+
diff --git a/browser-version/test/testPersistence.js b/browser-version/test/testPersistence.js index 8a63bfe..f7b6839 100644 --- a/browser-version/test/testPersistence.js +++ b/browser-version/test/testPersistence.js @@ -1,7 +1,18 @@ console.log("Beginning tests"); +console.log("Please note these tests work on Chrome latest, might not work on other browsers due to discrepancies in how local storage works for the file:// protocol"); -var db = new Nedb({ filename: 'test' }); +function testsFailed () { + document.getElementById("results").innerHTML = "TESTS FAILED"; +} -db.loadDatabase(function (err) { - console.log("LOADING DONE " + err); +localStorage.removeItem('test'); +var db = new Nedb({ filename: 'test', autoload: true }); +db.insert({ hello: 'world' }, function (err) { + if (err) { + testsFailed(); + return; + } + + window.location = './testPersistence2.html'; }); + diff --git a/browser-version/test/testPersistence2.html b/browser-version/test/testPersistence2.html new file mode 100644 index 0000000..b2a057e --- /dev/null +++ b/browser-version/test/testPersistence2.html @@ -0,0 +1,13 @@ + + + + + Test NeDB persistence in the browser - Results + + + +
+ + + + diff --git a/browser-version/test/testPersistence2.js b/browser-version/test/testPersistence2.js new file mode 100644 index 0000000..f2c2353 --- /dev/null +++ b/browser-version/test/testPersistence2.js @@ -0,0 +1,27 @@ +console.log("Checking tests results"); +console.log("Please note these tests work on Chrome latest, might not work on other browsers due to discrepancies in how local storage works for the file:// protocol"); + +function testsFailed () { + document.getElementById("results").innerHTML = "TESTS FAILED"; +} + +var db = new Nedb({ filename: 'test', autoload: true }); +db.find({}, function (err, docs) { + if (docs.length !== 1) { + console.log("Unexpected length of document database"); + return testsFailed(); + } + + if (Object.keys(docs[0]).length !== 2) { + console.log("Unexpected length insert document in database"); + return testsFailed(); + } + + if (docs[0].hello !== 'world') { + console.log("Unexpected document"); + return testsFailed(); + } + + document.getElementById("results").innerHTML = "BROWSER PERSISTENCE TEST PASSED"; +}); +