Skip to content
Source
Sign inSign up
TanStack/db
Open History to see the last commit

react-native-sqlite-core-adapter-contract.test.ts

37 lines1.3 KB

1import { mkdtempSync, rmSync } from 'node:fs'
2import { tmpdir } from 'node:os'
3import { join } from 'node:path'
4import { runSQLiteCoreAdapterContractSuite } from '../../db-sqlite-persistence-core/tests/contracts/sqlite-core-adapter-contract'
5import { OpSQLiteDriver } from '../src/op-sqlite-driver'
6import { SQLiteCorePersistenceAdapter } from '../../db-sqlite-persistence-core/src'
7import { createOpSQLiteTestDatabase } from './helpers/op-sqlite-test-db'
8import type { SQLiteCoreAdapterHarnessFactory } from '../../db-sqlite-persistence-core/tests/contracts/sqlite-core-adapter-contract'
9​
10const createHarness: SQLiteCoreAdapterHarnessFactory = (options) => {
11 const tempDirectory = mkdtempSync(join(tmpdir(), `db-rn-sqlite-core-`))
12 const dbPath = join(tempDirectory, `state.sqlite`)
13 const database = createOpSQLiteTestDatabase({
14 filename: dbPath,
15 resultShape: `statement-array`,
16 })
17 const driver = new OpSQLiteDriver({ database })
18​
19 const adapter = new SQLiteCorePersistenceAdapter({
20 driver,
21 ...options,
22 })
23​
24 return {
25 adapter,
26 driver,
27 cleanup: async () => {
28 await Promise.resolve(database.close())
29 rmSync(tempDirectory, { recursive: true, force: true })
30 },
31 }
33​
34runSQLiteCoreAdapterContractSuite(
35 `SQLiteCorePersistenceAdapter (react-native op-sqlite driver harness)`,
36 createHarness,