@@ -162,10 +162,15 @@ describe('CLI Commands', () => {
162162
163163 beforeEach ( async ( ) => {
164164 // Create a test SQLite database with sample schema
165+ const dbPath = path . join ( testDir , `test_${ Date . now ( ) } .db` ) ;
165166 const driver = new SqlDriver ( {
166167 client : 'sqlite3' ,
167- connection : { filename : path . join ( testDir , 'test.db' ) } ,
168- useNullAsDefault : true
168+ connection : { filename : dbPath } ,
169+ useNullAsDefault : true ,
170+ pool : {
171+ min : 1 ,
172+ max : 1 // Single connection for test
173+ }
169174 } ) ;
170175
171176 app = new ObjectQL ( {
@@ -195,42 +200,21 @@ describe('CLI Commands', () => {
195200 } ) ;
196201
197202 await app . init ( ) ;
198-
199- // Create a config file for the sync command to use
200- configPath = path . join ( testDir , 'objectql.config.js' ) ;
201- const configContent = `
202- const { ObjectQL } = require('@objectql/core');
203- const { SqlDriver } = require('@objectql/driver-sql');
204-
205- const driver = new SqlDriver({
206- client: 'sqlite3',
207- connection: { filename: '${ path . join ( testDir , 'test.db' ) . replace ( / \\ / g, '\\\\' ) } ' },
208- useNullAsDefault: true
209- });
210-
211- const app = new ObjectQL({
212- datasources: { default: driver }
213- });
214-
215- module.exports = { default: app };
216- ` ;
217- fs . writeFileSync ( configPath , configContent , 'utf-8' ) ;
218203 } ) ;
219204
220205 afterEach ( async ( ) => {
221- if ( app && app . datasources && app . datasources . default ) {
222- const driver = app . datasources . default as any ;
223- if ( driver . disconnect ) {
224- await driver . disconnect ( ) ;
225- }
206+ try {
207+ if ( app ) await app . close ( ) ;
208+ } catch ( e ) {
209+ // Ignore if already closed
226210 }
227211 } ) ;
228212
229213 it ( 'should introspect database and generate .object.yml files' , async ( ) => {
230214 const outputDir = path . join ( testDir , 'objects' ) ;
231215
232216 await syncDatabase ( {
233- config : configPath ,
217+ app : app ,
234218 output : outputDir
235219 } ) ;
236220
@@ -269,7 +253,7 @@ describe('CLI Commands', () => {
269253 const outputDir = path . join ( testDir , 'objects_selective' ) ;
270254
271255 await syncDatabase ( {
272- config : configPath ,
256+ app : app ,
273257 output : outputDir ,
274258 tables : [ 'users' ]
275259 } ) ;
@@ -284,7 +268,7 @@ describe('CLI Commands', () => {
284268
285269 // First sync
286270 await syncDatabase ( {
287- config : configPath ,
271+ app : app ,
288272 output : outputDir
289273 } ) ;
290274
@@ -295,7 +279,7 @@ describe('CLI Commands', () => {
295279
296280 // Second sync without force - should skip
297281 await syncDatabase ( {
298- config : configPath ,
282+ app : app ,
299283 output : outputDir
300284 } ) ;
301285
@@ -308,7 +292,7 @@ describe('CLI Commands', () => {
308292
309293 // First sync
310294 await syncDatabase ( {
311- config : configPath ,
295+ app : app ,
312296 output : outputDir
313297 } ) ;
314298
@@ -318,7 +302,7 @@ describe('CLI Commands', () => {
318302
319303 // Second sync with force - should overwrite
320304 await syncDatabase ( {
321- config : configPath ,
305+ app : app ,
322306 output : outputDir ,
323307 force : true
324308 } ) ;
0 commit comments