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

expo-sqlite-driver-contract.test.ts

29 lines1.1 KB

1import { mkdtempSync, rmSync } from 'node:fs'
2import { tmpdir } from 'node:os'
3import { join } from 'node:path'
4import { runSQLiteDriverContractSuite } from '../../db-sqlite-persistence-core/tests/contracts/sqlite-driver-contract'
5import { ExpoSQLiteDriver } from '../src/expo-sqlite-driver'
6import { createExpoSQLiteTestDatabase } from './helpers/expo-sqlite-test-db'
7import type { SQLiteDriverContractHarness } from '../../db-sqlite-persistence-core/tests/contracts/sqlite-driver-contract'
8​
9function createDriverHarness(): SQLiteDriverContractHarness {
10 const tempDirectory = mkdtempSync(join(tmpdir(), `db-expo-driver-contract-`))
11 const dbPath = join(tempDirectory, `state.sqlite`)
12 const database = createExpoSQLiteTestDatabase({
13 filename: dbPath,
14 })
15 const driver = new ExpoSQLiteDriver({ database })
16​
17 return {
18 driver,
19 cleanup: async () => {
20 try {
21 await database.closeAsync()
22 } finally {
23 rmSync(tempDirectory, { recursive: true, force: true })
24 }
25 },
26 }
28​
29runSQLiteDriverContractSuite(`expo sqlite driver`, createDriverHarness)