chore: ensure jest respects PAYLOAD_DATABASE env variable (#11065)

Previously, if the `PAYLOAD_DATABASE` env variable was set to `postgres`, it would still start up the mongo memory db and write the mongo db adapter.
This commit is contained in:
Alessio Gravili
2025-02-08 16:25:00 -07:00
committed by GitHub
parent dc56acbdaf
commit c6c65ac842
2 changed files with 7 additions and 2 deletions

View File

@@ -1,9 +1,10 @@
import { MongoMemoryReplSet } from 'mongodb-memory-server'
import dotenv from 'dotenv'
dotenv.config()
// eslint-disable-next-line no-restricted-exports
export default async () => {
console.log('Starting memory db...')
// @ts-expect-error
process.env.NODE_ENV = 'test'
process.env.PAYLOAD_DROP_DATABASE = 'true'
@@ -14,6 +15,7 @@ export default async () => {
(!process.env.PAYLOAD_DATABASE || process.env.PAYLOAD_DATABASE === 'mongodb') &&
!global._mongoMemoryServer
) {
console.log('Starting memory db...')
const db = await MongoMemoryReplSet.create({
replSet: {
count: 3,

View File

@@ -2,6 +2,9 @@ import { jest } from '@jest/globals'
import console from 'console'
global.console = console
import dotenv from 'dotenv'
dotenv.config()
import nodemailer from 'nodemailer'
import { generateDatabaseAdapter } from './generateDatabaseAdapter.js'