1
0

sqlite-backend.test.ts 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /**
  2. * SQLite backend reporting.
  3. *
  4. * node:sqlite (Node's built-in real SQLite) is the sole backend. Pin that
  5. * DatabaseConnection / CodeGraph report it and come up in WAL.
  6. */
  7. import { describe, it, expect, beforeEach, afterEach } from 'vitest';
  8. import * as fs from 'fs';
  9. import * as path from 'path';
  10. import * as os from 'os';
  11. import { DatabaseConnection } from '../src/db';
  12. import { CodeGraph } from '../src';
  13. describe('DatabaseConnection — backend reporting', () => {
  14. let dir: string;
  15. beforeEach(() => {
  16. dir = fs.mkdtempSync(path.join(os.tmpdir(), 'codegraph-backend-'));
  17. });
  18. afterEach(() => {
  19. if (fs.existsSync(dir)) {
  20. fs.rmSync(dir, { recursive: true, force: true });
  21. }
  22. });
  23. it('reports the node-sqlite backend in WAL for an initialized DB', () => {
  24. const conn = DatabaseConnection.initialize(path.join(dir, 'test.db'));
  25. expect(conn.getBackend()).toBe('node-sqlite');
  26. expect(conn.getJournalMode()).toBe('wal');
  27. conn.close();
  28. });
  29. it('CodeGraph.getBackend() delegates to the underlying DatabaseConnection', async () => {
  30. fs.writeFileSync(path.join(dir, 'x.ts'), `export function x(): void {}\n`);
  31. const cg = await CodeGraph.init(dir, { index: true });
  32. try {
  33. expect(cg.getBackend()).toBe('node-sqlite');
  34. } finally {
  35. cg.destroy();
  36. }
  37. });
  38. });