Added tests for browser persistence

pull/2/head
Louis Chatriot 10 years ago
parent 236ee15e64
commit fa9dfe6289
  1. 2
      browser-version/test/testPersistence.html
  2. 17
      browser-version/test/testPersistence.js
  3. 13
      browser-version/test/testPersistence2.html
  4. 27
      browser-version/test/testPersistence2.js

@ -6,7 +6,7 @@
<link rel="stylesheet" href="mocha.css"> <link rel="stylesheet" href="mocha.css">
</head> </head>
<body> <body>
<div id="mocha"></div> <div id="results"></div>
<script src="../out/nedb.js"></script> <script src="../out/nedb.js"></script>
<script src="./testPersistence.js"></script> <script src="./testPersistence.js"></script>
</body> </body>

@ -1,7 +1,18 @@
console.log("Beginning tests"); 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) { localStorage.removeItem('test');
console.log("LOADING DONE " + err); var db = new Nedb({ filename: 'test', autoload: true });
db.insert({ hello: 'world' }, function (err) {
if (err) {
testsFailed();
return;
}
window.location = './testPersistence2.html';
}); });

@ -0,0 +1,13 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Test NeDB persistence in the browser - Results</title>
<link rel="stylesheet" href="mocha.css">
</head>
<body>
<div id="results"></div>
<script src="../out/nedb.js"></script>
<script src="./testPersistence2.js"></script>
</body>
</html>

@ -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";
});
Loading…
Cancel
Save