Skip to content
This repository has been archived by the owner on Jan 1, 2025. It is now read-only.

Commit

Permalink
Merge branch 'fix_master_tests' into fix_master_tests_cherese
Browse files Browse the repository at this point in the history
Signed-off-by: mix irving <mix@protozoa.nz>
  • Loading branch information
mixmix authored Jul 15, 2024
2 parents 0ed6859 + 91ba236 commit 7372c41
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 2 deletions.
58 changes: 58 additions & 0 deletions packages/leveldb/tests/basic.test.ts
Original file line number Diff line number Diff line change
@@ -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()
})
})
4 changes: 2 additions & 2 deletions packages/leveldb/tests/init.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ describe("Testing suite", () => {
describe, it, beforeEach, afterEach
}, {
name: 'leveldb',
getStorage() {
return createLevelDBStorage({ dbPath: './db' })
getStorage(i = '') {
return createLevelDBStorage({ dbPath: './db' + i })
},
getPerformanceStorage() {
return {
Expand Down

0 comments on commit 7372c41

Please sign in to comment.