test: refactor int tests to use initPayloadInt which reduces boilerplate

This commit is contained in:
Elliot DeNolf
2024-03-16 10:11:00 -04:00
parent ef141d499b
commit 14eb66c87d
52 changed files with 103 additions and 259 deletions

View File

@@ -10,3 +10,4 @@
**/temp **/temp
playwright.config.ts playwright.config.ts
jest.config.js jest.config.js
test/live-preview/next-app

View File

@@ -1,9 +1,8 @@
import type { Payload } from '../../packages/payload/src/index.js' import type { Payload } from '../../packages/payload/types.js'
import type { NextRESTClient } from '../helpers/NextRESTClient.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 { initPayloadInt } from '../helpers/initPayloadInt.js'
import { startMemoryDB } from '../startMemoryDB.js'
import { postsSlug } from './collections/Posts/index.js' import { postsSlug } from './collections/Posts/index.js'
import configPromise from './config.js' import configPromise from './config.js'
@@ -18,9 +17,8 @@ describe('_Community Tests', () => {
// Boilerplate test setup/teardown // Boilerplate test setup/teardown
// --__--__--__--__--__--__--__--__--__ // --__--__--__--__--__--__--__--__--__
beforeAll(async () => { beforeAll(async () => {
const config = await startMemoryDB(configPromise) const initialized = await initPayloadInt(configPromise)
payload = await getPayload({ config }) ;({ payload, restClient } = initialized)
restClient = new NextRESTClient(payload.config)
const data = await restClient const data = await restClient
.POST('/users/login', { .POST('/users/login', {

View File

@@ -2,10 +2,8 @@ import type { Payload, PayloadRequest } from '../../packages/payload/src/types/i
import type { Post, RelyOnRequestHeader, Restricted } from './payload-types.js' import type { Post, RelyOnRequestHeader, Restricted } from './payload-types.js'
import { Forbidden } from '../../packages/payload/src/errors/index.js' import { Forbidden } from '../../packages/payload/src/errors/index.js'
import { getPayload } from '../../packages/payload/src/index.js' import { initPayloadInt } from '../helpers/initPayloadInt.js'
import { startMemoryDB } from '../startMemoryDB.js' import configPromise, { requestHeaders } from './config.js'
import configPromise from './config.js'
import { requestHeaders } from './config.js'
import { import {
firstArrayText, firstArrayText,
hiddenAccessSlug, hiddenAccessSlug,
@@ -25,8 +23,7 @@ describe('Access Control', () => {
let restricted: Restricted let restricted: Restricted
beforeAll(async () => { beforeAll(async () => {
const config = await startMemoryDB(configPromise) ;({ payload } = await initPayloadInt(configPromise))
payload = await getPayload({ config })
}) })
beforeEach(async () => { beforeEach(async () => {
@@ -43,7 +40,7 @@ describe('Access Control', () => {
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

@@ -159,7 +159,3 @@ export interface PayloadMigration {
updatedAt: string updatedAt: string
createdAt: string createdAt: string
} }
declare module 'payload' {
export interface GeneratedTypes extends Config {}
}

View File

@@ -192,7 +192,3 @@ export interface GroupGlobalsTwo {
updatedAt?: string | null updatedAt?: string | null
createdAt?: string | null createdAt?: string | null
} }
declare module 'payload' {
export interface GeneratedTypes extends Config {}
}

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 { getPayload } from '../../packages/payload/src/index.js' import { initPayloadInt } from '../helpers/initPayloadInt.js'
import { startMemoryDB } from '../startMemoryDB.js'
import configPromise from './config.js' import configPromise from './config.js'
import { arraySlug } from './shared.js' import { arraySlug } from './shared.js'
@@ -9,13 +8,12 @@ let payload: Payload
describe('array-update', () => { describe('array-update', () => {
beforeAll(async () => { beforeAll(async () => {
const config = await startMemoryDB(configPromise) ;({ payload } = await initPayloadInt(configPromise))
payload = await getPayload({ config })
}) })
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,11 +2,10 @@ 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 type { NextRESTClient } from '../helpers/NextRESTClient.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 { initPayloadInt } from '../helpers/initPayloadInt.js'
import { startMemoryDB } from '../startMemoryDB.js'
import configPromise from './config.js' import configPromise from './config.js'
import { namedSaveToJWTValue, saveToJWTKey, slug } from './shared.js' import { namedSaveToJWTValue, saveToJWTKey, slug } from './shared.js'
@@ -17,9 +16,7 @@ const { email, password } = devUser
describe('Auth', () => { describe('Auth', () => {
beforeAll(async () => { beforeAll(async () => {
const config = await startMemoryDB(configPromise) ;({ payload, restClient } = await initPayloadInt(configPromise))
payload = await getPayload({ config })
restClient = new NextRESTClient(payload.config)
}) })
afterAll(async () => { afterAll(async () => {

View File

@@ -118,15 +118,3 @@ export interface PayloadMigration {
updatedAt: string updatedAt: string
createdAt: string createdAt: string
} }
declare module 'payload' {
export interface GeneratedTypes {
collections: {
users: User
'api-keys': ApiKey
'public-users': PublicUser
'payload-preferences': PayloadPreference
'payload-migrations': PayloadMigration
}
}
}

View File

@@ -4,6 +4,7 @@ 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 { mapAsync } from '../../packages/payload/src/utilities/mapAsync.js'
import { NextRESTClient } from '../helpers/NextRESTClient.js' import { NextRESTClient } from '../helpers/NextRESTClient.js'
import { initPayloadInt } from '../helpers/initPayloadInt.js'
import { idToString } from '../helpers/idToString.js' import { idToString } from '../helpers/idToString.js'
import { startMemoryDB } from '../startMemoryDB.js' import { startMemoryDB } from '../startMemoryDB.js'
import configPromise, { errorOnHookSlug, pointSlug, relationSlug, slug } from './config.js' import configPromise, { errorOnHookSlug, pointSlug, relationSlug, slug } from './config.js'
@@ -15,6 +16,8 @@ let payload: Payload
describe('collections-graphql', () => { describe('collections-graphql', () => {
beforeAll(async () => { beforeAll(async () => {
;({ payload, restClient } = await initPayloadInt(configPromise))
const config = await startMemoryDB(configPromise) const config = await startMemoryDB(configPromise)
payload = await getPayload({ config }) payload = await getPayload({ config })
restClient = new NextRESTClient(payload.config) restClient = new NextRESTClient(payload.config)

View File

@@ -1,16 +1,14 @@
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 { initPayloadInt } from '../helpers/initPayloadInt.js'
import { startMemoryDB } from '../startMemoryDB.js'
import configPromise from './config.js' import configPromise from './config.js'
let payload: Payload let payload: Payload
describe('Config', () => { describe('Config', () => {
beforeAll(async () => { beforeAll(async () => {
const config = await startMemoryDB(configPromise) ;({ payload } = await initPayloadInt(configPromise))
payload = await getPayload({ config })
}) })
afterAll(async () => { afterAll(async () => {

View File

@@ -77,7 +77,3 @@ export interface MyGlobal {
updatedAt?: string | null updatedAt?: string | null
createdAt?: string | null createdAt?: string | null
} }
declare module 'payload' {
export interface GeneratedTypes extends Config {}
}

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 type { NextRESTClient } from '../helpers/NextRESTClient.js'
import { getPayload } from '../../packages/payload/src/index.js' import { initPayloadInt } from '../helpers/initPayloadInt.js'
import { NextRESTClient } from '../helpers/NextRESTClient.js'
import { startMemoryDB } from '../startMemoryDB.js'
import configPromise from './config.js' import configPromise from './config.js'
let restClient: NextRESTClient let restClient: NextRESTClient
@@ -10,9 +9,7 @@ let payload: Payload
describe('Custom GraphQL', () => { describe('Custom GraphQL', () => {
beforeAll(async () => { beforeAll(async () => {
const config = await startMemoryDB(configPromise) ;({ payload, restClient } = await initPayloadInt(configPromise))
payload = await getPayload({ config })
restClient = new NextRESTClient(payload.config)
}) })
afterAll(async () => { afterAll(async () => {

View File

@@ -53,7 +53,3 @@ export interface PayloadMigration {
updatedAt: string updatedAt: string
createdAt: string createdAt: string
} }
declare module 'payload' {
export interface GeneratedTypes extends Config {}
}

View File

@@ -8,12 +8,11 @@ import type { TypeWithID } from '../../packages/payload/src/collections/config/t
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 type { PayloadRequest } from '../../packages/payload/src/types/index.js'
import { getPayload } from '../../packages/payload/src/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 { initPayloadInt } from '../helpers/initPayloadInt.js'
import removeFiles from '../helpers/removeFiles.js' import removeFiles from '../helpers/removeFiles.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)
@@ -27,8 +26,7 @@ process.env.PAYLOAD_CONFIG_PATH = path.join(dirname, 'config.ts')
describe('database', () => { describe('database', () => {
beforeAll(async () => { beforeAll(async () => {
const config = await startMemoryDB(configPromise) ;({ payload } = await initPayloadInt(configPromise))
payload = await getPayload({ config })
payload.db.migrationDir = path.join(dirname, './migrations') payload.db.migrationDir = path.join(dirname, './migrations')
const loginResult = await payload.login({ const loginResult = await payload.login({

View File

@@ -84,7 +84,3 @@ export interface PayloadMigration {
updatedAt: string updatedAt: string
createdAt: string createdAt: string
} }
declare module 'payload' {
export interface GeneratedTypes extends Config {}
}

View File

@@ -1,9 +1,8 @@
import type { Payload } from '../../packages/payload/src/index.js' import type { Payload } from '../../packages/payload/src/index.js'
import type { NextRESTClient } from '../helpers/NextRESTClient.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 { initPayloadInt } from '../helpers/initPayloadInt.js'
import { startMemoryDB } from '../startMemoryDB.js'
import configPromise, { postDoc } from './config.js' import configPromise, { postDoc } from './config.js'
let restClient: NextRESTClient let restClient: NextRESTClient
@@ -12,9 +11,7 @@ let token: string
describe('dataloader', () => { describe('dataloader', () => {
beforeAll(async () => { beforeAll(async () => {
const config = await startMemoryDB(configPromise) ;({ payload, restClient } = await initPayloadInt(configPromise))
payload = await getPayload({ config })
restClient = new NextRESTClient(payload.config)
const loginResult = await payload.login({ const loginResult = await payload.login({
collection: 'users', collection: 'users',

View File

@@ -1,6 +1,7 @@
import { type Payload, getPayload } from '../../packages/payload/src/index.js' import type { NextRESTClient } from '../helpers/NextRESTClient.js'
import { NextRESTClient } from '../helpers/NextRESTClient.js'
import { startMemoryDB } from '../startMemoryDB.js' import { type Payload } from '../../packages/payload/src/index.js'
import { initPayloadInt } from '../helpers/initPayloadInt.js'
import configPromise from './config.js' import configPromise from './config.js'
import { import {
applicationEndpoint, applicationEndpoint,
@@ -17,9 +18,7 @@ let restClient: NextRESTClient
describe('Endpoints', () => { describe('Endpoints', () => {
beforeAll(async () => { beforeAll(async () => {
const config = await startMemoryDB(configPromise) ;({ payload, restClient } = await initPayloadInt(configPromise))
payload = await getPayload({ config })
restClient = new NextRESTClient(config)
}) })
afterAll(async () => { afterAll(async () => {

View File

@@ -219,7 +219,3 @@ export interface PayloadMigration {
updatedAt: string updatedAt: string
createdAt: string createdAt: string
} }
declare module 'payload' {
export interface GeneratedTypes extends Config {}
}

View File

@@ -165,7 +165,3 @@ export interface PayloadMigration {
updatedAt: string updatedAt: string
createdAt: string createdAt: string
} }
declare module 'payload' {
export interface GeneratedTypes extends Config {}
}

View File

@@ -3,11 +3,11 @@ 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 { NextRESTClient } from '../helpers/NextRESTClient.js'
import type { GroupField, RichTextField } from './payload-types.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 { devUser } from '../credentials.js' import { devUser } from '../credentials.js'
import { NextRESTClient } from '../helpers/NextRESTClient.js'
import { isMongoose } from '../helpers/isMongoose.js' import { isMongoose } from '../helpers/isMongoose.js'
import { startMemoryDB } from '../startMemoryDB.js' import { startMemoryDB } from '../startMemoryDB.js'
import { arrayDefaultValue } from './collections/Array/index.js' import { arrayDefaultValue } from './collections/Array/index.js'
@@ -39,12 +39,12 @@ import {
let restClient: NextRESTClient let restClient: NextRESTClient
let user: any let user: any
let payload: Payload let payload: Payload
import { initPayloadInt } from '../helpers/initPayloadInt.js'
describe('Fields', () => { describe('Fields', () => {
beforeAll(async () => { beforeAll(async () => {
const config = await startMemoryDB(configPromise) ;({ payload, restClient } = await initPayloadInt(configPromise))
payload = await getPayload({ config })
restClient = new NextRESTClient(payload.config)
await restClient.login({ await restClient.login({
slug: 'users', slug: 'users',
credentials: devUser, credentials: devUser,

View File

@@ -1254,7 +1254,3 @@ export interface LexicalBlocksRadioButtonsBlock {
blockName?: string | null blockName?: string | null
blockType: 'radioButtons' blockType: 'radioButtons'
} }
declare module 'payload' {
export interface GeneratedTypes extends Config {}
}

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 type { NextRESTClient } from '../helpers/NextRESTClient.js'
import { getPayload } from '../../packages/payload/src/index.js' import { initPayloadInt } from '../helpers/initPayloadInt.js'
import { NextRESTClient } from '../helpers/NextRESTClient.js'
import { startMemoryDB } from '../startMemoryDB.js'
import configPromise, { import configPromise, {
accessControlSlug, accessControlSlug,
arraySlug, arraySlug,
@@ -17,9 +16,7 @@ let restClient: NextRESTClient
describe('globals', () => { describe('globals', () => {
beforeAll(async () => { beforeAll(async () => {
const config = await startMemoryDB(configPromise) ;({ payload, restClient } = await initPayloadInt(configPromise))
payload = await getPayload({ config })
restClient = new NextRESTClient(config)
}) })
afterAll(async () => { afterAll(async () => {

View File

@@ -1,15 +1,16 @@
import { promises as _promises } from 'fs' import { promises as _promises } from 'fs'
import { createServer } from 'http' import { createServer } from 'http'
import nextImport from 'next' import nextImport from 'next'
import { startMemoryDB } from 'test/startMemoryDB.js'
import { parse } from 'url' import { parse } from 'url'
import type { SanitizedConfig } from '../../packages/payload/src/config/types.js' import type { SanitizedConfig } from '../../packages/payload/src/config/types.js'
import type { Payload } from '../../packages/payload/src/index.js'
import { getPayloadHMR } from '../../packages/next/src/utilities/getPayloadHMR.js' import { getPayloadHMR } from '../../packages/next/src/utilities/getPayloadHMR.js'
import { type Payload, 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 { createTestHooks } from '../testHooks.js' import { createTestHooks } from '../testHooks.js'
import { NextRESTClient } from './NextRESTClient.js'
type Args = { type Args = {
config: Promise<SanitizedConfig> config: Promise<SanitizedConfig>

View File

@@ -0,0 +1,18 @@
import type { SanitizedConfig } from '../../packages/payload/src/config/types.js'
import { type Payload, getPayload } from '../../packages/payload/src/index.js'
import { startMemoryDB } from '../startMemoryDB.js'
import { NextRESTClient } from './NextRESTClient.js'
/**
* Initialize Payload configured for integration tests
*/
export async function initPayloadInt(
configPromise: Promise<SanitizedConfig>,
): Promise<{ config: SanitizedConfig; payload: Payload; restClient: NextRESTClient }> {
const config = await startMemoryDB(configPromise)
const payload = await getPayload({ config })
const restClient = new NextRESTClient(payload.config)
return { config, payload, restClient }
}

View File

@@ -1,11 +1,10 @@
import type { Payload } from '../../packages/payload/src/index.js' import type { Payload } from '../../packages/payload/src/index.js'
import type { NextRESTClient } from '../helpers/NextRESTClient.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 { initPayloadInt } from '../helpers/initPayloadInt.js'
import { startMemoryDB } from '../startMemoryDB.js'
import { afterOperationSlug } from './collections/AfterOperation/index.js' import { afterOperationSlug } from './collections/AfterOperation/index.js'
import { chainingHooksSlug } from './collections/ChainingHooks/index.js' import { chainingHooksSlug } from './collections/ChainingHooks/index.js'
import { contextHooksSlug } from './collections/ContextHooks/index.js' import { contextHooksSlug } from './collections/ContextHooks/index.js'
@@ -26,9 +25,7 @@ let payload: Payload
describe('Hooks', () => { describe('Hooks', () => {
beforeAll(async () => { beforeAll(async () => {
const config = await startMemoryDB(configPromise) ;({ payload, restClient } = await initPayloadInt(configPromise))
payload = await getPayload({ config })
restClient = new NextRESTClient(payload.config)
}) })
afterAll(async () => { afterAll(async () => {

View File

@@ -8,12 +8,6 @@ beforeAll(async () => {
process.env.PAYLOAD_DISABLE_ADMIN = 'true' process.env.PAYLOAD_DISABLE_ADMIN = 'true'
process.env.PAYLOAD_DROP_DATABASE = 'true' process.env.PAYLOAD_DROP_DATABASE = 'true'
if (process.env.PAYLOAD_DATABASE) {
console.log('\n\nUsing database:', process.env.PAYLOAD_DATABASE)
} else {
console.log('\n\nNo database specified, using default')
}
process.env.PAYLOAD_PUBLIC_CLOUD_STORAGE_ADAPTER = 's3' process.env.PAYLOAD_PUBLIC_CLOUD_STORAGE_ADAPTER = 's3'
afterAll(async () => { afterAll(async () => {

View File

@@ -2,16 +2,14 @@ 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 type { NextRESTClient } from '../helpers/NextRESTClient.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 { startMemoryDB } from '../startMemoryDB.js'
import { Pages } from './collections/Pages.js' 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'
@@ -25,6 +23,8 @@ const schemaJSON = fieldSchemaToJSON(Pages.fields)
let payload: Payload let payload: Payload
let restClient: NextRESTClient let restClient: NextRESTClient
import { initPayloadInt } from '../helpers/initPayloadInt.js'
function collectionPopulationRequestHandler({ endpoint }: { endpoint: string }) { function collectionPopulationRequestHandler({ endpoint }: { endpoint: string }) {
return restClient.GET(`/${endpoint}`) return restClient.GET(`/${endpoint}`)
} }
@@ -37,9 +37,7 @@ describe('Collections - Live Preview', () => {
let media: Media let media: Media
beforeAll(async () => { beforeAll(async () => {
const config = await startMemoryDB(configPromise) ;({ payload, restClient } = await initPayloadInt(configPromise))
payload = await getPayload({ config })
restClient = new NextRESTClient(payload.config)
tenant = await payload.create({ tenant = await payload.create({
collection: tenantsSlug, collection: tenantsSlug,

View File

@@ -1,3 +0,0 @@
{
"extends": "next/core-web-vitals"
}

View File

@@ -457,7 +457,3 @@ export interface Footer {
updatedAt?: string | null updatedAt?: string | null
createdAt?: string | null createdAt?: string | null
} }
declare module 'payload' {
export interface GeneratedTypes extends Config {}
}

View File

@@ -457,7 +457,3 @@ export interface Footer {
updatedAt?: string | null updatedAt?: string | null
createdAt?: string | null createdAt?: string | null
} }
declare module 'payload' {
export interface GeneratedTypes extends Config {}
}

View File

@@ -1,11 +1,12 @@
import type { Payload } from '../../packages/payload/src/index.js' import type { Payload } 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 { NextRESTClient } from '../helpers/NextRESTClient.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 { 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 { idToString } from '../helpers/idToString.js' import { idToString } from '../helpers/idToString.js'
import { initPayloadInt } from '../helpers/initPayloadInt.js'
import { startMemoryDB } from '../startMemoryDB.js' import { startMemoryDB } from '../startMemoryDB.js'
import { arrayCollectionSlug } from './collections/Array/index.js' import { arrayCollectionSlug } from './collections/Array/index.js'
import { nestedToArrayAndBlockCollectionSlug } from './collections/NestedToArrayAndBlock/index.js' import { nestedToArrayAndBlockCollectionSlug } from './collections/NestedToArrayAndBlock/index.js'
@@ -36,9 +37,7 @@ describe('Localization', () => {
let postWithLocalizedData: LocalizedPost let postWithLocalizedData: LocalizedPost
beforeAll(async () => { beforeAll(async () => {
const config = await startMemoryDB(configPromise) ;({ payload, restClient } = await initPayloadInt(configPromise))
payload = await getPayload({ config })
restClient = new NextRESTClient(payload.config)
// @ts-expect-error Force typing // @ts-expect-error Force typing
post1 = await payload.create({ post1 = await payload.create({
@@ -912,8 +911,6 @@ describe('Localization', () => {
}) })
// should return the value of the fallback locale // should return the value of the fallback locale
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
expect(updatedSpanishDoc.items[0].text).toStrictEqual(englishTitle) expect(updatedSpanishDoc.items[0].text).toStrictEqual(englishTitle)
}) })
}) })

View File

@@ -180,7 +180,3 @@ export interface GlobalArray {
updatedAt?: string | null updatedAt?: string | null
createdAt?: string | null createdAt?: string | null
} }
declare module 'payload' {
export interface GeneratedTypes extends Config {}
}

View File

@@ -1,13 +1,11 @@
/* eslint-disable jest/require-top-level-describe */
import * as AWS from '@aws-sdk/client-s3' import * as AWS from '@aws-sdk/client-s3'
import path from 'path' 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 { describeIfInCIOrHasLocalstack } from '../helpers.js' import { describeIfInCIOrHasLocalstack } from '../helpers.js'
import { startMemoryDB } from '../startMemoryDB.js' import { initPayloadInt } from '../helpers/initPayloadInt.js'
import configPromise from './config.js' import configPromise from './config.js'
const filename = fileURLToPath(import.meta.url) const filename = fileURLToPath(import.meta.url)
@@ -17,8 +15,7 @@ let payload: Payload
describe('@payloadcms/plugin-cloud-storage', () => { describe('@payloadcms/plugin-cloud-storage', () => {
beforeAll(async () => { beforeAll(async () => {
const config = await startMemoryDB(configPromise) ;({ payload } = await initPayloadInt(configPromise))
payload = await getPayload({ config })
}) })
afterAll(async () => { afterAll(async () => {

View File

@@ -1,15 +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 { initPayloadInt } from '../helpers/initPayloadInt.js'
import { startMemoryDB } from '../startMemoryDB.js'
import configPromise from './config.js' import configPromise from './config.js'
let payload: Payload let payload: Payload
describe('@payloadcms/plugin-cloud', () => { describe('@payloadcms/plugin-cloud', () => {
beforeAll(async () => { beforeAll(async () => {
const config = await startMemoryDB(configPromise) ;({ payload } = await initPayloadInt(configPromise))
payload = await getPayload({ config })
}) })
afterAll(async () => { afterAll(async () => {

View File

@@ -2,10 +2,9 @@ import type { Payload } 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 { initPayloadInt } from '../helpers/initPayloadInt.js'
import configPromise from './config.js' import configPromise from './config.js'
import { formSubmissionsSlug, formsSlug } from './shared.js' import { formSubmissionsSlug, formsSlug } from './shared.js'
@@ -14,8 +13,7 @@ let form: Form
describe('@payloadcms/plugin-form-builder', () => { describe('@payloadcms/plugin-form-builder', () => {
beforeAll(async () => { beforeAll(async () => {
const config = await startMemoryDB(configPromise) ;({ payload } = await initPayloadInt(configPromise))
payload = await getPayload({ config })
const formConfig: Omit<Form, 'createdAt' | 'id' | 'updatedAt'> = { const formConfig: Omit<Form, 'createdAt' | 'id' | 'updatedAt'> = {
confirmationMessage: [ confirmationMessage: [

View File

@@ -251,7 +251,3 @@ export interface PayloadMigration {
updatedAt: string updatedAt: string
createdAt: string createdAt: string
} }
declare module 'payload' {
export interface GeneratedTypes extends Config {}
}

View File

@@ -5,6 +5,7 @@ import type {
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 { initPayloadInt } from '../helpers/initPayloadInt.js'
import { startMemoryDB } from '../startMemoryDB.js' import { startMemoryDB } from '../startMemoryDB.js'
import configPromise from './config.js' import configPromise from './config.js'
@@ -12,8 +13,7 @@ let payload: Payload
describe('@payloadcms/plugin-nested-docs', () => { describe('@payloadcms/plugin-nested-docs', () => {
beforeAll(async () => { beforeAll(async () => {
const config = await startMemoryDB(configPromise) ;({ payload } = await initPayloadInt(configPromise))
payload = await getPayload({ config })
}) })
afterAll(async () => { afterAll(async () => {

View File

@@ -72,7 +72,3 @@ export interface PayloadMigration {
updatedAt: string updatedAt: string
createdAt: string createdAt: string
} }
declare module 'payload' {
export interface GeneratedTypes extends Config {}
}

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 type { Page } from './payload-types.js' import type { Page } from './payload-types.js'
import { getPayload } from '../../packages/payload/src/index.js' import { initPayloadInt } from '../helpers/initPayloadInt.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'
@@ -11,8 +10,7 @@ let page: Page
describe('@payloadcms/plugin-redirects', () => { describe('@payloadcms/plugin-redirects', () => {
beforeAll(async () => { beforeAll(async () => {
const config = await startMemoryDB(configPromise) ;({ payload } = await initPayloadInt(configPromise))
payload = await getPayload({ config })
page = await payload.create({ page = await payload.create({
collection: 'pages', collection: 'pages',

View File

@@ -77,7 +77,3 @@ export interface PayloadMigration {
updatedAt: string updatedAt: string
createdAt: string createdAt: string
} }
declare module 'payload' {
export interface GeneratedTypes extends Config {}
}

View File

@@ -1,16 +1,14 @@
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 wait from '../../packages/payload/src/utilities/wait.js' import wait from '../../packages/payload/src/utilities/wait.js'
import { startMemoryDB } from '../startMemoryDB.js' import { initPayloadInt } from '../helpers/initPayloadInt.js'
import configPromise from './config.js' import configPromise from './config.js'
let payload: Payload let payload: Payload
describe('@payloadcms/plugin-search', () => { describe('@payloadcms/plugin-search', () => {
beforeAll(async () => { beforeAll(async () => {
const config = await startMemoryDB(configPromise) ;({ payload } = await initPayloadInt(configPromise))
payload = await getPayload({ config })
}) })
afterAll(async () => { afterAll(async () => {

View File

@@ -1,15 +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 { initPayloadInt } from '../helpers/initPayloadInt.js'
import { startMemoryDB } from '../startMemoryDB.js'
import configPromise from './config.js' import configPromise from './config.js'
let payload: Payload let payload: Payload
describe('@payloadcms/plugin-sentry', () => { describe('@payloadcms/plugin-sentry', () => {
beforeAll(async () => { beforeAll(async () => {
const config = await startMemoryDB(configPromise) ;({ payload } = await initPayloadInt(configPromise))
payload = await getPayload({ config })
}) })
afterAll(async () => { afterAll(async () => {

View File

@@ -60,7 +60,3 @@ export interface PayloadMigration {
updatedAt: string updatedAt: string
createdAt: string createdAt: string
} }
declare module 'payload' {
export interface GeneratedTypes extends Config {}
}

View File

@@ -3,10 +3,9 @@ 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 getFileByPath from '../../packages/payload/src/uploads/getFileByPath.js' import getFileByPath from '../../packages/payload/src/uploads/getFileByPath.js'
import { initPayloadInt } from '../helpers/initPayloadInt.js'
import removeFiles from '../helpers/removeFiles.js' import removeFiles from '../helpers/removeFiles.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'
@@ -22,9 +21,7 @@ describe('@payloadcms/plugin-seo', () => {
beforeAll(async () => { beforeAll(async () => {
const uploadsDir = path.resolve(dirname, './media') const uploadsDir = path.resolve(dirname, './media')
removeFiles(path.normalize(uploadsDir)) removeFiles(path.normalize(uploadsDir))
;({ payload } = await initPayloadInt(configPromise))
const config = await startMemoryDB(configPromise)
payload = await getPayload({ config })
// Create image // Create image
const filePath = path.resolve(dirname, './image-1.jpg') const filePath = path.resolve(dirname, './image-1.jpg')

View File

@@ -85,15 +85,3 @@ export interface PayloadMigration {
updatedAt: string updatedAt: string
createdAt: string createdAt: string
} }
declare module 'payload' {
export interface GeneratedTypes {
collections: {
users: User
pages: Page
media: Media
'payload-preferences': PayloadPreference
'payload-migrations': PayloadMigration
}
}
}

View File

@@ -1,15 +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 { initPayloadInt } from '../helpers/initPayloadInt.js'
import { startMemoryDB } from '../startMemoryDB.js'
import configPromise from './config.js' import configPromise from './config.js'
let payload: Payload let payload: Payload
describe('Stripe Plugin', () => { describe('Stripe Plugin', () => {
beforeAll(async () => { beforeAll(async () => {
const config = await startMemoryDB(configPromise) ;({ payload } = await initPayloadInt(configPromise))
payload = await getPayload({ config })
}) })
afterAll(async () => { afterAll(async () => {

View File

@@ -1,15 +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 { initPayloadInt } from '../helpers/initPayloadInt.js'
import { startMemoryDB } from '../startMemoryDB.js'
import configPromise, { pagesSlug } from './config.js' import configPromise, { pagesSlug } from './config.js'
let payload: Payload let payload: Payload
describe('Collections - Plugins', () => { describe('Collections - Plugins', () => {
beforeAll(async () => { beforeAll(async () => {
const config = await startMemoryDB(configPromise) ;({ payload } = await initPayloadInt(configPromise))
payload = await getPayload({ config })
}) })
afterAll(async () => { afterAll(async () => {

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 type { NextRESTClient } from '../helpers/NextRESTClient.js'
import type { import type {
ChainedRelation, ChainedRelation,
CustomIdNumberRelation, CustomIdNumberRelation,
@@ -10,9 +11,7 @@ import type {
Relation, Relation,
} from './payload-types.js' } from './payload-types.js'
import { getPayload } from '../../packages/payload/src/index.js' import { initPayloadInt } from '../helpers/initPayloadInt.js'
import { NextRESTClient } from '../helpers/NextRESTClient.js'
import { startMemoryDB } from '../startMemoryDB.js'
import configPromise from './config.js' import configPromise from './config.js'
import { import {
chainedRelSlug, chainedRelSlug,
@@ -33,9 +32,8 @@ type EasierChained = { id: string; relation: EasierChained }
describe('Relationships', () => { describe('Relationships', () => {
beforeAll(async () => { beforeAll(async () => {
const config = await startMemoryDB(configPromise) ;({ payload, restClient } = await initPayloadInt(configPromise))
payload = await getPayload({ config })
restClient = new NextRESTClient(payload.config)
await restClient.login({ slug: usersSlug }) await restClient.login({ slug: usersSlug })
}) })

View File

@@ -13,8 +13,6 @@ type TestHooks = {
} }
export const createTestHooks = async (testSuiteName = '_community'): Promise<TestHooks> => { export const createTestHooks = async (testSuiteName = '_community'): Promise<TestHooks> => {
console.log('\nUsing config:', testSuiteName, '\n')
const tsConfigPath = path.resolve(dirname, '..', 'tsconfig.json') const tsConfigPath = path.resolve(dirname, '..', 'tsconfig.json')
const tsConfig = await json5.parse(await readFile(tsConfigPath, 'utf8')) const tsConfig = await json5.parse(await readFile(tsConfigPath, 'utf8'))
const originalPayloadConfigTsValue = const originalPayloadConfigTsValue =

View File

@@ -6,11 +6,12 @@ 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 { NextRESTClient } from '../helpers/NextRESTClient.js'
import type { Enlarge, Media } from './payload-types.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 getFileByPath from '../../packages/payload/src/uploads/getFileByPath.js' import getFileByPath from '../../packages/payload/src/uploads/getFileByPath.js'
import { NextRESTClient } from '../helpers/NextRESTClient.js' import { initPayloadInt } from '../helpers/initPayloadInt.js'
import { startMemoryDB } from '../startMemoryDB.js' import { startMemoryDB } from '../startMemoryDB.js'
import configPromise from './config.js' import configPromise from './config.js'
import { import {
@@ -79,9 +80,8 @@ let payload: Payload
describe('Collections - Uploads', () => { describe('Collections - Uploads', () => {
beforeAll(async () => { beforeAll(async () => {
const config = await startMemoryDB(configPromise) ;({ payload, restClient } = await initPayloadInt(configPromise))
payload = await getPayload({ config })
restClient = new NextRESTClient(payload.config)
await restClient.login({ slug: usersSlug }) await restClient.login({ slug: usersSlug })
}) })

View File

@@ -546,30 +546,3 @@ export interface PayloadMigration {
updatedAt: string updatedAt: string
createdAt: string createdAt: string
} }
declare module 'payload' {
export interface GeneratedTypes {
collections: {
relation: Relation
audio: Audio
'gif-resize': GifResize
'no-image-sizes': NoImageSize
'crop-only': CropOnly
'focal-only': FocalOnly
media: Media
enlarge: Enlarge
reduce: Reduce
'media-trim': MediaTrim
'unstored-media': UnstoredMedia
'externally-served-media': ExternallyServedMedia
'uploads-1': Uploads1
'uploads-2': Uploads2
'admin-thumbnail': AdminThumbnail
'optional-file': OptionalFile
'required-file': RequiredFile
users: User
'payload-preferences': PayloadPreference
'payload-migrations': PayloadMigration
}
}
}

View File

@@ -1,9 +1,8 @@
import type { Payload } from '../../packages/payload/src/index.js' import type { Payload } from '../../packages/payload/src/index.js'
import type { NextRESTClient } from '../helpers/NextRESTClient.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 { initPayloadInt } from '../helpers/initPayloadInt.js'
import { startMemoryDB } from '../startMemoryDB.js'
import AutosavePosts from './collections/Autosave.js' import AutosavePosts from './collections/Autosave.js'
import configPromise from './config.js' import configPromise from './config.js'
import AutosaveGlobal from './globals/Autosave.js' import AutosaveGlobal from './globals/Autosave.js'
@@ -35,9 +34,7 @@ const formatGraphQLID = (id: number | string) =>
describe('Versions', () => { describe('Versions', () => {
beforeAll(async () => { beforeAll(async () => {
const config = await startMemoryDB(configPromise) ;({ payload, restClient } = await initPayloadInt(configPromise))
payload = await getPayload({ config })
restClient = new NextRESTClient(payload.config)
const login = ` const login = `
mutation { mutation {