@@ -9,64 +9,64 @@ let mongoServer;
99
1010// Simplified MongoDB connection for CI environments
1111module . exports . dbConnect = async ( ) => {
12- try {
13- console . log ( '=== Starting MongoDB Connection Process ===' ) ;
14-
15- // Disconnect any existing connections
16- if ( mongoose . connection . readyState !== 0 ) {
17- console . log ( 'Disconnecting existing MongoDB connection...' ) ;
18- await mongoose . disconnect ( ) ;
19- }
20-
21- // Try to use a real MongoDB connection if available, otherwise use a simple in-memory approach
22- const mongoUri = process . env . MONGODB_LOCAL_TEST_URI || 'mongodb://localhost:27017/test' ;
23-
24- console . log ( 'Using MongoDB URI:' , mongoUri ) ;
25-
26- // Simple connection options
27- const mongooseOpts = {
28- useNewUrlParser : true ,
29- useUnifiedTopology : true ,
30- serverSelectionTimeoutMS : 30000 , // 30 seconds
31- socketTimeoutMS : 30000 , // 30 seconds
32- connectTimeoutMS : 30000 , // 30 seconds
33- maxPoolSize : 1 ,
34- minPoolSize : 0 ,
35- } ;
12+ // try {
13+ console . log ( '=== Starting MongoDB Connection Process ===' ) ;
3614
37- console . log ( 'Connecting to MongoDB...' ) ;
38- await mongoose . connect ( mongoUri , mongooseOpts ) ;
39-
40- console . log ( 'MongoDB connection established successfully' ) ;
41- console . log ( '=== MongoDB Connection Process Complete ===' ) ;
42- } catch ( error ) {
43- console . error ( 'MongoDB connection failed:' , error ) ;
44- console . error ( 'Connection state:' , mongoose . connection . readyState ) ;
45-
46- // If connection fails, try to create a minimal test environment
47- console . log ( 'Attempting to create minimal test environment...' ) ;
15+ // Disconnect any existing connections
16+ if ( mongoose . connection . readyState !== 0 ) {
17+ console . log ( 'Disconnecting existing MongoDB connection...' ) ;
4818 await mongoose . disconnect ( ) ;
49-
50- mongoServer = await MongoMemoryServer . create ( ) ;
51-
52- const uri = mongoServer . getUri ( ) ;
53-
54- const mongooseOpts = {
55- useNewUrlParser : true ,
56- useUnifiedTopology : true ,
57- serverSelectionTimeoutMS : 30000 , // 30 seconds
58- socketTimeoutMS : 30000 , // 30 seconds
59- connectTimeoutMS : 30000 , // 30 seconds
60- maxPoolSize : 1 ,
61- minPoolSize : 0 ,
62- } ;
63-
64- await mongoose . connect ( uri , mongooseOpts , ( err ) => {
65- if ( err ) {
66- console . error ( err ) ;
67- }
68- } ) ;
6919 }
20+
21+ // Try to use a real MongoDB connection if available, otherwise use a simple in-memory approach
22+ // const mongoUri = process.env.MONGODB_LOCAL_TEST_URI || 'mongodb://localhost:27017/test';
23+
24+ // console.log('Using MongoDB URI:', mongoUri);
25+
26+ // // Simple connection options
27+ // const mongooseOpts = {
28+ // useNewUrlParser: true,
29+ // useUnifiedTopology: true,
30+ // serverSelectionTimeoutMS: 30000, // 30 seconds
31+ // socketTimeoutMS: 30000, // 30 seconds
32+ // connectTimeoutMS: 30000, // 30 seconds
33+ // maxPoolSize: 1,
34+ // minPoolSize: 0,
35+ // };
36+
37+ // console.log('Connecting to MongoDB...');
38+ // await mongoose.connect(mongoUri, mongooseOpts);
39+
40+ // console.log('MongoDB connection established successfully');
41+ // console.log('=== MongoDB Connection Process Complete ===');
42+ // } catch (error) {
43+ // console.error('MongoDB connection failed:', error);
44+ // console.error('Connection state:', mongoose.connection.readyState);
45+
46+ // // If connection fails, try to create a minimal test environment
47+ // console.log('Attempting to create minimal test environment...');
48+ // await mongoose.disconnect();
49+
50+ mongoServer = await MongoMemoryServer . create ( ) ;
51+
52+ const uri = mongoServer . getUri ( ) ;
53+
54+ const mongooseOpts = {
55+ useNewUrlParser : true ,
56+ useUnifiedTopology : true ,
57+ serverSelectionTimeoutMS : 30000 , // 30 seconds
58+ socketTimeoutMS : 30000 , // 30 seconds
59+ connectTimeoutMS : 30000 , // 30 seconds
60+ maxPoolSize : 1 ,
61+ minPoolSize : 0 ,
62+ } ;
63+
64+ await mongoose . connect ( uri , mongooseOpts , ( err ) => {
65+ if ( err ) {
66+ console . error ( err ) ;
67+ }
68+ } ) ;
69+ // }
7070} ;
7171
7272module . exports . dbDisconnect = async ( ) => {
0 commit comments