global-setup.ts 556 B

1234567891011121314151617
  1. import { MongoBinary } from 'mongodb-memory-server-core';
  2. import { MONGOMS_BINARY_OPTS } from './utils';
  3. /**
  4. * Global setup: pre-download the MongoDB binary before any workers start.
  5. * This prevents lock-file race conditions when multiple Vitest workers try to
  6. * download the binary concurrently on the first run.
  7. */
  8. export async function setup(): Promise<void> {
  9. // Skip if using an external MongoDB (e.g. CI with GitHub Actions services)
  10. if (process.env.MONGO_URI != null) {
  11. return;
  12. }
  13. await MongoBinary.getPath(MONGOMS_BINARY_OPTS);
  14. }