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.
31 lines
822 B
TypeScript
31 lines
822 B
TypeScript
import { MongoMemoryReplSet } from 'mongodb-memory-server'
|
|
import dotenv from 'dotenv'
|
|
dotenv.config()
|
|
|
|
|
|
// eslint-disable-next-line no-restricted-exports
|
|
export default async () => {
|
|
// @ts-expect-error
|
|
process.env.NODE_ENV = 'test'
|
|
process.env.PAYLOAD_DROP_DATABASE = 'true'
|
|
process.env.NODE_OPTIONS = '--no-deprecation'
|
|
process.env.DISABLE_PAYLOAD_HMR = 'true'
|
|
|
|
if (
|
|
(!process.env.PAYLOAD_DATABASE || process.env.PAYLOAD_DATABASE === 'mongodb') &&
|
|
!global._mongoMemoryServer
|
|
) {
|
|
console.log('Starting memory db...')
|
|
const db = await MongoMemoryReplSet.create({
|
|
replSet: {
|
|
count: 3,
|
|
dbName: 'payloadmemory',
|
|
},
|
|
})
|
|
|
|
global._mongoMemoryServer = db
|
|
|
|
process.env.MONGODB_MEMORY_SERVER_URI = `${global._mongoMemoryServer.getUri()}&retryWrites=true`
|
|
}
|
|
}
|