Skip to content

Commit

Permalink
chore: give all jest worker a different database to work on
Browse files Browse the repository at this point in the history
should help some conflicts
  • Loading branch information
hasezoey committed Jun 25, 2024
1 parent b6cf7f7 commit bf661da
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
5 changes: 4 additions & 1 deletion base-helpers/connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,11 @@ export async function connect(extraConfig: ExtraConnectionConfig = {}): Promise<
}
}

// ensure all test suites get a different database when not using a explicit database
const dbName = extraConfig.dbName ?? config.DataBase + process.env.JEST_WORKER_ID;

// to not duplicate code
const connectionString = `${process.env.MONGO_URI}/${extraConfig.dbName ?? config.DataBase}`;
const connectionString = `${process.env.MONGO_URI}/${dbName}`;

if (extraConfig.createNewConnection) {
connection = await mongooseInstance.createConnection(connectionString, options).asPromise();
Expand Down
8 changes: 4 additions & 4 deletions base-helpers/globalSetup.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { MongoMemoryServer } from 'mongodb-memory-server';
import { config } from './config';
import { connect } from './connect';
// import { connect } from './connect';

export = async function globalSetup() {
if (config.Memory) {
Expand All @@ -13,7 +13,7 @@ export = async function globalSetup() {
process.env.MONGO_URI = `mongodb://${config.IP}:${config.Port}`;
}

const connection = await connect({ dbName: config.DataBase });
await connection.db.dropDatabase();
await connection.close();
// const connection = await connect({ dbName: config.DataBase });
// await connection.db.dropDatabase();
// await connection.close();
};

0 comments on commit bf661da

Please sign in to comment.