chore: attach mongoMemoryServer to db and destroy in tests (#5326)

* chore: attach mongoMemoryServer to db and destroy in tests

* bump mongodb-memory-server to 9.x

---------

Co-authored-by: Paul Popus <paul@nouance.io>
This commit is contained in:
Dan Ribbens
2024-03-14 15:41:20 -04:00
committed by GitHub
parent cbfc7c8b43
commit d193c677c7
36 changed files with 254 additions and 133 deletions

View File

@@ -119,7 +119,7 @@
"lexical": "0.13.1", "lexical": "0.13.1",
"lint-staged": "^14.0.1", "lint-staged": "^14.0.1",
"minimist": "1.2.8", "minimist": "1.2.8",
"mongodb-memory-server": "8.13.0", "mongodb-memory-server": "^9.0",
"next": "14.2.0-canary.21", "next": "14.2.0-canary.21",
"node-mocks-http": "^1.14.1", "node-mocks-http": "^1.14.1",
"nodemon": "3.0.3", "nodemon": "3.0.3",

View File

@@ -1,8 +1,7 @@
/* eslint-disable @typescript-eslint/no-var-requires */ /* eslint-disable @typescript-eslint/no-var-requires */
import type { ConnectOptions } from 'mongoose' import type { ConnectOptions } from 'mongoose'
import type { Connect } from 'payload/database'
import mongoose from 'mongoose' import mongoose from 'mongoose'
import type { Connect } from 'payload/database'
import type { MongooseAdapter } from './index.js' import type { MongooseAdapter } from './index.js'
@@ -37,12 +36,14 @@ export const connect: Connect = async function connect(
const client = this.connection.getClient() const client = this.connection.getClient()
if (!client.options.replicaSet) { if (!client.options.replicaSet) {
this.transactionOptions = false this.transactionOptions = false
this.beginTransaction = undefined this.beginTransaction = undefined
} }
if (!hotReload) { if (!this.mongoMemoryServer && !hotReload) {
if (process.env.PAYLOAD_DROP_DATABASE === 'true') { if (process.env.PAYLOAD_DROP_DATABASE === 'true') {
this.payload.logger.info('---- DROPPING DATABASE ----') this.payload.logger.info('---- DROPPING DATABASE ----')
await mongoose.connection.dropDatabase() await mongoose.connection.dropDatabase()
@@ -50,6 +51,7 @@ export const connect: Connect = async function connect(
} }
} }
} catch (err) { } catch (err) {
console.log(err)
this.payload.logger.error(`Error: cannot connect to MongoDB. Details: ${err.message}`, err) this.payload.logger.error(`Error: cannot connect to MongoDB. Details: ${err.message}`, err)
process.exit(1) process.exit(1)
} }

View File

@@ -6,11 +6,9 @@ import type { MongooseAdapter } from './index.js'
export const destroy: Destroy = async function destroy(this: MongooseAdapter) { export const destroy: Destroy = async function destroy(this: MongooseAdapter) {
if (this.mongoMemoryServer) { if (this.mongoMemoryServer) {
await mongoose.connection.dropDatabase() this.mongoMemoryServer.stop()
await mongoose.connection.close()
await this.mongoMemoryServer.stop()
} else {
await mongoose.disconnect()
} }
await mongoose.disconnect()
Object.keys(mongoose.models).map((model) => mongoose.deleteModel(model)) Object.keys(mongoose.models).map((model) => mongoose.deleteModel(model))
} }

View File

@@ -1,12 +1,12 @@
import type { TransactionOptions } from 'mongodb' import type { TransactionOptions } from 'mongodb'
import type { ClientSession, ConnectOptions, Connection } from 'mongoose' import type { ClientSession, Connection, ConnectOptions } from 'mongoose'
import mongoose from 'mongoose'
import type { Payload } from 'payload' import type { Payload } from 'payload'
import type { BaseDatabaseAdapter } from 'payload/database' import type { BaseDatabaseAdapter, DatabaseAdapterObj } from 'payload/database'
import { createDatabaseAdapter } from 'payload/database'
import fs from 'fs' import fs from 'fs'
import mongoose from 'mongoose'
import path from 'path' import path from 'path'
import { createDatabaseAdapter } from 'payload/database'
import type { CollectionModel, GlobalModel } from './types.js' import type { CollectionModel, GlobalModel } from './types.js'
@@ -37,7 +37,6 @@ import { updateOne } from './updateOne.js'
import { updateVersion } from './updateVersion.js' import { updateVersion } from './updateVersion.js'
export type { MigrateDownArgs, MigrateUpArgs } from './types.js' export type { MigrateDownArgs, MigrateUpArgs } from './types.js'
import type { DatabaseAdapterObj } from 'payload/database'
export interface Args { export interface Args {
/** Set to false to disable auto-pluralization of collection names, Defaults to true */ /** Set to false to disable auto-pluralization of collection names, Defaults to true */
@@ -47,6 +46,10 @@ export interface Args {
/** Set false to disable $facet aggregation in non-supporting databases, Defaults to true */ /** Set false to disable $facet aggregation in non-supporting databases, Defaults to true */
useFacet?: boolean useFacet?: boolean
} }
/**
* typed as any to avoid dependency
*/
mongoMemoryServer?: any
/** Set to true to disable hinting to MongoDB to use 'id' as index. This is currently done when counting documents for pagination. Disabling this optimization might fix some problems with AWS DocumentDB. Defaults to false */ /** Set to true to disable hinting to MongoDB to use 'id' as index. This is currently done when counting documents for pagination. Disabling this optimization might fix some problems with AWS DocumentDB. Defaults to false */
disableIndexHints?: boolean disableIndexHints?: boolean
migrationDir?: string migrationDir?: string
@@ -91,6 +94,7 @@ export function mongooseAdapter({
autoPluralization = true, autoPluralization = true,
connectOptions, connectOptions,
disableIndexHints = false, disableIndexHints = false,
mongoMemoryServer,
migrationDir: migrationDirArg, migrationDir: migrationDirArg,
transactionOptions = {}, transactionOptions = {},
url, url,
@@ -109,7 +113,7 @@ export function mongooseAdapter({
connection: undefined, connection: undefined,
disableIndexHints, disableIndexHints,
globals: undefined, globals: undefined,
mongoMemoryServer: undefined, mongoMemoryServer,
sessions: {}, sessions: {},
transactionOptions: transactionOptions === false ? undefined : transactionOptions, transactionOptions: transactionOptions === false ? undefined : transactionOptions,
url, url,

100
pnpm-lock.yaml generated
View File

@@ -10,7 +10,7 @@ overrides:
dotenv: 8.6.0 dotenv: 8.6.0
drizzle-orm: 0.29.4 drizzle-orm: 0.29.4
graphql: ^16.8.1 graphql: ^16.8.1
mongodb-memory-server: 8.13.0 mongodb-memory-server: ^9.0
react: ^18.2.0 react: ^18.2.0
react-dom: ^18.2.0 react-dom: ^18.2.0
typescript: 5.2.2 typescript: 5.2.2
@@ -188,8 +188,8 @@ importers:
specifier: 1.2.8 specifier: 1.2.8
version: 1.2.8 version: 1.2.8
mongodb-memory-server: mongodb-memory-server:
specifier: 8.13.0 specifier: ^9.0
version: 8.13.0 version: 9.1.7
next: next:
specifier: 14.2.0-canary.21 specifier: 14.2.0-canary.21
version: 14.2.0-canary.21(@babel/core@7.24.0)(react-dom@18.2.0)(react@18.2.0)(sass@1.71.1) version: 14.2.0-canary.21(@babel/core@7.24.0)(react-dom@18.2.0)(react@18.2.0)(sass@1.71.1)
@@ -385,8 +385,8 @@ importers:
specifier: 4.17.1 specifier: 4.17.1
version: 4.17.1 version: 4.17.1
mongodb-memory-server: mongodb-memory-server:
specifier: 8.13.0 specifier: ^9.0
version: 8.13.0 version: 9.1.7
payload: payload:
specifier: workspace:* specifier: workspace:*
version: link:../payload version: link:../payload
@@ -7048,8 +7048,8 @@ packages:
tslib: 2.6.2 tslib: 2.6.2
dev: true dev: true
/async-mutex@0.3.2: /async-mutex@0.4.1:
resolution: {integrity: sha512-HuTK7E7MT7jZEh1P9GtRW9+aTWiDWWi9InbZ5hjxrnRa39KS4BW04+xLBhYNS2aXhHUIKZSw3gj4Pn1pj+qGAA==} resolution: {integrity: sha512-WfoBo4E/TbCX1G95XTjbWTE3X2XLG0m1Xbv2cwOtuPdyH9CZvnaA5nCt1ucjaKEgW2A5IF71hxrRhr83Je5xjA==}
dependencies: dependencies:
tslib: 2.6.2 tslib: 2.6.2
dev: true dev: true
@@ -7113,7 +7113,7 @@ packages:
/axios@1.4.0: /axios@1.4.0:
resolution: {integrity: sha512-S4XCWMEmzvo64T9GfvQDOXgYRDJ/wsSZc7Jvdgx5u1sd0JwsuPLqb3SYmusag+edF6ziyMensPVqLTSc1PiSEA==} resolution: {integrity: sha512-S4XCWMEmzvo64T9GfvQDOXgYRDJ/wsSZc7Jvdgx5u1sd0JwsuPLqb3SYmusag+edF6ziyMensPVqLTSc1PiSEA==}
dependencies: dependencies:
follow-redirects: 1.15.5 follow-redirects: 1.15.5(debug@4.3.4)
form-data: 4.0.0 form-data: 4.0.0
proxy-from-env: 1.1.0 proxy-from-env: 1.1.0
transitivePeerDependencies: transitivePeerDependencies:
@@ -7395,6 +7395,11 @@ packages:
dependencies: dependencies:
buffer: 5.7.1 buffer: 5.7.1
/bson@5.5.1:
resolution: {integrity: sha512-ix0EwukN2EpC0SRWIj/7B5+A6uQMQy6KMREI9qQqvgpkV2frH63T0UDVd1SYedL6dNCmDBYB3QtXi4ISk9YT+g==}
engines: {node: '>=14.20.1'}
dev: true
/buffer-crc32@0.2.13: /buffer-crc32@0.2.13:
resolution: {integrity: sha512-VO9Ht/+p3SN7SKWqcrgEzjGbRSJYTx+Q1pTQC0wrWqHx0vpJraQ6GtHx8tvcg1rlK1byhU5gccxgOgj7B0TDkQ==} resolution: {integrity: sha512-VO9Ht/+p3SN7SKWqcrgEzjGbRSJYTx+Q1pTQC0wrWqHx0vpJraQ6GtHx8tvcg1rlK1byhU5gccxgOgj7B0TDkQ==}
dev: true dev: true
@@ -10099,7 +10104,7 @@ packages:
tabbable: 5.3.3 tabbable: 5.3.3
dev: false dev: false
/follow-redirects@1.15.5: /follow-redirects@1.15.5(debug@4.3.4):
resolution: {integrity: sha512-vSFWUON1B+yAw1VN4xMfxgn5fTUiaOzAJCKBwIIgT/+7CuGy9+r+5gITvP62j3RmaD5Ph65UaERdOSRGUzZtgw==} resolution: {integrity: sha512-vSFWUON1B+yAw1VN4xMfxgn5fTUiaOzAJCKBwIIgT/+7CuGy9+r+5gITvP62j3RmaD5Ph65UaERdOSRGUzZtgw==}
engines: {node: '>=4.0'} engines: {node: '>=4.0'}
peerDependencies: peerDependencies:
@@ -10107,7 +10112,8 @@ packages:
peerDependenciesMeta: peerDependenciesMeta:
debug: debug:
optional: true optional: true
dev: false dependencies:
debug: 4.3.4(supports-color@5.5.0)
/for-each@0.3.3: /for-each@0.3.3:
resolution: {integrity: sha512-jqYfLp7mo9vIyQf8ykW2v7A+2N4QjeCeI5+Dz9XraiO1ign81wjiH7Fb9vSOWvQfNtmSa4H2RoQTrrXivdUZmw==} resolution: {integrity: sha512-jqYfLp7mo9vIyQf8ykW2v7A+2N4QjeCeI5+Dz9XraiO1ign81wjiH7Fb9vSOWvQfNtmSa4H2RoQTrrXivdUZmw==}
@@ -12276,7 +12282,7 @@ packages:
dependencies: dependencies:
array-includes: 3.1.7 array-includes: 3.1.7
array.prototype.flat: 1.3.2 array.prototype.flat: 1.3.2
object.assign: 4.1.4 object.assign: 4.1.5
object.values: 1.1.7 object.values: 1.1.7
dev: false dev: false
@@ -12647,12 +12653,6 @@ packages:
dependencies: dependencies:
tmpl: 1.0.5 tmpl: 1.0.5
/md5-file@5.0.0:
resolution: {integrity: sha512-xbEFXCYVWrSx/gEKS1VPlg84h/4L20znVIulKw6kMfmBUAZNAnF00eczz9ICMl+/hjQGo5KSXRxbL/47X3rmMw==}
engines: {node: '>=10.13.0'}
hasBin: true
dev: true
/md5@2.3.0: /md5@2.3.0:
resolution: {integrity: sha512-T1GITYmFaKuO91vxyoQMFETst+O71VUPEU3ze5GNzDm0OWdP8v1ziTaAEPUr/3kLsY3Sftgz242A1SetQiDL7g==} resolution: {integrity: sha512-T1GITYmFaKuO91vxyoQMFETst+O71VUPEU3ze5GNzDm0OWdP8v1ziTaAEPUr/3kLsY3Sftgz242A1SetQiDL7g==}
dependencies: dependencies:
@@ -12851,38 +12851,44 @@ packages:
'@types/whatwg-url': 8.2.2 '@types/whatwg-url': 8.2.2
whatwg-url: 11.0.0 whatwg-url: 11.0.0
/mongodb-memory-server-core@8.13.0: /mongodb-memory-server-core@9.1.7:
resolution: {integrity: sha512-4NTOzYOlRUilwb8CxOKix/XbZmac4cLpmEU03eaHx90lgEp+ARZM2PQtIOEg3nhHo97r9THIEv6Gs4LECokp0Q==} resolution: {integrity: sha512-q8geqCmt5hGuxaDhRo03ZUB0ITr6lnJ3jffdNiC4nDq13WbHUfY2A1RQq3OHDbdrY6aRYvZphx2bcXYBFRis3A==}
engines: {node: '>=12.22.0'} engines: {node: '>=14.20.1'}
dependencies: dependencies:
async-mutex: 0.3.2 async-mutex: 0.4.1
camelcase: 6.3.0 camelcase: 6.3.0
debug: 4.3.4(supports-color@5.5.0) debug: 4.3.4(supports-color@5.5.0)
find-cache-dir: 3.3.2 find-cache-dir: 3.3.2
get-port: 5.1.1 follow-redirects: 1.15.5(debug@4.3.4)
https-proxy-agent: 5.0.1 https-proxy-agent: 7.0.4
md5-file: 5.0.0 mongodb: 5.9.2
mongodb: 4.17.1
new-find-package-json: 2.0.0 new-find-package-json: 2.0.0
semver: 7.6.0 semver: 7.6.0
tar-stream: 2.2.0 tar-stream: 3.1.7
tslib: 2.6.2 tslib: 2.6.2
uuid: 9.0.1
yauzl: 2.10.0 yauzl: 2.10.0
transitivePeerDependencies: transitivePeerDependencies:
- aws-crt - '@aws-sdk/credential-providers'
- '@mongodb-js/zstd'
- kerberos
- mongodb-client-encryption
- snappy
- supports-color - supports-color
dev: true dev: true
/mongodb-memory-server@8.13.0: /mongodb-memory-server@9.1.7:
resolution: {integrity: sha512-CyrKMwEmRePn8iQ3LtWQiOJxlGK0eM+NNTq3Yg8m7gaywepFu24mF7s13q87Kfuq0WgBuCJQ4t6VcUZJ4m+KWQ==} resolution: {integrity: sha512-Yxw1cUMoCKTK6jxk4cKG07P+Z/qOmuCVyt3ScIDaoHeOCbOlg2sEtXYO9vEK/tzpj/1KHdDStU2oYrsJ8Fvm0A==}
engines: {node: '>=12.22.0'} engines: {node: '>=14.20.1'}
requiresBuild: true requiresBuild: true
dependencies: dependencies:
mongodb-memory-server-core: 8.13.0 mongodb-memory-server-core: 9.1.7
tslib: 2.6.2 tslib: 2.6.2
transitivePeerDependencies: transitivePeerDependencies:
- aws-crt - '@aws-sdk/credential-providers'
- '@mongodb-js/zstd'
- kerberos
- mongodb-client-encryption
- snappy
- supports-color - supports-color
dev: true dev: true
@@ -12899,6 +12905,34 @@ packages:
transitivePeerDependencies: transitivePeerDependencies:
- aws-crt - aws-crt
/mongodb@5.9.2:
resolution: {integrity: sha512-H60HecKO4Bc+7dhOv4sJlgvenK4fQNqqUIlXxZYQNbfEWSALGAwGoyJd/0Qwk4TttFXUOHJ2ZJQe/52ScaUwtQ==}
engines: {node: '>=14.20.1'}
peerDependencies:
'@aws-sdk/credential-providers': ^3.188.0
'@mongodb-js/zstd': ^1.0.0
kerberos: ^1.0.0 || ^2.0.0
mongodb-client-encryption: '>=2.3.0 <3'
snappy: ^7.2.2
peerDependenciesMeta:
'@aws-sdk/credential-providers':
optional: true
'@mongodb-js/zstd':
optional: true
kerberos:
optional: true
mongodb-client-encryption:
optional: true
snappy:
optional: true
dependencies:
bson: 5.5.1
mongodb-connection-string-url: 2.6.0
socks: 2.8.1
optionalDependencies:
'@mongodb-js/saslprep': 1.1.4
dev: true
/mongoose-aggregate-paginate-v2@1.0.6: /mongoose-aggregate-paginate-v2@1.0.6:
resolution: {integrity: sha512-UuALu+mjhQa1K9lMQvjLL3vm3iALvNw8PQNIh2gp1b+tO5hUa0NC0Wf6/8QrT9PSJVTihXaD8hQVy3J4e0jO0Q==} resolution: {integrity: sha512-UuALu+mjhQa1K9lMQvjLL3vm3iALvNw8PQNIh2gp1b+tO5hUa0NC0Wf6/8QrT9PSJVTihXaD8hQVy3J4e0jO0Q==}
engines: {node: '>=4.0.0'} engines: {node: '>=4.0.0'}

View File

@@ -1,5 +1,4 @@
import type { Payload } from '../../packages/payload/src/index.js' import type { Payload } from '../../packages/payload/src/index.js'
import { getPayload } from '../../packages/payload/src/index.js' import { getPayload } from '../../packages/payload/src/index.js'
import { devUser } from '../credentials.js' import { devUser } from '../credentials.js'
import { NextRESTClient } from '../helpers/NextRESTClient.js' import { NextRESTClient } from '../helpers/NextRESTClient.js'
@@ -36,7 +35,7 @@ describe('_Community Tests', () => {
afterAll(async () => { afterAll(async () => {
if (typeof payload.db.destroy === 'function') { if (typeof payload.db.destroy === 'function') {
await payload.db.destroy(payload) await payload.db.destroy()
} }
}) })

View File

@@ -1,5 +1,4 @@
import type { Payload } from '../../../packages/payload/src/index.js' import type { Payload } from '../../../packages/payload/src/index.js'
import { getPayload } from '../../../packages/payload/src/index.js' import { getPayload } from '../../../packages/payload/src/index.js'
import { NextRESTClient } from '../../helpers/NextRESTClient.js' import { NextRESTClient } from '../../helpers/NextRESTClient.js'
import { startMemoryDB } from '../../startMemoryDB.js' import { startMemoryDB } from '../../startMemoryDB.js'
@@ -24,7 +23,7 @@ describe('AuthStrategies', () => {
afterAll(async () => { afterAll(async () => {
if (typeof payload.db.destroy === 'function') { if (typeof payload.db.destroy === 'function') {
await payload.db.destroy(payload) await payload.db.destroy()
} }
}) })

View File

@@ -2,7 +2,6 @@ import jwtDecode from 'jwt-decode'
import type { User } from '../../packages/payload/src/auth/index.js' import type { User } from '../../packages/payload/src/auth/index.js'
import type { Payload } from '../../packages/payload/src/index.js' import type { Payload } from '../../packages/payload/src/index.js'
import { getPayload } from '../../packages/payload/src/index.js' import { getPayload } from '../../packages/payload/src/index.js'
import { devUser } from '../credentials.js' import { devUser } from '../credentials.js'
import { NextRESTClient } from '../helpers/NextRESTClient.js' import { NextRESTClient } from '../helpers/NextRESTClient.js'
@@ -24,7 +23,7 @@ describe('Auth', () => {
afterAll(async () => { afterAll(async () => {
if (typeof payload.db.destroy === 'function') { if (typeof payload.db.destroy === 'function') {
await payload.db.destroy(payload) await payload.db.destroy()
} }
}) })

View File

@@ -1,11 +1,9 @@
import type { Payload } from '../../../packages/payload/src/index.js' import type { Payload } from '../../../packages/payload/src/index.js'
import { getPayload } from '../../../packages/payload/src/index.js' import { getPayload } from '../../../packages/payload/src/index.js'
import { devUser } from '../../credentials.js' import { devUser } from '../../credentials.js'
import { NextRESTClient } from '../../helpers/NextRESTClient.js' import { NextRESTClient } from '../../helpers/NextRESTClient.js'
import { startMemoryDB } from '../../startMemoryDB.js' import { startMemoryDB } from '../../startMemoryDB.js'
import { collectionSlug } from './config.js' import configPromise, { collectionSlug } from './config.js'
import configPromise from './config.js'
let restClient: NextRESTClient let restClient: NextRESTClient
let payload: Payload let payload: Payload
@@ -24,7 +22,7 @@ describe('Remove token from auth responses', () => {
afterAll(async () => { afterAll(async () => {
if (typeof payload.db.destroy === 'function') { if (typeof payload.db.destroy === 'function') {
await payload.db.destroy(payload) await payload.db.destroy()
} }
}) })

View File

@@ -1,7 +1,6 @@
import type { Payload } from '../../packages/payload/src/index.js' import type { Payload } from '../../packages/payload/src/index.js'
import type { Post } from './payload-types.js'
import { getPayload } from '../../packages/payload/src/index.js' import { getPayload } from '../../packages/payload/src/index.js'
import type { Post } from './payload-types.js'
import { mapAsync } from '../../packages/payload/src/utilities/mapAsync.js' import { mapAsync } from '../../packages/payload/src/utilities/mapAsync.js'
import { NextRESTClient } from '../helpers/NextRESTClient.js' import { NextRESTClient } from '../helpers/NextRESTClient.js'
import { idToString } from '../helpers/idToString.js' import { idToString } from '../helpers/idToString.js'
@@ -33,7 +32,7 @@ describe('collections-graphql', () => {
afterAll(async () => { afterAll(async () => {
if (typeof payload.db.destroy === 'function') { if (typeof payload.db.destroy === 'function') {
await payload.db.destroy(payload) await payload.db.destroy()
} }
}) })

View File

@@ -1,13 +1,8 @@
import { randomBytes } from 'crypto' import { randomBytes } from 'crypto'
import type { Payload } from '../../packages/payload/src/index.js' import type { Payload } from '../../packages/payload/src/index.js'
import type { Relation } from './config.js'
import type { Post } from './payload-types.js'
import { getPayload } from '../../packages/payload/src/index.js' import { getPayload } from '../../packages/payload/src/index.js'
import { mapAsync } from '../../packages/payload/src/utilities/mapAsync.js' import type { Relation } from './config.js'
import { NextRESTClient } from '../helpers/NextRESTClient.js'
import { startMemoryDB } from '../startMemoryDB.js'
import configPromise, { import configPromise, {
customIdNumberSlug, customIdNumberSlug,
customIdSlug, customIdSlug,
@@ -16,6 +11,10 @@ import configPromise, {
relationSlug, relationSlug,
slug, slug,
} from './config.js' } from './config.js'
import type { Post } from './payload-types.js'
import { mapAsync } from '../../packages/payload/src/utilities/mapAsync.js'
import { NextRESTClient } from '../helpers/NextRESTClient.js'
import { startMemoryDB } from '../startMemoryDB.js'
let restClient: NextRESTClient let restClient: NextRESTClient
let payload: Payload let payload: Payload
@@ -40,7 +39,7 @@ describe('collections-rest', () => {
afterAll(async () => { afterAll(async () => {
if (typeof payload.db.destroy === 'function') { if (typeof payload.db.destroy === 'function') {
await payload.db.destroy(payload) await payload.db.destroy()
} }
}) })

View File

@@ -1,6 +1,5 @@
import type { BlockField } from '../../packages/payload/src/fields/config/types.js' import type { BlockField } from '../../packages/payload/src/fields/config/types.js'
import type { Payload } from '../../packages/payload/src/index.js' import type { Payload } from '../../packages/payload/src/index.js'
import { getPayload } from '../../packages/payload/src/index.js' import { getPayload } from '../../packages/payload/src/index.js'
import { startMemoryDB } from '../startMemoryDB.js' import { startMemoryDB } from '../startMemoryDB.js'
import configPromise from './config.js' import configPromise from './config.js'
@@ -13,6 +12,12 @@ describe('Config', () => {
payload = await getPayload({ config }) payload = await getPayload({ config })
}) })
afterAll(async () => {
if (typeof payload.db.destroy === 'function') {
await payload.db.destroy()
}
})
describe('payload config', () => { describe('payload config', () => {
it('allows a custom field at the config root', () => { it('allows a custom field at the config root', () => {
const { config } = payload const { config } = payload

View File

@@ -10,6 +10,7 @@ import { fileURLToPath } from 'url'
import { promisify } from 'util' import { promisify } from 'util'
import { initNext } from '../../packages/create-payload-app/src/lib/init-next.js' import { initNext } from '../../packages/create-payload-app/src/lib/init-next.js'
const filename = fileURLToPath(import.meta.url) const filename = fileURLToPath(import.meta.url)
const dirname = path.dirname(filename) const dirname = path.dirname(filename)

View File

@@ -12,6 +12,12 @@ describe('Custom GraphQL', () => {
restClient = new NextRESTClient(payload.config) restClient = new NextRESTClient(payload.config)
}) })
afterAll(async () => {
if (typeof payload.db.destroy === 'function') {
await payload.db.destroy()
}
})
describe('Isolated Transaction ID', () => { describe('Isolated Transaction ID', () => {
it('should isolate transaction IDs between queries in the same request', async () => { it('should isolate transaction IDs between queries in the same request', async () => {
const query = `query { const query = `query {

View File

@@ -6,15 +6,15 @@ import { fileURLToPath } from 'url'
import type { PostgresAdapter } from '../../packages/db-postgres/src/types.js' import type { PostgresAdapter } from '../../packages/db-postgres/src/types.js'
import type { TypeWithID } from '../../packages/payload/src/collections/config/types.js' import type { TypeWithID } from '../../packages/payload/src/collections/config/types.js'
import type { Payload } from '../../packages/payload/src/index.js' import type { Payload } from '../../packages/payload/src/index.js'
import type { PayloadRequest } from '../../packages/payload/src/types/index.js'
import { getPayload } from '../../packages/payload/src/index.js' import { getPayload } from '../../packages/payload/src/index.js'
import type { PayloadRequest } from '../../packages/payload/src/types/index.js'
import { commitTransaction } from '../../packages/payload/src/utilities/commitTransaction.js' import { commitTransaction } from '../../packages/payload/src/utilities/commitTransaction.js'
import { initTransaction } from '../../packages/payload/src/utilities/initTransaction.js' import { initTransaction } from '../../packages/payload/src/utilities/initTransaction.js'
import { devUser } from '../credentials.js' import { devUser } from '../credentials.js'
import removeFiles from '../helpers/removeFiles.js' import removeFiles from '../helpers/removeFiles.js'
import { startMemoryDB } from '../startMemoryDB.js' import { startMemoryDB } from '../startMemoryDB.js'
import configPromise from './config.js' import configPromise from './config.js'
const filename = fileURLToPath(import.meta.url) const filename = fileURLToPath(import.meta.url)
const dirname = path.dirname(filename) const dirname = path.dirname(filename)
@@ -40,6 +40,13 @@ describe('database', () => {
user = loginResult.user user = loginResult.user
}) })
afterAll(async () => {
if (typeof payload.db.destroy === 'function') {
await payload.db.destroy()
}
})
describe('migrations', () => { describe('migrations', () => {
beforeAll(async () => { beforeAll(async () => {
if (process.env.PAYLOAD_DROP_DATABASE === 'true' && 'drizzle' in payload.db) { if (process.env.PAYLOAD_DROP_DATABASE === 'true' && 'drizzle' in payload.db) {

View File

@@ -1,11 +1,9 @@
import type { Payload } from '../../packages/payload/src/index.js' import type { Payload } from '../../packages/payload/src/index.js'
import { getPayload } from '../../packages/payload/src/index.js' import { getPayload } from '../../packages/payload/src/index.js'
import { devUser } from '../credentials.js' import { devUser } from '../credentials.js'
import { NextRESTClient } from '../helpers/NextRESTClient.js' import { NextRESTClient } from '../helpers/NextRESTClient.js'
import { startMemoryDB } from '../startMemoryDB.js' import { startMemoryDB } from '../startMemoryDB.js'
import configPromise from './config.js' import configPromise, { postDoc } from './config.js'
import { postDoc } from './config.js'
let restClient: NextRESTClient let restClient: NextRESTClient
let payload: Payload let payload: Payload
@@ -28,6 +26,12 @@ describe('dataloader', () => {
if (loginResult.token) token = loginResult.token if (loginResult.token) token = loginResult.token
}) })
afterAll(async () => {
if (typeof payload.db.destroy === 'function') {
await payload.db.destroy()
}
})
describe('graphql', () => { describe('graphql', () => {
it('should allow querying via graphql', async () => { it('should allow querying via graphql', async () => {
const query = `query { const query = `query {

View File

@@ -1,4 +1,4 @@
import { getPayload } from '../../packages/payload/src/index.js' import { getPayload, type Payload } from '../../packages/payload/src/index.js'
import { NextRESTClient } from '../helpers/NextRESTClient.js' import { NextRESTClient } from '../helpers/NextRESTClient.js'
import { startMemoryDB } from '../startMemoryDB.js' import { startMemoryDB } from '../startMemoryDB.js'
import configPromise from './config.js' import configPromise from './config.js'
@@ -12,15 +12,22 @@ import {
rootEndpoint, rootEndpoint,
} from './shared.js' } from './shared.js'
let payload: Payload
let restClient: NextRESTClient let restClient: NextRESTClient
describe('Endpoints', () => { describe('Endpoints', () => {
beforeAll(async () => { beforeAll(async () => {
const config = await startMemoryDB(configPromise) const config = await startMemoryDB(configPromise)
await getPayload({ config }) payload = await getPayload({ config })
restClient = new NextRESTClient(config) restClient = new NextRESTClient(config)
}) })
afterAll(async () => {
if (typeof payload.db.destroy === 'function') {
await payload.db.destroy()
}
})
describe('Collections', () => { describe('Collections', () => {
it('should GET a static endpoint', async () => { it('should GET a static endpoint', async () => {
const response = await restClient.GET(`/${collectionSlug}/say-hello/joe-bloggs`) const response = await restClient.GET(`/${collectionSlug}/say-hello/joe-bloggs`)

View File

@@ -3,9 +3,8 @@ import type { IndexDirection, IndexOptions } from 'mongoose'
import type { MongooseAdapter } from '../../packages/db-mongodb/src/index.js' import type { MongooseAdapter } from '../../packages/db-mongodb/src/index.js'
import type { PaginatedDocs } from '../../packages/payload/src/database/types.js' import type { PaginatedDocs } from '../../packages/payload/src/database/types.js'
import type { Payload } from '../../packages/payload/src/index.js' import type { Payload } from '../../packages/payload/src/index.js'
import type { GroupField, RichTextField } from './payload-types.js'
import { getPayload } from '../../packages/payload/src/index.js' import { getPayload } from '../../packages/payload/src/index.js'
import type { GroupField, RichTextField } from './payload-types.js'
import { devUser } from '../credentials.js' import { devUser } from '../credentials.js'
import { NextRESTClient } from '../helpers/NextRESTClient.js' import { NextRESTClient } from '../helpers/NextRESTClient.js'
import { isMongoose } from '../helpers/isMongoose.js' import { isMongoose } from '../helpers/isMongoose.js'
@@ -18,11 +17,7 @@ import { groupDoc } from './collections/Group/shared.js'
import { defaultNumber } from './collections/Number/index.js' import { defaultNumber } from './collections/Number/index.js'
import { numberDoc } from './collections/Number/shared.js' import { numberDoc } from './collections/Number/shared.js'
import { pointDoc } from './collections/Point/shared.js' import { pointDoc } from './collections/Point/shared.js'
import { import { localizedTextValue, namedTabDefaultValue, namedTabText, } from './collections/Tabs/constants.js'
localizedTextValue,
namedTabDefaultValue,
namedTabText,
} from './collections/Tabs/constants.js'
import { tabsDoc } from './collections/Tabs/shared.js' import { tabsDoc } from './collections/Tabs/shared.js'
import { defaultText } from './collections/Text/shared.js' import { defaultText } from './collections/Text/shared.js'
import configPromise from './config.js' import configPromise from './config.js'
@@ -59,6 +54,12 @@ describe('Fields', () => {
}) })
}) })
afterAll(async () => {
if (typeof payload.db.destroy === 'function') {
await payload.db.destroy()
}
})
beforeEach(async () => { beforeEach(async () => {
await clearAndSeedEverything(payload) await clearAndSeedEverything(payload)
await restClient.login({ await restClient.login({

View File

@@ -1,5 +1,4 @@
import type { Payload } from '../../packages/payload/src/index.js' import type { Payload } from '../../packages/payload/src/index.js'
import { getPayload } from '../../packages/payload/src/index.js' import { getPayload } from '../../packages/payload/src/index.js'
import { NextRESTClient } from '../helpers/NextRESTClient.js' import { NextRESTClient } from '../helpers/NextRESTClient.js'
import { startMemoryDB } from '../startMemoryDB.js' import { startMemoryDB } from '../startMemoryDB.js'
@@ -21,6 +20,13 @@ describe('globals', () => {
payload = await getPayload({ config }) payload = await getPayload({ config })
restClient = new NextRESTClient(config) restClient = new NextRESTClient(config)
}) })
afterAll(async () => {
if (typeof payload.db.destroy === 'function') {
await payload.db.destroy()
}
})
describe('REST', () => { describe('REST', () => {
it('should create', async () => { it('should create', async () => {
const title = 'update' const title = 'update'

View File

@@ -1,8 +1,8 @@
import type { Payload } from '../../packages/payload/src/index.js' import type { Payload } from '../../packages/payload/src/index.js'
import { getPayload } from '../../packages/payload/src/index.js'
import type { NestedAfterReadHook } from './payload-types.js' import type { NestedAfterReadHook } from './payload-types.js'
import { AuthenticationError } from '../../packages/payload/src/errors/index.js' import { AuthenticationError } from '../../packages/payload/src/errors/index.js'
import { getPayload } from '../../packages/payload/src/index.js'
import { devUser, regularUser } from '../credentials.js' import { devUser, regularUser } from '../credentials.js'
import { NextRESTClient } from '../helpers/NextRESTClient.js' import { NextRESTClient } from '../helpers/NextRESTClient.js'
import { startMemoryDB } from '../startMemoryDB.js' import { startMemoryDB } from '../startMemoryDB.js'
@@ -11,10 +11,7 @@ import { chainingHooksSlug } from './collections/ChainingHooks/index.js'
import { contextHooksSlug } from './collections/ContextHooks/index.js' import { contextHooksSlug } from './collections/ContextHooks/index.js'
import { dataHooksSlug } from './collections/Data/index.js' import { dataHooksSlug } from './collections/Data/index.js'
import { hooksSlug } from './collections/Hook/index.js' import { hooksSlug } from './collections/Hook/index.js'
import { import { generatedAfterReadText, nestedAfterReadHooksSlug, } from './collections/NestedAfterReadHooks/index.js'
generatedAfterReadText,
nestedAfterReadHooksSlug,
} from './collections/NestedAfterReadHooks/index.js'
import { relationsSlug } from './collections/Relations/index.js' import { relationsSlug } from './collections/Relations/index.js'
import { transformSlug } from './collections/Transform/index.js' import { transformSlug } from './collections/Transform/index.js'
import { hooksUsersSlug } from './collections/Users/index.js' import { hooksUsersSlug } from './collections/Users/index.js'
@@ -33,7 +30,7 @@ describe('Hooks', () => {
afterAll(async () => { afterAll(async () => {
if (typeof payload.db.destroy === 'function') { if (typeof payload.db.destroy === 'function') {
await payload.db.destroy(payload) await payload.db.destroy()
} }
}) })

View File

@@ -2,12 +2,12 @@ import path from 'path'
import { fileURLToPath } from 'url' import { fileURLToPath } from 'url'
import type { Payload } from '../../packages/payload/src/index.js' import type { Payload } from '../../packages/payload/src/index.js'
import { getPayload } from '../../packages/payload/src/index.js'
import type { Media, Page, Post, Tenant } from './payload-types.js' import type { Media, Page, Post, Tenant } from './payload-types.js'
import { handleMessage } from '../../packages/live-preview/src/handleMessage.js' import { handleMessage } from '../../packages/live-preview/src/handleMessage.js'
import { mergeData } from '../../packages/live-preview/src/mergeData.js' import { mergeData } from '../../packages/live-preview/src/mergeData.js'
import { traverseRichText } from '../../packages/live-preview/src/traverseRichText.js' import { traverseRichText } from '../../packages/live-preview/src/traverseRichText.js'
import { getPayload } from '../../packages/payload/src/index.js'
import getFileByPath from '../../packages/payload/src/uploads/getFileByPath.js' import getFileByPath from '../../packages/payload/src/uploads/getFileByPath.js'
import { fieldSchemaToJSON } from '../../packages/payload/src/utilities/fieldSchemaToJSON.js' import { fieldSchemaToJSON } from '../../packages/payload/src/utilities/fieldSchemaToJSON.js'
import { NextRESTClient } from '../helpers/NextRESTClient.js' import { NextRESTClient } from '../helpers/NextRESTClient.js'
@@ -16,6 +16,7 @@ import { Pages } from './collections/Pages.js'
import { postsSlug } from './collections/Posts.js' import { postsSlug } from './collections/Posts.js'
import configPromise from './config.js' import configPromise from './config.js'
import { tenantsSlug } from './shared.js' import { tenantsSlug } from './shared.js'
const filename = fileURLToPath(import.meta.url) const filename = fileURLToPath(import.meta.url)
const dirname = path.dirname(filename) const dirname = path.dirname(filename)
@@ -71,6 +72,12 @@ describe('Collections - Live Preview', () => {
}) })
}) })
afterAll(async () => {
if (typeof payload.db.destroy === 'function') {
await payload.db.destroy()
}
})
it('handles `postMessage`', async () => { it('handles `postMessage`', async () => {
const handledMessage = await handleMessage({ const handledMessage = await handleMessage({
depth: 1, depth: 1,

View File

@@ -1,8 +1,7 @@
import type { Payload } from '../../packages/payload/src/index.js' import type { Payload } from '../../packages/payload/src/index.js'
import { getPayload } from '../../packages/payload/src/index.js'
import type { Where } from '../../packages/payload/src/types/index.js' import type { Where } from '../../packages/payload/src/types/index.js'
import type { LocalizedPost, WithLocalizedRelationship } from './payload-types.js' import type { LocalizedPost, WithLocalizedRelationship } from './payload-types.js'
import { getPayload } from '../../packages/payload/src/index.js'
import { englishLocale } from '../globals/config.js' import { englishLocale } from '../globals/config.js'
import { NextRESTClient } from '../helpers/NextRESTClient.js' import { NextRESTClient } from '../helpers/NextRESTClient.js'
import { idToString } from '../helpers/idToString.js' import { idToString } from '../helpers/idToString.js'
@@ -18,9 +17,9 @@ import {
portugueseLocale, portugueseLocale,
relationEnglishTitle, relationEnglishTitle,
relationEnglishTitle2, relationEnglishTitle2,
relationshipLocalizedSlug,
relationSpanishTitle, relationSpanishTitle,
relationSpanishTitle2, relationSpanishTitle2,
relationshipLocalizedSlug,
spanishLocale, spanishLocale,
spanishTitle, spanishTitle,
withLocalizedRelSlug, withLocalizedRelSlug,
@@ -68,7 +67,7 @@ describe('Localization', () => {
afterAll(async () => { afterAll(async () => {
if (typeof payload.db.destroy === 'function') { if (typeof payload.db.destroy === 'function') {
await payload.db.destroy(payload) await payload.db.destroy()
} }
}) })

View File

@@ -4,11 +4,11 @@ import path from 'path'
import { fileURLToPath } from 'url' import { fileURLToPath } from 'url'
import type { Payload } from '../../packages/payload/src/index.js' import type { Payload } from '../../packages/payload/src/index.js'
import { getPayload } from '../../packages/payload/src/index.js' import { getPayload } from '../../packages/payload/src/index.js'
import { describeIfInCIOrHasLocalstack } from '../helpers.js' import { describeIfInCIOrHasLocalstack } from '../helpers.js'
import { startMemoryDB } from '../startMemoryDB.js' import { startMemoryDB } from '../startMemoryDB.js'
import configPromise from './config.js' import configPromise from './config.js'
const filename = fileURLToPath(import.meta.url) const filename = fileURLToPath(import.meta.url)
const dirname = path.dirname(filename) const dirname = path.dirname(filename)
@@ -19,6 +19,13 @@ describe('@payloadcms/plugin-cloud-storage', () => {
const config = await startMemoryDB(configPromise) const config = await startMemoryDB(configPromise)
payload = await getPayload({ config }) payload = await getPayload({ config })
}) })
afterAll(async () => {
if (typeof payload.db.destroy === 'function') {
await payload.db.destroy()
}
})
const TEST_BUCKET = 'payload-bucket' const TEST_BUCKET = 'payload-bucket'
let client: AWS.S3Client let client: AWS.S3Client

View File

@@ -1,5 +1,4 @@
import type { Payload } from '../../packages/payload/src/index.js' import type { Payload } from '../../packages/payload/src/index.js'
import { getPayload } from '../../packages/payload/src/index.js' import { getPayload } from '../../packages/payload/src/index.js'
import { startMemoryDB } from '../startMemoryDB.js' import { startMemoryDB } from '../startMemoryDB.js'
import configPromise from './config.js' import configPromise from './config.js'
@@ -12,6 +11,12 @@ describe('@payloadcms/plugin-cloud', () => {
payload = await getPayload({ config }) payload = await getPayload({ config })
}) })
afterAll(async () => {
if (typeof payload.db.destroy === 'function') {
await payload.db.destroy()
}
})
describe('tests', () => { describe('tests', () => {
it.todo('plugin-cloud tests') it.todo('plugin-cloud tests')
}) })

View File

@@ -1,13 +1,13 @@
import type { Payload } from '../../packages/payload/src/index.js' import type { Payload } from '../../packages/payload/src/index.js'
import { getPayload } from '../../packages/payload/src/index.js'
import type { Form } from './payload-types.js' import type { Form } from './payload-types.js'
import { ValidationError } from '../../packages/payload/src/errors/index.js' import { ValidationError } from '../../packages/payload/src/errors/index.js'
import { getPayload } from '../../packages/payload/src/index.js'
import { serializeLexical } from '../../packages/plugin-form-builder/src/utilities/lexical/serializeLexical.js' import { serializeLexical } from '../../packages/plugin-form-builder/src/utilities/lexical/serializeLexical.js'
import { serializeSlate } from '../../packages/plugin-form-builder/src/utilities/slate/serializeSlate.js' import { serializeSlate } from '../../packages/plugin-form-builder/src/utilities/slate/serializeSlate.js'
import { startMemoryDB } from '../startMemoryDB.js' import { startMemoryDB } from '../startMemoryDB.js'
import configPromise from './config.js' import configPromise from './config.js'
import { formSubmissionsSlug, formsSlug } from './shared.js' import { formsSlug, formSubmissionsSlug } from './shared.js'
let payload: Payload let payload: Payload
let form: Form let form: Form
@@ -39,6 +39,12 @@ describe('@payloadcms/plugin-form-builder', () => {
})) as unknown as Form })) as unknown as Form
}) })
afterAll(async () => {
if (typeof payload.db.destroy === 'function') {
await payload.db.destroy()
}
})
describe('plugin collections', () => { describe('plugin collections', () => {
it('adds forms collection', async () => { it('adds forms collection', async () => {
const { docs: forms } = await payload.find({ collection: formsSlug }) const { docs: forms } = await payload.find({ collection: formsSlug })

View File

@@ -1,9 +1,5 @@
import type { import type { ArrayField, RelationshipField, } from '../../packages/payload/src/fields/config/types.js'
ArrayField,
RelationshipField,
} from '../../packages/payload/src/fields/config/types.js'
import type { Payload } from '../../packages/payload/src/index.js' import type { Payload } from '../../packages/payload/src/index.js'
import { getPayload } from '../../packages/payload/src/index.js' import { getPayload } from '../../packages/payload/src/index.js'
import { startMemoryDB } from '../startMemoryDB.js' import { startMemoryDB } from '../startMemoryDB.js'
import configPromise from './config.js' import configPromise from './config.js'
@@ -16,6 +12,12 @@ describe('@payloadcms/plugin-nested-docs', () => {
payload = await getPayload({ config }) payload = await getPayload({ config })
}) })
afterAll(async () => {
if (typeof payload.db.destroy === 'function') {
await payload.db.destroy()
}
})
describe('seed', () => { describe('seed', () => {
it('should populate two levels of breadcrumbs', async () => { it('should populate two levels of breadcrumbs', async () => {
const query = await payload.find({ const query = await payload.find({

View File

@@ -1,7 +1,6 @@
import type { Payload } from '../../packages/payload/src/index.js' import type { Payload } from '../../packages/payload/src/index.js'
import type { Page } from './payload-types.js'
import { getPayload } from '../../packages/payload/src/index.js' import { getPayload } from '../../packages/payload/src/index.js'
import type { Page } from './payload-types.js'
import { startMemoryDB } from '../startMemoryDB.js' import { startMemoryDB } from '../startMemoryDB.js'
import configPromise from './config.js' import configPromise from './config.js'
import { pagesSlug } from './shared.js' import { pagesSlug } from './shared.js'
@@ -22,6 +21,12 @@ describe('@payloadcms/plugin-redirects', () => {
}) })
}) })
afterAll(async () => {
if (typeof payload.db.destroy === 'function') {
await payload.db.destroy()
}
})
it('should add a redirects collection', async () => { it('should add a redirects collection', async () => {
const redirect = await payload.find({ const redirect = await payload.find({
collection: 'redirects', collection: 'redirects',

View File

@@ -1,5 +1,4 @@
import type { Payload } from '../../packages/payload/src/index.js' import type { Payload } from '../../packages/payload/src/index.js'
import { getPayload } from '../../packages/payload/src/index.js' import { getPayload } from '../../packages/payload/src/index.js'
import wait from '../../packages/payload/src/utilities/wait.js' import wait from '../../packages/payload/src/utilities/wait.js'
import { startMemoryDB } from '../startMemoryDB.js' import { startMemoryDB } from '../startMemoryDB.js'
@@ -13,6 +12,12 @@ describe('@payloadcms/plugin-search', () => {
payload = await getPayload({ config }) payload = await getPayload({ config })
}) })
afterAll(async () => {
if (typeof payload.db.destroy === 'function') {
await payload.db.destroy()
}
})
it('should add a search collection', async () => { it('should add a search collection', async () => {
const search = await payload.find({ const search = await payload.find({
collection: 'search', collection: 'search',

View File

@@ -1,5 +1,4 @@
import type { Payload } from '../../packages/payload/src/index.js' import type { Payload } from '../../packages/payload/src/index.js'
import { getPayload } from '../../packages/payload/src/index.js' import { getPayload } from '../../packages/payload/src/index.js'
import { startMemoryDB } from '../startMemoryDB.js' import { startMemoryDB } from '../startMemoryDB.js'
import configPromise from './config.js' import configPromise from './config.js'
@@ -12,6 +11,12 @@ describe('@payloadcms/plugin-sentry', () => {
payload = await getPayload({ config }) payload = await getPayload({ config })
}) })
afterAll(async () => {
if (typeof payload.db.destroy === 'function') {
await payload.db.destroy()
}
})
describe('tests', () => { describe('tests', () => {
it.todo('plugin-sentry tests') it.todo('plugin-sentry tests')
}) })

View File

@@ -2,13 +2,13 @@ import path from 'path'
import { fileURLToPath } from 'url' import { fileURLToPath } from 'url'
import type { Payload } from '../../packages/payload/src/index.js' import type { Payload } from '../../packages/payload/src/index.js'
import { getPayload } from '../../packages/payload/src/index.js' import { getPayload } from '../../packages/payload/src/index.js'
import getFileByPath from '../../packages/payload/src/uploads/getFileByPath.js' import getFileByPath from '../../packages/payload/src/uploads/getFileByPath.js'
import removeFiles from '../helpers/removeFiles.js' import removeFiles from '../helpers/removeFiles.js'
import { startMemoryDB } from '../startMemoryDB.js' import { startMemoryDB } from '../startMemoryDB.js'
import configPromise from './config.js' import configPromise from './config.js'
import { mediaSlug } from './shared.js' import { mediaSlug } from './shared.js'
const filename = fileURLToPath(import.meta.url) const filename = fileURLToPath(import.meta.url)
const dirname = path.dirname(filename) const dirname = path.dirname(filename)
@@ -48,6 +48,12 @@ describe('@payloadcms/plugin-seo', () => {
}) })
}) })
afterAll(async () => {
if (typeof payload.db.destroy === 'function') {
await payload.db.destroy()
}
})
it('should add meta title', async () => { it('should add meta title', async () => {
const pageWithTitle = await payload.update({ const pageWithTitle = await payload.update({
collection: 'pages', collection: 'pages',

View File

@@ -1,5 +1,4 @@
import type { Payload } from '../../packages/payload/src/index.js' import type { Payload } from '../../packages/payload/src/index.js'
import { getPayload } from '../../packages/payload/src/index.js' import { getPayload } from '../../packages/payload/src/index.js'
import { startMemoryDB } from '../startMemoryDB.js' import { startMemoryDB } from '../startMemoryDB.js'
import configPromise from './config.js' import configPromise from './config.js'
@@ -12,6 +11,12 @@ describe('Stripe Plugin', () => {
payload = await getPayload({ config }) payload = await getPayload({ config })
}) })
afterAll(async () => {
if (typeof payload.db.destroy === 'function') {
await payload.db.destroy()
}
})
it('should create products', async () => { it('should create products', async () => {
const product = await payload.create({ const product = await payload.create({
collection: 'products', collection: 'products',

View File

@@ -1,5 +1,4 @@
import type { Payload } from '../../packages/payload/src/index.js' import type { Payload } from '../../packages/payload/src/index.js'
import { getPayload } from '../../packages/payload/src/index.js' import { getPayload } from '../../packages/payload/src/index.js'
import { startMemoryDB } from '../startMemoryDB.js' import { startMemoryDB } from '../startMemoryDB.js'
import configPromise, { pagesSlug } from './config.js' import configPromise, { pagesSlug } from './config.js'
@@ -12,6 +11,12 @@ describe('Collections - Plugins', () => {
payload = await getPayload({ config }) payload = await getPayload({ config })
}) })
afterAll(async () => {
if (typeof payload.db.destroy === 'function') {
await payload.db.destroy()
}
})
it('created pages collection', async () => { it('created pages collection', async () => {
const { id } = await payload.create({ const { id } = await payload.create({
collection: pagesSlug, collection: pagesSlug,

View File

@@ -1,6 +1,7 @@
import { randomBytes } from 'crypto' import { randomBytes } from 'crypto'
import type { Payload } from '../../packages/payload/src/index.js' import type { Payload } from '../../packages/payload/src/index.js'
import { getPayload } from '../../packages/payload/src/index.js'
import type { import type {
ChainedRelation, ChainedRelation,
CustomIdNumberRelation, CustomIdNumberRelation,
@@ -9,8 +10,6 @@ import type {
Post, Post,
Relation, Relation,
} from './payload-types.js' } from './payload-types.js'
import { getPayload } from '../../packages/payload/src/index.js'
import { NextRESTClient } from '../helpers/NextRESTClient.js' import { NextRESTClient } from '../helpers/NextRESTClient.js'
import { startMemoryDB } from '../startMemoryDB.js' import { startMemoryDB } from '../startMemoryDB.js'
import configPromise from './config.js' import configPromise from './config.js'
@@ -41,7 +40,7 @@ describe('Relationships', () => {
afterAll(async () => { afterAll(async () => {
if (typeof payload.db.destroy === 'function') { if (typeof payload.db.destroy === 'function') {
await payload.db.destroy(payload) await payload.db.destroy()
} }
}) })

View File

@@ -1,4 +1,3 @@
import getPort from 'get-port'
import { MongoMemoryReplSet } from 'mongodb-memory-server' import { MongoMemoryReplSet } from 'mongodb-memory-server'
import type { SanitizedConfig } from '../packages/payload/src/config/types.js' import type { SanitizedConfig } from '../packages/payload/src/config/types.js'
@@ -22,20 +21,17 @@ export const startMemoryDB = async (
} }
default: { default: {
const port = await getPort()
const db = await MongoMemoryReplSet.create({ const db = await MongoMemoryReplSet.create({
instanceOpts: [
{
port,
},
],
replSet: { replSet: {
count: 3, count: 3,
dbName: 'payloadmemory', dbName: 'payloadmemory',
}, },
}) })
config.db = mongooseAdapter({ url: db.getUri() }) config.db = mongooseAdapter({
url: db.getUri(),
mongoMemoryServer: db,
})
return config return config
} }

View File

@@ -6,21 +6,14 @@ import { fileURLToPath } from 'url'
import { promisify } from 'util' import { promisify } from 'util'
import type { Payload } from '../../packages/payload/src/index.js' import type { Payload } from '../../packages/payload/src/index.js'
import type { Enlarge, Media } from './payload-types.js'
import { getPayload } from '../../packages/payload/src/index.js' import { getPayload } from '../../packages/payload/src/index.js'
import type { Enlarge, Media } from './payload-types.js'
import getFileByPath from '../../packages/payload/src/uploads/getFileByPath.js' import getFileByPath from '../../packages/payload/src/uploads/getFileByPath.js'
import { NextRESTClient } from '../helpers/NextRESTClient.js' import { NextRESTClient } from '../helpers/NextRESTClient.js'
import { startMemoryDB } from '../startMemoryDB.js' import { startMemoryDB } from '../startMemoryDB.js'
import configPromise from './config.js' import configPromise from './config.js'
import { import { enlargeSlug, mediaSlug, reduceSlug, relationSlug, unstoredMediaSlug, usersSlug, } from './shared.js'
enlargeSlug,
mediaSlug,
reduceSlug,
relationSlug,
unstoredMediaSlug,
usersSlug,
} from './shared.js'
const filename = fileURLToPath(import.meta.url) const filename = fileURLToPath(import.meta.url)
const dirname = path.dirname(filename) const dirname = path.dirname(filename)
@@ -84,6 +77,12 @@ describe('Collections - Uploads', () => {
await restClient.login({ slug: usersSlug }) await restClient.login({ slug: usersSlug })
}) })
afterAll(async () => {
if (typeof payload.db.destroy === 'function') {
await payload.db.destroy()
}
})
describe('REST', () => { describe('REST', () => {
describe('create', () => { describe('create', () => {
it('creates from form data given a png', async () => { it('creates from form data given a png', async () => {

View File

@@ -1,5 +1,4 @@
import type { Payload } from '../../packages/payload/src/index.js' import type { Payload } from '../../packages/payload/src/index.js'
import { getPayload } from '../../packages/payload/src/index.js' import { getPayload } from '../../packages/payload/src/index.js'
import { devUser } from '../credentials.js' import { devUser } from '../credentials.js'
import { NextRESTClient } from '../helpers/NextRESTClient.js' import { NextRESTClient } from '../helpers/NextRESTClient.js'
@@ -55,6 +54,12 @@ describe('Versions', () => {
token = data.loginUser.token token = data.loginUser.token
}) })
afterAll(async () => {
if (typeof payload.db.destroy === 'function') {
await payload.db.destroy()
}
})
beforeEach(async () => { beforeEach(async () => {
await clearAndSeedEverything(payload) await clearAndSeedEverything(payload)