From cc81634d94df013af8b4a56b1c8d720634c89ddf Mon Sep 17 00:00:00 2001 From: mixmix Date: Thu, 4 Jul 2024 09:39:19 +1200 Subject: [PATCH 1/2] write basic test --- packages/leveldb/tests/basic.test.js | 58 ++++++++++++++++++++++++++++ packages/leveldb/tests/init.test.ts | 4 +- 2 files changed, 60 insertions(+), 2 deletions(-) create mode 100644 packages/leveldb/tests/basic.test.js diff --git a/packages/leveldb/tests/basic.test.js b/packages/leveldb/tests/basic.test.js new file mode 100644 index 0000000..7b276c9 --- /dev/null +++ b/packages/leveldb/tests/basic.test.js @@ -0,0 +1,58 @@ +import "./setup"; + +import fs from 'fs'; +import { createRxDatabase } from 'rxdb' +import { describe, it } from 'vitest'; + +import { createLevelDBStorage } from '../src' + +function clean () { + if (fs.existsSync("./db1")) fs.rmdirSync("./db1", { recursive: true }) + if (fs.existsSync("./db2")) fs.rmdirSync("./db2", { recursive: true }) +} + +describe("Basic tests", () => { + + it('should be able to instanciate multiple databases in the same thread', async ({ expect }) => { + clean() + + const collections = { + todo: { + schema: { + version: 0, + primaryKey: 'id', + type: 'object', + properties: { + id: { type: 'string', maxLength: 100 }, + name: { type: 'string' }, + }, + required: ['id', 'name'] + } + } + } + + const level1 = createLevelDBStorage({ dbPath: "./db1" }) + const db1 = await createRxDatabase({ + name: 'level-1-db', + storage: level1, + password: 'password-1' + }) + await db1.addCollections(collections) + await db1.todo.insert({ id: '1', name: 'milk' }) + const record1 = await db1.todo.findOne('1').exec() + expect(record1._data.name).toBe('milk') + + const level2 = createLevelDBStorage({ dbPath: "./db2" }) + const db2 = await createRxDatabase({ + name: 'level-2-db', + storage: level2, + password: 'password-2' + }) + await db2.addCollections(collections) + await db2.todo.insert({ id: '2', name: 'potatoes' }) + const record2 = await db2.todo.findOne('2').exec() + expect(record2._data.name).toBe('potatoes') + + clean() + }) +}) diff --git a/packages/leveldb/tests/init.test.ts b/packages/leveldb/tests/init.test.ts index b263528..e9d8d0e 100644 --- a/packages/leveldb/tests/init.test.ts +++ b/packages/leveldb/tests/init.test.ts @@ -10,8 +10,8 @@ describe("Testing suite", () => { describe, it, beforeEach, afterEach }, { name: 'leveldb', - getStorage() { - return createLevelDBStorage({ dbPath: './db' }) + getStorage(i = '') { + return createLevelDBStorage({ dbPath: './db' + i }) }, getPerformanceStorage() { return { From 91ba2366f179fd83a17839b5634c839af81d9edd Mon Sep 17 00:00:00 2001 From: mixmix Date: Thu, 4 Jul 2024 09:39:44 +1200 Subject: [PATCH 2/2] write basic test --- .../tests/{basic.test.js => basic.test.ts} | 0 packages/test-suite/src/index.ts | 21 ++++++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) rename packages/leveldb/tests/{basic.test.js => basic.test.ts} (100%) diff --git a/packages/leveldb/tests/basic.test.js b/packages/leveldb/tests/basic.test.ts similarity index 100% rename from packages/leveldb/tests/basic.test.js rename to packages/leveldb/tests/basic.test.ts diff --git a/packages/test-suite/src/index.ts b/packages/test-suite/src/index.ts index ad064bb..2307daa 100644 --- a/packages/test-suite/src/index.ts +++ b/packages/test-suite/src/index.ts @@ -73,9 +73,28 @@ import { let storage: RxStorage let storageInstance: RxStorageInstance | undefined + +/* +Possible Approaches + +1. read the tests from top to bottom + +2. focus on getting "some" of the tests working (e.g. the queries?) + - use describe.skip + - this may not work if the tests depend on state from earlier tests? + - could see if this is case with indexdb tests + +3. investigate if "parallelism" is messing with us here + - vitest uses "pools" to run many in once, the default strategy is "thread" (there is also "fork") + - this + +*/ + + + export function runTestSuite(suite: TestSuite, testStorage: RxTestStorage): void { const { describe, it, beforeEach, afterEach } = suite - describe('RxStorageInstance', () => { + describe.skip('RxStorageInstance', () => { beforeEach(async () => { storage = await testStorage.getStorage() })