Skip to content

Commit 189b5f1

Browse files
fix: make jest globalSetup resilient to missing MongoDB in CI
- Remove config.db.options from mongoose.connect (empty user/pass caused auth error) - Wrap in try/catch: drop is best-effort, CI starts fresh anyway - Fix test.js DB name WaosNodeTest -> NodeTest
1 parent 7fcd654 commit 189b5f1

2 files changed

Lines changed: 10 additions & 5 deletions

File tree

config/defaults/test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export default _.merge(config.default, {
1010
port: 3001,
1111
},
1212
db: {
13-
uri: 'mongodb://127.0.0.1:27017/WaosNodeTest',
13+
uri: 'mongodb://127.0.0.1:27017/NodeTest',
1414
debug: false,
1515
},
1616
uploads: {

scripts/jest.globalSetup.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
/**
22
* Jest global setup - drops the test database before the test suite runs.
33
* Replaces the gulp dropDB task that previously ran before jest.
4+
* Silently skips if MongoDB is unreachable (e.g. fresh CI environment).
45
*/
56
import mongoose from 'mongoose';
67

78
export default async () => {
8-
const config = (await import('../config/index.js')).default;
9-
await mongoose.connect(config.db.uri, config.db.options);
10-
await mongoose.connection.dropDatabase();
11-
await mongoose.disconnect();
9+
try {
10+
const config = (await import('../config/index.js')).default;
11+
await mongoose.connect(config.db.uri);
12+
await mongoose.connection.dropDatabase();
13+
await mongoose.disconnect();
14+
} catch {
15+
// MongoDB unreachable or drop failed — tests will run against existing state
16+
}
1217
};

0 commit comments

Comments
 (0)