-
Notifications
You must be signed in to change notification settings - Fork 208
Expand file tree
/
Copy pathcapacitor-sqlite-core-adapter-contract.test.ts
More file actions
36 lines (32 loc) · 1.3 KB
/
capacitor-sqlite-core-adapter-contract.test.ts
File metadata and controls
36 lines (32 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import { mkdtempSync, rmSync } from 'node:fs'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
import { runSQLiteCoreAdapterContractSuite } from '../../db-sqlite-persistence-core/tests/contracts/sqlite-core-adapter-contract'
import { CapacitorSQLiteDriver } from '../src/capacitor-sqlite-driver'
import { SQLiteCorePersistenceAdapter } from '../../db-sqlite-persistence-core/src'
import { createCapacitorSQLiteTestDatabase } from './helpers/capacitor-sqlite-test-db'
import type { SQLiteCoreAdapterHarnessFactory } from '../../db-sqlite-persistence-core/tests/contracts/sqlite-core-adapter-contract'
const createHarness: SQLiteCoreAdapterHarnessFactory = (options) => {
const tempDirectory = mkdtempSync(join(tmpdir(), `db-capacitor-core-`))
const dbPath = join(tempDirectory, `state.sqlite`)
const database = createCapacitorSQLiteTestDatabase({
filename: dbPath,
})
const driver = new CapacitorSQLiteDriver({ database })
const adapter = new SQLiteCorePersistenceAdapter({
driver,
...options,
})
return {
adapter,
driver,
cleanup: async () => {
await database.close()
rmSync(tempDirectory, { recursive: true, force: true })
},
}
}
runSQLiteCoreAdapterContractSuite(
`SQLiteCorePersistenceAdapter (capacitor sqlite driver harness)`,
createHarness,
)