mirror of https://github.com/seald/nedb
parent
236ee15e64
commit
fa9dfe6289
@ -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'; |
||||
}); |
||||
|
||||
|
@ -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…
Reference in new issue