Replace better-sqlite3 with built-in SQLite drivers
This commit is contained in:
43
tests/bun-runtime.test.ts
Normal file
43
tests/bun-runtime.test.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
import { execFile } from 'node:child_process';
|
||||
import { promisify } from 'node:util';
|
||||
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
const execFileAsync = promisify(execFile);
|
||||
|
||||
describe('Bun runtime compatibility', () => {
|
||||
it('connects to sqlite from the package in Bun', async () => {
|
||||
const script = [
|
||||
"import { IdentityDB } from './src/index.ts';",
|
||||
"const db = await IdentityDB.connect({ client: 'sqlite', filename: ':memory:' });",
|
||||
'await db.initialize();',
|
||||
"console.log('bun-sqlite-ok');",
|
||||
'await db.close();',
|
||||
].join('\n');
|
||||
|
||||
const result = await execFileAsync('bun', ['--eval', script], {
|
||||
cwd: process.cwd(),
|
||||
});
|
||||
|
||||
expect(result.stdout).toContain('bun-sqlite-ok');
|
||||
});
|
||||
|
||||
it('supports writes and reads through the Bun sqlite adapter path', async () => {
|
||||
const script = [
|
||||
"import { IdentityDB } from './src/index.ts';",
|
||||
"const db = await IdentityDB.connect({ client: 'sqlite', filename: ':memory:' });",
|
||||
'await db.initialize();',
|
||||
"await db.addFact({ statement: 'Bun supports sqlite.', topics: [{ name: 'Bun', category: 'entity', granularity: 'concrete' }, { name: 'sqlite', category: 'concept', granularity: 'concrete' }] });",
|
||||
"const facts = await db.getTopicFacts('Bun');",
|
||||
"if (facts.length !== 1 || facts[0]?.statement !== 'Bun supports sqlite.') throw new Error('bun sqlite CRUD failed');",
|
||||
"console.log('bun-sqlite-crud-ok');",
|
||||
'await db.close();',
|
||||
].join('\n');
|
||||
|
||||
const result = await execFileAsync('bun', ['--eval', script], {
|
||||
cwd: process.cwd(),
|
||||
});
|
||||
|
||||
expect(result.stdout).toContain('bun-sqlite-crud-ok');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user