fix(core): update
This commit is contained in:
@ -1,33 +1,25 @@
|
||||
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';
|
||||
|
||||
import * as mongoPlugin from 'mongodb-memory-server';
|
||||
import { smartunique } from '../ts/smartdata.plugins';
|
||||
import * as smartdata from '../ts/index.js';
|
||||
|
||||
// =======================================
|
||||
// Connecting to the database server
|
||||
// =======================================
|
||||
|
||||
let smartmongoInstance: smartmongo.SmartMongo;
|
||||
let testDb: smartdata.SmartdataDb;
|
||||
let smartdataOptions: smartdata.IMongoDescriptor;
|
||||
let mongod: mongoPlugin.MongoMemoryServer;
|
||||
|
||||
tap.test('should create a testinstance as database', async () => {
|
||||
mongod = await mongoPlugin.MongoMemoryServer.create();
|
||||
console.log('created mongod instance');
|
||||
console.log('mongod started');
|
||||
smartdataOptions = {
|
||||
mongoDbUrl: mongod.getUri(),
|
||||
};
|
||||
console.log(smartdataOptions);
|
||||
testDb = new smartdata.SmartdataDb(smartdataOptions);
|
||||
smartmongoInstance = await smartmongo.SmartMongo.createAndStart();
|
||||
testDb = new smartdata.SmartdataDb(await smartmongoInstance.getMongoDescriptor());
|
||||
await testDb.init();
|
||||
});
|
||||
|
||||
@ -49,12 +41,12 @@ tap.test('should create an easystore', async () => {
|
||||
easyStore = await testDb.createEasyStore('hellothere');
|
||||
await easyStore.writeKey('key1', 'hello');
|
||||
const retrievedKey = await easyStore.readKey('key1');
|
||||
expect(retrievedKey).to.equal('hello');
|
||||
expect(retrievedKey).toEqual('hello');
|
||||
});
|
||||
|
||||
tap.test('close', async () => {
|
||||
if (mongod) {
|
||||
await mongod.stop();
|
||||
if (smartmongoInstance) {
|
||||
await smartmongoInstance.stop();
|
||||
} else {
|
||||
await testDb.mongoDb.dropDatabase();
|
||||
}
|
||||
|
48
test/test.ts
48
test/test.ts
@ -1,35 +1,27 @@
|
||||
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';
|
||||
|
||||
import * as mongoPlugin from 'mongodb-memory-server';
|
||||
import { smartunique } from '../ts/smartdata.plugins';
|
||||
import * as smartdata from '../ts/index.js';
|
||||
|
||||
// =======================================
|
||||
// Connecting to the database server
|
||||
// =======================================
|
||||
|
||||
let smartmongoInstance: smartmongo.SmartMongo;
|
||||
let testDb: smartdata.SmartdataDb;
|
||||
let smartdataOptions: smartdata.IMongoDescriptor;
|
||||
let mongod: mongoPlugin.MongoMemoryServer;
|
||||
|
||||
const totalCars = 2000;
|
||||
|
||||
tap.test('should create a testinstance as database', async () => {
|
||||
mongod = await mongoPlugin.MongoMemoryServer.create();
|
||||
console.log('created mongod instance');
|
||||
console.log('mongod started');
|
||||
smartdataOptions = {
|
||||
mongoDbUrl: mongod.getUri(),
|
||||
};
|
||||
console.log(smartdataOptions);
|
||||
testDb = new smartdata.SmartdataDb(smartdataOptions);
|
||||
smartmongoInstance = await smartmongo.SmartMongo.createAndStart();
|
||||
testDb = new smartdata.SmartdataDb(await smartmongoInstance.getMongoDescriptor());
|
||||
await testDb.init();
|
||||
});
|
||||
|
||||
@ -100,7 +92,7 @@ tap.test('should save the car to the db', async () => {
|
||||
});
|
||||
|
||||
tap.test('expect to get instance of Car with shallow match', async () => {
|
||||
const totalQueryCycles = totalCars / 4;
|
||||
const totalQueryCycles = totalCars / 2;
|
||||
let counter = 0;
|
||||
do {
|
||||
const timeStart = Date.now();
|
||||
@ -114,8 +106,8 @@ tap.test('expect to get instance of Car with shallow match', async () => {
|
||||
}ms to query a set of 2000 with memory footprint ${process.memoryUsage().rss / 1e6} MB`
|
||||
);
|
||||
}
|
||||
expect(myCars[0].deepData.sodeep).to.equal('yes');
|
||||
expect(myCars[0].brand).to.equal('Renault');
|
||||
expect(myCars[0].deepData.sodeep).toEqual('yes');
|
||||
expect(myCars[0].brand).toEqual('Renault');
|
||||
counter++;
|
||||
} while (counter < totalQueryCycles);
|
||||
});
|
||||
@ -137,8 +129,8 @@ tap.test('expect to get instance of Car with deep match', async () => {
|
||||
}ms to deep query a set of 2000 with memory footprint ${process.memoryUsage().rss / 1e6} MB`
|
||||
);
|
||||
}
|
||||
expect(myCars2[0].deepData.sodeep).to.equal('yes');
|
||||
expect(myCars2[0].brand).to.equal('Volvo');
|
||||
expect(myCars2[0].deepData.sodeep).toEqual('yes');
|
||||
expect(myCars2[0].brand).toEqual('Volvo');
|
||||
counter++;
|
||||
} while (counter < totalQueryCycles);
|
||||
});
|
||||
@ -147,7 +139,7 @@ tap.test('expect to get instance of Car and update it', async () => {
|
||||
const myCar = await Car.getInstance<Car>({
|
||||
brand: 'Volvo',
|
||||
});
|
||||
expect(myCar.color).to.equal('red');
|
||||
expect(myCar.color).toEqual('red');
|
||||
myCar.color = 'blue';
|
||||
await myCar.save();
|
||||
});
|
||||
@ -158,7 +150,7 @@ tap.test('should be able to delete an instance of car', async () => {
|
||||
color: 'blue',
|
||||
});
|
||||
console.log(myCars);
|
||||
expect(myCars[0].color).to.equal('blue');
|
||||
expect(myCars[0].color).toEqual('blue');
|
||||
for (const myCar of myCars) {
|
||||
await myCar.delete();
|
||||
}
|
||||
@ -166,7 +158,7 @@ tap.test('should be able to delete an instance of car', async () => {
|
||||
const myCar2 = await Car.getInstance<Car>({
|
||||
brand: 'Volvo',
|
||||
});
|
||||
expect(myCar2.color).to.equal('red');
|
||||
expect(myCar2.color).toEqual('red');
|
||||
});
|
||||
|
||||
// tslint:disable-next-line: max-classes-per-file
|
||||
@ -201,9 +193,11 @@ tap.test('should store a new Truck', async () => {
|
||||
});
|
||||
|
||||
tap.test('should use a cursor', async () => {
|
||||
const cursor = await Truck.getCursor({});
|
||||
cursor.forEach(async (truckArg) => {
|
||||
console.log(truckArg.id);
|
||||
const cursor = await Car.getCursor({});
|
||||
let counter = 0;
|
||||
await cursor.forEach(async (carArg) => {
|
||||
counter++;
|
||||
counter % 50 === 0 ? console.log(`50 more of ${carArg.color}`) : null;
|
||||
});
|
||||
});
|
||||
|
||||
@ -211,8 +205,8 @@ tap.test('should use a cursor', async () => {
|
||||
// close the database connection
|
||||
// =======================================
|
||||
tap.test('close', async () => {
|
||||
if (mongod) {
|
||||
await mongod.stop();
|
||||
if (smartmongoInstance) {
|
||||
await smartmongoInstance.stop();
|
||||
} else {
|
||||
await testDb.mongoDb.dropDatabase();
|
||||
}
|
||||
|
@ -1,35 +1,27 @@
|
||||
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';
|
||||
|
||||
import * as mongoPlugin from 'mongodb-memory-server';
|
||||
import { smartunique } from '../ts/smartdata.plugins';
|
||||
import * as smartdata from '../ts/index.js';
|
||||
|
||||
// =======================================
|
||||
// Connecting to the database server
|
||||
// =======================================
|
||||
|
||||
let smartmongoInstance: smartmongo.SmartMongo;
|
||||
let testDb: smartdata.SmartdataDb;
|
||||
let smartdataOptions: smartdata.IMongoDescriptor;
|
||||
let mongod: mongoPlugin.MongoMemoryServer;
|
||||
|
||||
const totalCars = 2000;
|
||||
|
||||
tap.test('should create a testinstance as database', async () => {
|
||||
mongod = await mongoPlugin.MongoMemoryServer.create();
|
||||
console.log('created mongod instance');
|
||||
console.log('mongod started');
|
||||
smartdataOptions = {
|
||||
mongoDbUrl: mongod.getUri(),
|
||||
};
|
||||
console.log(smartdataOptions);
|
||||
testDb = new smartdata.SmartdataDb(smartdataOptions);
|
||||
smartmongoInstance = await smartmongo.SmartMongo.createAndStart();
|
||||
testDb = new smartdata.SmartdataDb(await smartmongoInstance.getMongoDescriptor());
|
||||
await testDb.init();
|
||||
});
|
||||
|
||||
@ -93,8 +85,8 @@ tap.test('should get a car', async () => {
|
||||
// close the database connection
|
||||
// =======================================
|
||||
tap.test('close', async () => {
|
||||
if (mongod) {
|
||||
await mongod.stop();
|
||||
if (smartmongoInstance) {
|
||||
await smartmongoInstance.stop();
|
||||
} else {
|
||||
await testDb.mongoDb.dropDatabase();
|
||||
}
|
||||
|
62
test/test.watch.ts
Normal file
62
test/test.watch.ts
Normal 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 });
|
Reference in New Issue
Block a user