This commit is contained in:
2022-09-30 05:39:11 +00:00
parent 41ee9463ae
commit 4687fa49bc
11418 changed files with 1312504 additions and 0 deletions

File diff suppressed because one or more lines are too long

5332
buildfiles/app/node_modules/nedb/browser-version/test/chai.js generated vendored Executable file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,24 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Mocha tests for NeDB</title>
<link rel="stylesheet" href="mocha.css">
</head>
<body>
<div id="mocha"></div>
<script src="jquery.min.js"></script>
<script src="chai.js"></script>
<script src="underscore.min.js"></script>
<script src="mocha.js"></script>
<script>mocha.setup('bdd')</script>
<script src="../out/nedb.min.js"></script>
<script src="localforage.js"></script>
<script src="nedb-browser.js"></script>
<script>
mocha.checkLeaks();
mocha.globals(['jQuery']);
mocha.run();
</script>
</body>
</html>

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,199 @@
@charset "UTF-8";
body {
font: 20px/1.5 "Helvetica Neue", Helvetica, Arial, sans-serif;
padding: 60px 50px;
}
#mocha ul, #mocha li {
margin: 0;
padding: 0;
}
#mocha ul {
list-style: none;
}
#mocha h1, #mocha h2 {
margin: 0;
}
#mocha h1 {
margin-top: 15px;
font-size: 1em;
font-weight: 200;
}
#mocha h1 a {
text-decoration: none;
color: inherit;
}
#mocha h1 a:hover {
text-decoration: underline;
}
#mocha .suite .suite h1 {
margin-top: 0;
font-size: .8em;
}
#mocha h2 {
font-size: 12px;
font-weight: normal;
cursor: pointer;
}
#mocha .suite {
margin-left: 15px;
}
#mocha .test {
margin-left: 15px;
}
#mocha .test:hover h2::after {
position: relative;
top: 0;
right: -10px;
content: '(view source)';
font-size: 12px;
font-family: arial;
color: #888;
}
#mocha .test.pending:hover h2::after {
content: '(pending)';
font-family: arial;
}
#mocha .test.pass.medium .duration {
background: #C09853;
}
#mocha .test.pass.slow .duration {
background: #B94A48;
}
#mocha .test.pass::before {
content: '✓';
font-size: 12px;
display: block;
float: left;
margin-right: 5px;
color: #00d6b2;
}
#mocha .test.pass .duration {
font-size: 9px;
margin-left: 5px;
padding: 2px 5px;
color: white;
-webkit-box-shadow: inset 0 1px 1px rgba(0,0,0,.2);
-moz-box-shadow: inset 0 1px 1px rgba(0,0,0,.2);
box-shadow: inset 0 1px 1px rgba(0,0,0,.2);
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
-ms-border-radius: 5px;
-o-border-radius: 5px;
border-radius: 5px;
}
#mocha .test.pass.fast .duration {
display: none;
}
#mocha .test.pending {
color: #0b97c4;
}
#mocha .test.pending::before {
content: '◦';
color: #0b97c4;
}
#mocha .test.fail {
color: #c00;
}
#mocha .test.fail pre {
color: black;
}
#mocha .test.fail::before {
content: '✖';
font-size: 12px;
display: block;
float: left;
margin-right: 5px;
color: #c00;
}
#mocha .test pre.error {
color: #c00;
}
#mocha .test pre {
display: inline-block;
font: 12px/1.5 monaco, monospace;
margin: 5px;
padding: 15px;
border: 1px solid #eee;
border-bottom-color: #ddd;
-webkit-border-radius: 3px;
-webkit-box-shadow: 0 1px 3px #eee;
}
#report.pass .test.fail {
display: none;
}
#report.fail .test.pass {
display: none;
}
#error {
color: #c00;
font-size: 1.5 em;
font-weight: 100;
letter-spacing: 1px;
}
#stats {
position: fixed;
top: 15px;
right: 10px;
font-size: 12px;
margin: 0;
color: #888;
}
#stats .progress {
float: right;
padding-top: 0;
}
#stats em {
color: black;
}
#stats a {
text-decoration: none;
color: inherit;
}
#stats a:hover {
border-bottom: 1px solid #eee;
}
#stats li {
display: inline-block;
margin: 0 5px;
list-style: none;
padding-top: 11px;
}
code .comment { color: #ddd }
code .init { color: #2F6FAD }
code .string { color: #5890AD }
code .keyword { color: #8A6343 }
code .number { color: #2F6FAD }

4859
buildfiles/app/node_modules/nedb/browser-version/test/mocha.js generated vendored Executable file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,306 @@
/**
* Testing the browser version of NeDB
* The goal of these tests is not to be exhaustive, we have the server-side NeDB tests for that
* This is more of a sanity check which executes most of the code at least once and checks
* it behaves as the server version does
*/
var assert = chai.assert;
/**
* Given a docs array and an id, return the document whose id matches, or null if none is found
*/
function findById (docs, id) {
return _.find(docs, function (doc) { return doc._id === id; }) || null;
}
describe('Basic CRUD functionality', function () {
it('Able to create a database object in the browser', function () {
var db = new Nedb();
assert.equal(db.inMemoryOnly, true);
assert.equal(db.persistence.inMemoryOnly, true);
});
it('Insertion and querying', function (done) {
var db = new Nedb();
db.insert({ a: 4 }, function (err, newDoc1) {
assert.isNull(err);
db.insert({ a: 40 }, function (err, newDoc2) {
assert.isNull(err);
db.insert({ a: 400 }, function (err, newDoc3) {
assert.isNull(err);
db.find({ a: { $gt: 36 } }, function (err, docs) {
var doc2 = _.find(docs, function (doc) { return doc._id === newDoc2._id; })
, doc3 = _.find(docs, function (doc) { return doc._id === newDoc3._id; })
;
assert.isNull(err);
assert.equal(docs.length, 2);
assert.equal(doc2.a, 40);
assert.equal(doc3.a, 400);
db.find({ a: { $lt: 36 } }, function (err, docs) {
assert.isNull(err);
assert.equal(docs.length, 1);
assert.equal(docs[0].a, 4);
done();
});
});
});
});
});
});
it('Querying with regular expressions', function (done) {
var db = new Nedb();
db.insert({ planet: 'Earth' }, function (err, newDoc1) {
assert.isNull(err);
db.insert({ planet: 'Mars' }, function (err, newDoc2) {
assert.isNull(err);
db.insert({ planet: 'Jupiter' }, function (err, newDoc3) {
assert.isNull(err);
db.insert({ planet: 'Eaaaaaarth' }, function (err, newDoc4) {
assert.isNull(err);
db.insert({ planet: 'Maaaars' }, function (err, newDoc5) {
assert.isNull(err);
db.find({ planet: /ar/ }, function (err, docs) {
assert.isNull(err);
assert.equal(docs.length, 4);
assert.equal(_.find(docs, function (doc) { return doc._id === newDoc1._id; }).planet, 'Earth');
assert.equal(_.find(docs, function (doc) { return doc._id === newDoc2._id; }).planet, 'Mars');
assert.equal(_.find(docs, function (doc) { return doc._id === newDoc4._id; }).planet, 'Eaaaaaarth');
assert.equal(_.find(docs, function (doc) { return doc._id === newDoc5._id; }).planet, 'Maaaars');
db.find({ planet: /aa+r/ }, function (err, docs) {
assert.isNull(err);
assert.equal(docs.length, 2);
assert.equal(_.find(docs, function (doc) { return doc._id === newDoc4._id; }).planet, 'Eaaaaaarth');
assert.equal(_.find(docs, function (doc) { return doc._id === newDoc5._id; }).planet, 'Maaaars');
done();
});
});
});
});
});
});
});
});
it('Updating documents', function (done) {
var db = new Nedb();
db.insert({ planet: 'Eaaaaarth' }, function (err, newDoc1) {
db.insert({ planet: 'Maaaaars' }, function (err, newDoc2) {
// Simple update
db.update({ _id: newDoc2._id }, { $set: { planet: 'Saturn' } }, {}, function (err, nr) {
assert.isNull(err);
assert.equal(nr, 1);
db.find({}, function (err, docs) {
assert.equal(docs.length, 2);
assert.equal(findById(docs, newDoc1._id).planet, 'Eaaaaarth');
assert.equal(findById(docs, newDoc2._id).planet, 'Saturn');
// Failing update
db.update({ _id: 'unknown' }, { $inc: { count: 1 } }, {}, function (err, nr) {
assert.isNull(err);
assert.equal(nr, 0);
db.find({}, function (err, docs) {
assert.equal(docs.length, 2);
assert.equal(findById(docs, newDoc1._id).planet, 'Eaaaaarth');
assert.equal(findById(docs, newDoc2._id).planet, 'Saturn');
// Document replacement
db.update({ planet: 'Eaaaaarth' }, { planet: 'Uranus' }, { multi: false }, function (err, nr) {
assert.isNull(err);
assert.equal(nr, 1);
db.find({}, function (err, docs) {
assert.equal(docs.length, 2);
assert.equal(findById(docs, newDoc1._id).planet, 'Uranus');
assert.equal(findById(docs, newDoc2._id).planet, 'Saturn');
// Multi update
db.update({}, { $inc: { count: 3 } }, { multi: true }, function (err, nr) {
assert.isNull(err);
assert.equal(nr, 2);
db.find({}, function (err, docs) {
assert.equal(docs.length, 2);
assert.equal(findById(docs, newDoc1._id).planet, 'Uranus');
assert.equal(findById(docs, newDoc1._id).count, 3);
assert.equal(findById(docs, newDoc2._id).planet, 'Saturn');
assert.equal(findById(docs, newDoc2._id).count, 3);
done();
});
});
});
});
});
});
});
});
});
});
});
it('Updating documents: special modifiers', function (done) {
var db = new Nedb();
db.insert({ planet: 'Earth' }, function (err, newDoc1) {
// Pushing to an array
db.update({}, { $push: { satellites: 'Phobos' } }, {}, function (err, nr) {
assert.isNull(err);
assert.equal(nr, 1);
db.findOne({}, function (err, doc) {
assert.deepEqual(doc, { planet: 'Earth', _id: newDoc1._id, satellites: ['Phobos'] });
db.update({}, { $push: { satellites: 'Deimos' } }, {}, function (err, nr) {
assert.isNull(err);
assert.equal(nr, 1);
db.findOne({}, function (err, doc) {
assert.deepEqual(doc, { planet: 'Earth', _id: newDoc1._id, satellites: ['Phobos', 'Deimos'] });
done();
});
});
});
});
});
});
it('Upserts', function (done) {
var db = new Nedb();
db.update({ a: 4 }, { $inc: { b: 1 } }, { upsert: true }, function (err, nr, upsert) {
assert.isNull(err);
// Return upserted document
assert.equal(upsert.a, 4);
assert.equal(upsert.b, 1);
assert.equal(nr, 1);
db.find({}, function (err, docs) {
assert.equal(docs.length, 1);
assert.equal(docs[0].a, 4);
assert.equal(docs[0].b, 1);
done();
});
});
});
it('Removing documents', function (done) {
var db = new Nedb();
db.insert({ a: 2 });
db.insert({ a: 5 });
db.insert({ a: 7 });
// Multi remove
db.remove({ a: { $in: [ 5, 7 ] } }, { multi: true }, function (err, nr) {
assert.isNull(err);
assert.equal(nr, 2);
db.find({}, function (err, docs) {
assert.equal(docs.length, 1);
assert.equal(docs[0].a, 2);
// Remove with no match
db.remove({ b: { $exists: true } }, { multi: true }, function (err, nr) {
assert.isNull(err);
assert.equal(nr, 0);
db.find({}, function (err, docs) {
assert.equal(docs.length, 1);
assert.equal(docs[0].a, 2);
// Simple remove
db.remove({ a: { $exists: true } }, { multi: true }, function (err, nr) {
assert.isNull(err);
assert.equal(nr, 1);
db.find({}, function (err, docs) {
assert.equal(docs.length, 0);
done();
});
});
});
});
});
});
});
}); // ==== End of 'Basic CRUD functionality' ==== //
describe('Indexing', function () {
it('getCandidates works as expected', function (done) {
var db = new Nedb();
db.insert({ a: 4 }, function () {
db.insert({ a: 6 }, function () {
db.insert({ a: 7 }, function () {
var candidates = db.getCandidates({ a: 6 })
assert.equal(candidates.length, 3);
assert.isDefined(_.find(candidates, function (doc) { return doc.a === 4; }));
assert.isDefined(_.find(candidates, function (doc) { return doc.a === 6; }));
assert.isDefined(_.find(candidates, function (doc) { return doc.a === 7; }));
db.ensureIndex({ fieldName: 'a' });
candidates = db.getCandidates({ a: 6 })
assert.equal(candidates.length, 1);
assert.isDefined(_.find(candidates, function (doc) { return doc.a === 6; }));
done();
});
});
});
});
it('Can use indexes to enforce a unique constraint', function (done) {
var db = new Nedb();
db.ensureIndex({ fieldName: 'u', unique: true });
db.insert({ u : 5 }, function (err) {
assert.isNull(err);
db.insert({ u : 98 }, function (err) {
assert.isNull(err);
db.insert({ u : 5 }, function (err) {
assert.equal(err.errorType, 'uniqueViolated');
done();
});
});
});
});
}); // ==== End of 'Indexing' ==== //
describe("Don't forget to launch persistence tests!", function () {
it("See file testPersistence.html", function (done) {
done();
});
}); // ===== End of 'persistent in-browser database' =====

View File

@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Playground for NeDB</title>
</head>
<body>
<script src="../out/nedb.min.js"></script>
</body>
</html>

View File

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

View File

@ -0,0 +1,111 @@
console.log('BEGINNING');
var N = 50000
, db = new Nedb({ filename: 'loadTest', autoload: true })
, t, i
, sample = JSON.stringify({ data: Math.random(), _id: Math.random() });
;
// Some inserts in sequence, using the default storage mechanism (IndexedDB in my case)
function someInserts (sn, N, callback) {
var i = 0, beg = Date.now();
async.whilst( function () { return i < N; }
, function (_cb) {
db.insert({ data: Math.random() }, function (err) { i += 1; return _cb(err); });
}
, function (err) {
console.log("Inserts, series " + sn + " " + (Date.now() - beg));
return callback(err);
});
}
// Manually updating the localStorage on the same variable
function someLS (sn, N, callback) {
var i = 0, beg = Date.now();
for (i = 0; i < N; i += 1) {
localStorage.setItem('loadTestLS', getItem('loadTestLS') + sample);
}
console.log("localStorage, series " + sn + " " + (Date.now() - beg));
return callback();
}
// Manually updating the localStorage on different variables
function someLSDiff (sn, N, callback) {
var i = 0, beg = Date.now();
for (i = 0; i < N; i += 1) {
localStorage.setItem('loadTestLS-' + i, sample);
}
console.log("localStorage, series " + sn + " " + (Date.now() - beg));
return callback();
}
// Manually updating the localforage default on the same variable (IndexedDB on my machine)
function someLF (sn, N, callback) {
var i = 0, beg = Date.now();
async.whilst( function () { return i < N; }
, function (_cb) {
localforage.getItem('loadTestLF', function (err, value) {
if (err) { return _cb(err); }
localforage.setItem('loadTestLF', value + sample, function (err) { i += 1; return _cb(err); });
});
}
, function (err) {
console.log("localForage/IDB, series " + sn + " " + (Date.now() - beg));
return callback(err);
});
}
// Manually updating the localforage default on the different variables (IndexedDB on my machine)
function someLFDiff (sn, N, callback) {
var i = 0, beg = Date.now();
async.whilst( function () { return i < N; }
, function (_cb) {
localforage.setItem('loadTestLF-' + i, sample, function (err) { i += 1; return _cb(err); });
}
, function (err) {
console.log("localForage/IDB, series " + sn + " " + (Date.now() - beg));
return callback(err);
});
}
localStorage.setItem('loadTestLS', '');
async.waterfall([
function (cb) { db.remove({}, { multi: true }, function (err) { return cb(err); }); }
// Slow and gets slower with database size
//, async.apply(someInserts, "#1", N) // N=5000, 141s
//, async.apply(someInserts, "#2", N) // N=5000, 208s
//, async.apply(someInserts, "#3", N) // N=5000, 281s
//, async.apply(someInserts, "#4", N) // N=5000, 350s
// Slow and gets slower really fast with database size, then outright crashes
//, async.apply(someLS, "#1", N) // N=4000, 2.5s
//, async.apply(someLS, "#2", N) // N=4000, 8.0s
//, async.apply(someLS, "#3", N) // N=4000, 26.5s
//, async.apply(someLS, "#4", N) // N=4000, 47.8s then crash, can't get string (with N=5000 crash happens on second pass)
// Much faster and more consistent
//, async.apply(someLSDiff, "#1", N) // N=50000, 0.7s
//, async.apply(someLSDiff, "#2", N) // N=50000, 0.5s
//, async.apply(someLSDiff, "#3", N) // N=50000, 0.5s
//, async.apply(someLSDiff, "#4", N) // N=50000, 0.5s
// Slow and gets slower with database size
//, function (cb) { localforage.setItem('loadTestLF', '', function (err) { return cb(err) }) }
//, async.apply(someLF, "#1", N) // N=5000, 69s
//, async.apply(someLF, "#2", N) // N=5000, 108s
//, async.apply(someLF, "#3", N) // N=5000, 137s
//, async.apply(someLF, "#4", N) // N=5000, 169s
// Quite fast and speed doesn't change with database size (tested with N=10000 and N=50000, still no slow-down)
//, async.apply(someLFDiff, "#1", N) // N=5000, 18s
//, async.apply(someLFDiff, "#2", N) // N=5000, 18s
//, async.apply(someLFDiff, "#3", N) // N=5000, 18s
//, async.apply(someLFDiff, "#4", N) // N=5000, 18s
]);

View File

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

View File

@ -0,0 +1,20 @@
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");
function testsFailed () {
document.getElementById("results").innerHTML = "TESTS FAILED";
}
var filename = 'test';
var db = new Nedb({ filename: filename, autoload: true });
db.remove({}, { multi: true }, function () {
db.insert({ hello: 'world' }, function (err) {
if (err) {
testsFailed();
return;
}
window.location = './testPersistence2.html';
});
});

View File

@ -0,0 +1,14 @@
<!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="jquery.min.js"></script>
<script src="../out/nedb.js"></script>
<script src="./testPersistence2.js"></script>
</body>
</html>

View File

@ -0,0 +1,39 @@
// Capture F5 to reload the base page testPersistence.html not this one
$(document).on('keydown', function (e) {
if (e.keyCode === 116) {
e.preventDefault();
window.location = 'testPersistence.html';
}
});
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 filename = 'test';
var db = new Nedb({ filename: filename, autoload: true });
db.find({}, function (err, docs) {
if (docs.length !== 1) {
console.log(docs);
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";
});

File diff suppressed because one or more lines are too long