1313 * - CLI uninit command
1414 */
1515
16- import { describe , it , expect , beforeEach , afterEach } from 'vitest' ;
16+ import { describe , it , expect , beforeAll , beforeEach , afterEach } from 'vitest' ;
1717import * as fs from 'fs' ;
1818import * as path from 'path' ;
1919import * as os from 'os' ;
@@ -24,8 +24,13 @@ import {
2424 getSupportedLanguages ,
2525 clearParserCache ,
2626 getUnavailableGrammarErrors ,
27+ initGrammars ,
2728} from '../src/extraction/grammars' ;
2829
30+ beforeAll ( async ( ) => {
31+ await initGrammars ( ) ;
32+ } ) ;
33+
2934// Create a temporary directory for each test
3035function createTempDir ( ) : string {
3136 return fs . mkdtempSync ( path . join ( os . tmpdir ( ) , 'codegraph-pr19-test-' ) ) ;
@@ -320,8 +325,9 @@ describe('Database Layer Improvements', () => {
320325 const { DatabaseConnection } = await import ( '../src/db' ) ;
321326 const { QueryBuilder } = await import ( '../src/db/queries' ) ;
322327
323- const db = DatabaseConnection . initialize ( testDir ) ;
324- const queries = new QueryBuilder ( db . getDatabase ( ) ) ;
328+ const dbPath = path . join ( testDir , 'codegraph.db' ) ;
329+ const db = DatabaseConnection . initialize ( dbPath ) ;
330+ const queries = new QueryBuilder ( db . getDb ( ) ) ;
325331
326332 // Insert a node first (needed as foreign key)
327333 queries . insertNode ( {
@@ -375,8 +381,9 @@ describe('Database Layer Improvements', () => {
375381 const { DatabaseConnection } = await import ( '../src/db' ) ;
376382 const { QueryBuilder } = await import ( '../src/db/queries' ) ;
377383
378- const db = DatabaseConnection . initialize ( testDir ) ;
379- const queries = new QueryBuilder ( db . getDatabase ( ) ) ;
384+ const dbPath = path . join ( testDir , 'codegraph.db' ) ;
385+ const db = DatabaseConnection . initialize ( dbPath ) ;
386+ const queries = new QueryBuilder ( db . getDb ( ) ) ;
380387
381388 // Insert some nodes
382389 for ( let i = 0 ; i < 3 ; i ++ ) {
@@ -405,8 +412,9 @@ describe('Database Layer Improvements', () => {
405412 it . skipIf ( ! HAS_SQLITE ) ( 'should set performance pragmas on initialization' , async ( ) => {
406413 const { DatabaseConnection } = await import ( '../src/db' ) ;
407414
408- const db = DatabaseConnection . initialize ( testDir ) ;
409- const rawDb = db . getDatabase ( ) ;
415+ const dbPath = path . join ( testDir , 'codegraph.db' ) ;
416+ const db = DatabaseConnection . initialize ( dbPath ) ;
417+ const rawDb = db . getDb ( ) ;
410418
411419 // Check pragmas were set
412420 const synchronous = rawDb . pragma ( 'synchronous' , { simple : true } ) ;
@@ -428,8 +436,9 @@ describe('Database Layer Improvements', () => {
428436 const { DatabaseConnection } = await import ( '../src/db' ) ;
429437 const { QueryBuilder } = await import ( '../src/db/queries' ) ;
430438
431- const db = DatabaseConnection . initialize ( testDir ) ;
432- const queries = new QueryBuilder ( db . getDatabase ( ) ) ;
439+ const dbPath = path . join ( testDir , 'codegraph.db' ) ;
440+ const db = DatabaseConnection . initialize ( dbPath ) ;
441+ const queries = new QueryBuilder ( db . getDb ( ) ) ;
433442
434443 // Should not throw on empty array
435444 expect ( ( ) => queries . insertUnresolvedRefsBatch ( [ ] ) ) . not . toThrow ( ) ;
@@ -665,28 +674,21 @@ describe('CLI uninit', () => {
665674// Tree-sitter Version Pinning
666675// =============================================================================
667676
668- describe ( 'Tree-sitter Version Pinning ' , ( ) => {
669- it ( 'should have exact versions (no caret) in package.json ' , ( ) => {
677+ describe ( 'Tree-sitter WASM Setup ' , ( ) => {
678+ it ( 'should use web-tree-sitter and tree-sitter-wasms in dependencies ' , ( ) => {
670679 const pkgPath = path . join ( __dirname , '..' , 'package.json' ) ;
671680 const pkg = JSON . parse ( fs . readFileSync ( pkgPath , 'utf-8' ) ) ;
672681
673- const treeSitterDeps = Object . entries ( pkg . dependencies as Record < string , string > )
674- . filter ( ( [ name ] ) => name . startsWith ( 'tree-sitter' ) || name . includes ( 'tree-sitter' ) ) ;
675-
676- for ( const [ name , version ] of treeSitterDeps ) {
677- // Skip github: references
678- if ( version . startsWith ( 'github:' ) ) continue ;
679- expect ( version , `${ name } should not use caret range` ) . not . toMatch ( / ^ \^ / ) ;
680- }
682+ expect ( pkg . dependencies [ 'web-tree-sitter' ] ) . toBeDefined ( ) ;
683+ expect ( pkg . dependencies [ 'tree-sitter-wasms' ] ) . toBeDefined ( ) ;
681684 } ) ;
682685
683- it ( 'should have tree-sitter override pinned ' , ( ) => {
686+ it ( 'should not have native tree-sitter in dependencies ' , ( ) => {
684687 const pkgPath = path . join ( __dirname , '..' , 'package.json' ) ;
685688 const pkg = JSON . parse ( fs . readFileSync ( pkgPath , 'utf-8' ) ) ;
686689
687- expect ( pkg . overrides ) . toBeDefined ( ) ;
688- expect ( pkg . overrides [ 'tree-sitter' ] ) . toBeDefined ( ) ;
689- expect ( pkg . overrides [ 'tree-sitter' ] ) . not . toMatch ( / ^ \^ / ) ;
690+ expect ( pkg . dependencies [ 'tree-sitter' ] ) . toBeUndefined ( ) ;
691+ expect ( pkg . overrides ) . toBeUndefined ( ) ;
690692 } ) ;
691693} ) ;
692694
0 commit comments