Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions server/test/global-setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { MongoBinary } from 'mongodb-memory-server';

/**
* Fetch the `mongod` binary once, before any test file runs.
*
* On a cold cache (every fresh CI runner) each suite that calls
* `useMongoMemoryServer` would otherwise start the ~100 MB download inside its
* own `beforeAll`, in parallel workers that contend for the same lock file.
* The download outlives the 10 s hook timeout, so those suites fail at random
* depending on network speed. Global setup has no hook timeout and runs before
* the workers start, so the suites only ever find a warm cache.
*/
export default async function setup() {
await MongoBinary.getPath();
}
5 changes: 3 additions & 2 deletions server/test/helpers/mongo.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ import { MongoMemoryServer } from 'mongodb-memory-server';
* `mongod` binary into its cache (~/.cache/mongodb-binaries) from
* fastdl.mongodb.org, then reuses it on later runs. That fetch is a *runtime*
* step performed by the test, not an npm postinstall — so it is unaffected by
* CI's `npm ci --ignore-scripts` and keeps installs fast. The first CI run on
* a cold cache pays the one-time download.
* CI's `npm ci --ignore-scripts` and keeps installs fast. `test/global-setup.js`
* performs that download once before the workers start, so this hook never
* races other suites for it.
*/
export function useMongoMemoryServer() {
let mongod;
Expand Down
1 change: 1 addition & 0 deletions server/vitest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { defineConfig } from 'vitest/config';
export default defineConfig({
test: {
environment: 'node',
globalSetup: ['./test/global-setup.js'],
setupFiles: ['./test/setup.js'],
include: ['test/**/*.test.js'],
coverage: {
Expand Down
Loading