fix(core): update

This commit is contained in:
2022-05-17 00:33:44 +02:00
parent 83a5170591
commit 37f9a64735
20 changed files with 3056 additions and 20198 deletions

62
test/test.watch.ts Normal file
View File

@@ -0,0 +1,62 @@
import { tap, expect } from '@pushrocks/tapbundle';
import { Qenv } from '@pushrocks/qenv';
import * as smartmongo from '@pushrocks/smartmongo';
import { smartunique } from '../ts/smartdata.plugins.js';
const testQenv = new Qenv(process.cwd(), process.cwd() + '/.nogit/');
console.log(process.memoryUsage());
// the tested module
import * as smartdata from '../ts/index.js';
// =======================================
// Connecting to the database server
// =======================================
let smartmongoInstance: smartmongo.SmartMongo;
let testDb: smartdata.SmartdataDb;
const totalCars = 2000;
tap.test('should create a testinstance as database', async () => {
smartmongoInstance = await smartmongo.SmartMongo.createAndStart();
testDb = new smartdata.SmartdataDb(await smartmongoInstance.getMongoDescriptor());
await testDb.init();
});
@smartdata.Collection(() => testDb)
class House extends smartdata.SmartDataDbDoc<House, House> {
@smartdata.svDb()
public data = {
id: smartunique.shortId(),
hello: 'hello'
}
}
tap.skip.test('should watch a collection', async (toolsArg) => {
const done = toolsArg.defer();
const watcher = await House.watch({});
watcher.changeSubject.subscribe(houseArg => {
console.log('hey there, we observed a house');
watcher.close();
done.resolve();
});
const newHouse = new House();
await newHouse.save();
await done.promise;
})
// =======================================
// close the database connection
// =======================================
tap.test('close', async () => {
if (smartmongoInstance) {
await smartmongoInstance.stop();
} else {
await testDb.mongoDb.dropDatabase();
}
await testDb.close();
});
tap.start({ throwOnError: true });