From baead05ccd8525fae2671764ad367406076db9d4 Mon Sep 17 00:00:00 2001 From: Alessio Gravili Date: Wed, 31 Jul 2024 00:05:38 -0400 Subject: [PATCH] get int test spawnInitProcess scripts to work --- test/_community/int.spec.ts | 8 ++++++-- test/access-control/int.spec.ts | 9 ++++++--- test/admin-root/int.spec.ts | 9 +++++++-- test/array-update/int.spec.ts | 9 +++++++-- test/auth/custom-strategy/int.spec.ts | 9 +++++++-- test/auth/int.spec.ts | 8 ++++++-- test/auth/removed-token/int.spec.ts | 10 ++++++++-- test/collections-graphql/int.spec.ts | 4 ++-- test/collections-rest/int.spec.ts | 9 +++++++-- test/config/int.spec.ts | 9 +++++++-- test/custom-graphql/int.spec.ts | 9 +++++++-- test/database/int.spec.ts | 3 +-- test/dataloader/int.spec.ts | 10 ++++++++-- test/endpoints/int.spec.ts | 8 ++++++-- test/fields/int.spec.ts | 8 ++++++-- test/fields/lexical.int.spec.ts | 9 +++++++-- test/globals/int.spec.ts | 10 ++++++++-- test/helpers/initPayloadInt.ts | 8 +++++++- test/hooks/int.spec.ts | 9 +++++++-- test/live-preview/int.spec.ts | 3 +-- test/localization/int.spec.ts | 9 +++++++-- test/plugin-cloud-storage/int.spec.ts | 3 +-- test/plugin-cloud/int.spec.ts | 9 +++++++-- test/plugin-form-builder/int.spec.ts | 8 ++++++-- test/plugin-nested-docs/int.spec.ts | 9 +++++++-- test/plugin-redirects/int.spec.ts | 9 +++++++-- test/plugin-relationship-object-ids/int.spec.ts | 9 +++++++-- test/plugin-search/int.spec.ts | 8 ++++++-- test/plugin-sentry/int.spec.ts | 9 +++++++-- test/plugin-seo/int.spec.ts | 3 +-- test/plugin-stripe/int.spec.ts | 9 +++++++-- test/plugins/int.spec.ts | 10 ++++++++-- test/relationships/int.spec.ts | 8 ++++++-- test/storage-s3/int.spec.ts | 3 +-- test/uploads/int.spec.ts | 3 +-- test/versions/int.spec.ts | 8 ++++++-- 36 files changed, 206 insertions(+), 72 deletions(-) diff --git a/test/_community/int.spec.ts b/test/_community/int.spec.ts index 3244effde5e..2e4fc730b41 100644 --- a/test/_community/int.spec.ts +++ b/test/_community/int.spec.ts @@ -1,24 +1,28 @@ import type { Payload } from 'payload' +import path from 'path' +import { fileURLToPath } from 'url' + import type { NextRESTClient } from '../helpers/NextRESTClient.js' import { devUser } from '../credentials.js' import { initPayloadInt } from '../helpers/initPayloadInt.js' import { postsSlug } from './collections/Posts/index.js' -import configPromise from './config.js' let payload: Payload let token: string let restClient: NextRESTClient const { email, password } = devUser +const filename = fileURLToPath(import.meta.url) +const dirname = path.dirname(filename) describe('_Community Tests', () => { // --__--__--__--__--__--__--__--__--__ // Boilerplate test setup/teardown // --__--__--__--__--__--__--__--__--__ beforeAll(async () => { - const initialized = await initPayloadInt(configPromise) + const initialized = await initPayloadInt(dirname) ;({ payload, restClient } = initialized) const data = await restClient diff --git a/test/access-control/int.spec.ts b/test/access-control/int.spec.ts index 057c6adc8ee..0fb1140e02e 100644 --- a/test/access-control/int.spec.ts +++ b/test/access-control/int.spec.ts @@ -6,12 +6,14 @@ import type { RequiredDataFromCollectionSlug, } from 'payload' +import path from 'path' import { Forbidden } from 'payload' +import { fileURLToPath } from 'url' import type { FullyRestricted, Post } from './payload-types.js' import { initPayloadInt } from '../helpers/initPayloadInt.js' -import configPromise, { requestHeaders } from './config.js' +import { requestHeaders } from './config.js' import { firstArrayText, fullyRestrictedSlug, @@ -26,13 +28,14 @@ import { } from './shared.js' let payload: Payload - +const filename = fileURLToPath(import.meta.url) +const dirname = path.dirname(filename) describe('Access Control', () => { let post1: Post let restricted: FullyRestricted beforeAll(async () => { - ;({ payload } = await initPayloadInt(configPromise)) + ;({ payload } = await initPayloadInt(dirname)) }) beforeEach(async () => { diff --git a/test/admin-root/int.spec.ts b/test/admin-root/int.spec.ts index fa6d6c9a366..7e16899b905 100644 --- a/test/admin-root/int.spec.ts +++ b/test/admin-root/int.spec.ts @@ -1,11 +1,13 @@ import type { Payload } from 'payload' +import path from 'path' +import { fileURLToPath } from 'url' + import type { NextRESTClient } from '../helpers/NextRESTClient.js' import { devUser } from '../credentials.js' import { initPayloadInt } from '../helpers/initPayloadInt.js' import { postsSlug } from './collections/Posts/index.js' -import configPromise from './config.js' let payload: Payload let token: string @@ -13,12 +15,15 @@ let restClient: NextRESTClient const { email, password } = devUser +const filename = fileURLToPath(import.meta.url) +const dirname = path.dirname(filename) + describe('Admin (Root) Tests', () => { // --__--__--__--__--__--__--__--__--__ // Boilerplate test setup/teardown // --__--__--__--__--__--__--__--__--__ beforeAll(async () => { - const initialized = await initPayloadInt(configPromise) + const initialized = await initPayloadInt(dirname) ;({ payload, restClient } = initialized) const data = await restClient diff --git a/test/array-update/int.spec.ts b/test/array-update/int.spec.ts index 764f1fbf32a..a34948ec68d 100644 --- a/test/array-update/int.spec.ts +++ b/test/array-update/int.spec.ts @@ -1,14 +1,19 @@ import type { Payload } from 'payload' +import path from 'path' +import { fileURLToPath } from 'url' + import { initPayloadInt } from '../helpers/initPayloadInt.js' -import configPromise from './config.js' import { arraySlug } from './shared.js' let payload: Payload +const filename = fileURLToPath(import.meta.url) +const dirname = path.dirname(filename) + describe('array-update', () => { beforeAll(async () => { - ;({ payload } = await initPayloadInt(configPromise)) + ;({ payload } = await initPayloadInt(dirname)) }) afterAll(async () => { diff --git a/test/auth/custom-strategy/int.spec.ts b/test/auth/custom-strategy/int.spec.ts index 329b2d64c1c..7ec4954b1a2 100644 --- a/test/auth/custom-strategy/int.spec.ts +++ b/test/auth/custom-strategy/int.spec.ts @@ -1,9 +1,11 @@ import type { Payload } from 'payload' +import path from 'path' +import { fileURLToPath } from 'url' + import type { NextRESTClient } from '../../helpers/NextRESTClient.js' import { initPayloadInt } from '../../helpers/initPayloadInt.js' -import configPromise from './config.js' import { usersSlug } from './shared.js' let payload: Payload @@ -15,9 +17,12 @@ const headers = { 'Content-Type': 'application/json', } +const filename = fileURLToPath(import.meta.url) +const dirname = path.dirname(filename) + describe('AuthStrategies', () => { beforeAll(async () => { - ;({ payload, restClient } = await initPayloadInt(configPromise)) + ;({ payload, restClient } = await initPayloadInt(dirname)) }) afterAll(async () => { diff --git a/test/auth/int.spec.ts b/test/auth/int.spec.ts index 01b2a6640ee..6e3e07bbfa0 100644 --- a/test/auth/int.spec.ts +++ b/test/auth/int.spec.ts @@ -1,13 +1,14 @@ import type { Payload, User } from 'payload' import { jwtDecode } from 'jwt-decode' +import path from 'path' +import { fileURLToPath } from 'url' import { v4 as uuid } from 'uuid' import type { NextRESTClient } from '../helpers/NextRESTClient.js' import { devUser } from '../credentials.js' import { initPayloadInt } from '../helpers/initPayloadInt.js' -import configPromise from './config.js' import { apiKeysSlug, namedSaveToJWTValue, saveToJWTKey, slug } from './shared.js' let restClient: NextRESTClient @@ -15,9 +16,12 @@ let payload: Payload const { email, password } = devUser +const filename = fileURLToPath(import.meta.url) +const dirname = path.dirname(filename) + describe('Auth', () => { beforeAll(async () => { - ;({ payload, restClient } = await initPayloadInt(configPromise)) + ;({ payload, restClient } = await initPayloadInt(dirname)) }) afterAll(async () => { diff --git a/test/auth/removed-token/int.spec.ts b/test/auth/removed-token/int.spec.ts index 1add6941255..5c6458ffbc2 100644 --- a/test/auth/removed-token/int.spec.ts +++ b/test/auth/removed-token/int.spec.ts @@ -1,17 +1,23 @@ import type { Payload } from 'payload' +import path from 'path' +import { fileURLToPath } from 'url' + import type { NextRESTClient } from '../../helpers/NextRESTClient.js' import { devUser } from '../../credentials.js' import { initPayloadInt } from '../../helpers/initPayloadInt.js' -import config, { collectionSlug } from './config.js' +import { collectionSlug } from './config.js' let restClient: NextRESTClient let payload: Payload +const filename = fileURLToPath(import.meta.url) +const dirname = path.dirname(filename) + describe('Remove token from auth responses', () => { beforeAll(async () => { - ;({ payload, restClient } = await initPayloadInt(config)) + ;({ payload, restClient } = await initPayloadInt(dirname)) await restClient.POST(`/${collectionSlug}/first-register`, { body: JSON.stringify({ ...devUser, 'confirm-password': devUser.password }), diff --git a/test/collections-graphql/int.spec.ts b/test/collections-graphql/int.spec.ts index 4379d35f6ce..dacdca859af 100644 --- a/test/collections-graphql/int.spec.ts +++ b/test/collections-graphql/int.spec.ts @@ -9,7 +9,7 @@ import type { Post } from './payload-types.js' import { idToString } from '../helpers/idToString.js' import { initPayloadInt } from '../helpers/initPayloadInt.js' -import config, { errorOnHookSlug, pointSlug, relationSlug, slug } from './config.js' +import { errorOnHookSlug, pointSlug, relationSlug, slug } from './config.js' const title = 'title' @@ -21,7 +21,7 @@ const dirname = path.dirname(filename) describe('collections-graphql', () => { beforeAll(async () => { - ;({ payload, restClient } = await initPayloadInt(config)) + ;({ payload, restClient } = await initPayloadInt(dirname)) // Wait for indexes to be created, // as we need them to query by point diff --git a/test/collections-rest/int.spec.ts b/test/collections-rest/int.spec.ts index 727484ab116..4eb40347f5c 100644 --- a/test/collections-rest/int.spec.ts +++ b/test/collections-rest/int.spec.ts @@ -1,13 +1,15 @@ import type { Payload } from 'payload' import { randomBytes } from 'crypto' +import path from 'path' +import { fileURLToPath } from 'url' import type { NextRESTClient } from '../helpers/NextRESTClient.js' import type { Relation } from './config.js' import type { Post } from './payload-types.js' import { initPayloadInt } from '../helpers/initPayloadInt.js' -import config, { +import { customIdNumberSlug, customIdSlug, errorOnHookSlug, @@ -16,12 +18,15 @@ import config, { slug, } from './config.js' +const filename = fileURLToPath(import.meta.url) +const dirname = path.dirname(filename) + let restClient: NextRESTClient let payload: Payload describe('collections-rest', () => { beforeAll(async () => { - ;({ payload, restClient } = await initPayloadInt(config)) + ;({ payload, restClient } = await initPayloadInt(dirname)) // Wait for indexes to be created, // as we need them to query by point diff --git a/test/config/int.spec.ts b/test/config/int.spec.ts index 455e36f9a2a..c6750ad690a 100644 --- a/test/config/int.spec.ts +++ b/test/config/int.spec.ts @@ -1,16 +1,21 @@ import type { BlockField, Payload } from 'payload' +import path from 'path' +import { fileURLToPath } from 'url' + import type { NextRESTClient } from '../helpers/NextRESTClient.js' import { initPayloadInt } from '../helpers/initPayloadInt.js' -import configPromise from './config.js' let restClient: NextRESTClient let payload: Payload +const filename = fileURLToPath(import.meta.url) +const dirname = path.dirname(filename) + describe('Config', () => { beforeAll(async () => { - ;({ payload, restClient } = await initPayloadInt(configPromise)) + ;({ payload, restClient } = await initPayloadInt(dirname)) }) afterAll(async () => { diff --git a/test/custom-graphql/int.spec.ts b/test/custom-graphql/int.spec.ts index 5e09e270436..016cb2107d8 100644 --- a/test/custom-graphql/int.spec.ts +++ b/test/custom-graphql/int.spec.ts @@ -1,16 +1,21 @@ import type { Payload } from 'payload' +import path from 'path' +import { fileURLToPath } from 'url' + import type { NextRESTClient } from '../helpers/NextRESTClient.js' import { initPayloadInt } from '../helpers/initPayloadInt.js' -import configPromise from './config.js' let restClient: NextRESTClient let payload: Payload +const filename = fileURLToPath(import.meta.url) +const dirname = path.dirname(filename) + describe('Custom GraphQL', () => { beforeAll(async () => { - ;({ payload, restClient } = await initPayloadInt(configPromise)) + ;({ payload, restClient } = await initPayloadInt(dirname)) }) afterAll(async () => { diff --git a/test/database/int.spec.ts b/test/database/int.spec.ts index 2c969f16b34..d11fbccc362 100644 --- a/test/database/int.spec.ts +++ b/test/database/int.spec.ts @@ -10,7 +10,6 @@ import { fileURLToPath } from 'url' import { devUser } from '../credentials.js' import { initPayloadInt } from '../helpers/initPayloadInt.js' import removeFiles from '../helpers/removeFiles.js' -import configPromise from './config.js' const filename = fileURLToPath(import.meta.url) const dirname = path.dirname(filename) @@ -25,7 +24,7 @@ process.env.PAYLOAD_CONFIG_PATH = path.join(dirname, 'config.ts') describe('database', () => { beforeAll(async () => { - ;({ payload, restClient } = await initPayloadInt(configPromise)) + ;({ payload, restClient } = await initPayloadInt(dirname)) payload.db.migrationDir = path.join(dirname, './migrations') const loginResult = await payload.login({ diff --git a/test/dataloader/int.spec.ts b/test/dataloader/int.spec.ts index 638089df6ee..9917c8582e3 100644 --- a/test/dataloader/int.spec.ts +++ b/test/dataloader/int.spec.ts @@ -1,18 +1,24 @@ import type { Payload } from 'payload' +import path from 'path' +import { fileURLToPath } from 'url' + import type { NextRESTClient } from '../helpers/NextRESTClient.js' import { devUser } from '../credentials.js' import { initPayloadInt } from '../helpers/initPayloadInt.js' -import configPromise, { postDoc } from './config.js' +import { postDoc } from './config.js' let restClient: NextRESTClient let payload: Payload let token: string +const filename = fileURLToPath(import.meta.url) +const dirname = path.dirname(filename) + describe('dataloader', () => { beforeAll(async () => { - ;({ payload, restClient } = await initPayloadInt(configPromise)) + ;({ payload, restClient } = await initPayloadInt(dirname)) const loginResult = await payload.login({ collection: 'users', diff --git a/test/endpoints/int.spec.ts b/test/endpoints/int.spec.ts index 62130ff02cd..ee91929ed3b 100644 --- a/test/endpoints/int.spec.ts +++ b/test/endpoints/int.spec.ts @@ -1,9 +1,10 @@ +import path from 'path' import { type Payload } from 'payload' +import { fileURLToPath } from 'url' import type { NextRESTClient } from '../helpers/NextRESTClient.js' import { initPayloadInt } from '../helpers/initPayloadInt.js' -import configPromise from './config.js' import { applicationEndpoint, collectionSlug, @@ -17,9 +18,12 @@ import { let payload: Payload let restClient: NextRESTClient +const filename = fileURLToPath(import.meta.url) +const dirname = path.dirname(filename) + describe('Endpoints', () => { beforeAll(async () => { - ;({ payload, restClient } = await initPayloadInt(configPromise)) + ;({ payload, restClient } = await initPayloadInt(dirname)) }) afterAll(async () => { diff --git a/test/fields/int.spec.ts b/test/fields/int.spec.ts index 1691ead0798..a6435434b21 100644 --- a/test/fields/int.spec.ts +++ b/test/fields/int.spec.ts @@ -3,6 +3,8 @@ import type { IndexDirection, IndexOptions } from 'mongoose' import type { PaginatedDocs, Payload } from 'payload' import { reload } from '@payloadcms/next/utilities' +import path from 'path' +import { fileURLToPath } from 'url' import type { NextRESTClient } from '../helpers/NextRESTClient.js' import type { GroupField, RichTextField } from './payload-types.js' @@ -25,7 +27,6 @@ import { } from './collections/Tabs/constants.js' import { tabsDoc } from './collections/Tabs/shared.js' import { defaultText } from './collections/Text/shared.js' -import configPromise from './config.js' import { clearAndSeedEverything } from './seed.js' import { arrayFieldsSlug, @@ -40,10 +41,13 @@ let restClient: NextRESTClient let user: any let payload: Payload +const filename = fileURLToPath(import.meta.url) +const dirname = path.dirname(filename) + describe('Fields', () => { beforeAll(async () => { process.env.SEED_IN_CONFIG_ONINIT = 'false' // Makes it so the payload config onInit seed is not run. Otherwise, the seed would be run unnecessarily twice for the initial test run - once for beforeEach and once for onInit - ;({ payload, restClient } = await initPayloadInt(configPromise)) + ;({ payload, restClient } = await initPayloadInt(dirname)) }) afterAll(async () => { diff --git a/test/fields/lexical.int.spec.ts b/test/fields/lexical.int.spec.ts index d603151cab9..c543eb30507 100644 --- a/test/fields/lexical.int.spec.ts +++ b/test/fields/lexical.int.spec.ts @@ -7,6 +7,9 @@ import type { import type { SerializedEditorState, SerializedParagraphNode } from 'lexical' import type { PaginatedDocs, Payload } from 'payload' +import path from 'path' +import { fileURLToPath } from 'url' + import type { LexicalField, LexicalMigrateField, RichTextField } from './payload-types.js' import { devUser } from '../credentials.js' @@ -20,7 +23,6 @@ import { richTextDocData } from './collections/RichText/data.js' import { generateLexicalRichText } from './collections/RichText/generateLexicalRichText.js' import { textDoc } from './collections/Text/shared.js' import { uploadsDoc } from './collections/Upload/shared.js' -import configPromise from './config.js' import { clearAndSeedEverything } from './seed.js' import { arrayFieldsSlug, @@ -39,10 +41,13 @@ let createdJPGDocID: number | string = null let createdTextDocID: number | string = null let createdRichTextDocID: number | string = null +const filename = fileURLToPath(import.meta.url) +const dirname = path.dirname(filename) + describe('Lexical', () => { beforeAll(async () => { process.env.SEED_IN_CONFIG_ONINIT = 'false' // Makes it so the payload config onInit seed is not run. Otherwise, the seed would be run unnecessarily twice for the initial test run - once for beforeEach and once for onInit - ;({ payload, restClient } = await initPayloadInt(configPromise)) + ;({ payload, restClient } = await initPayloadInt(dirname)) }) beforeEach(async () => { diff --git a/test/globals/int.spec.ts b/test/globals/int.spec.ts index 82167a6f1f6..943e45f46a7 100644 --- a/test/globals/int.spec.ts +++ b/test/globals/int.spec.ts @@ -1,9 +1,12 @@ import type { Payload } from 'payload' +import path from 'path' +import { fileURLToPath } from 'url' + import type { NextRESTClient } from '../helpers/NextRESTClient.js' import { initPayloadInt } from '../helpers/initPayloadInt.js' -import configPromise, { +import { accessControlSlug, arraySlug, defaultValueSlug, @@ -15,9 +18,12 @@ import configPromise, { let payload: Payload let restClient: NextRESTClient +const filename = fileURLToPath(import.meta.url) +const dirname = path.dirname(filename) + describe('globals', () => { beforeAll(async () => { - ;({ payload, restClient } = await initPayloadInt(configPromise)) + ;({ payload, restClient } = await initPayloadInt(dirname)) }) afterAll(async () => { diff --git a/test/helpers/initPayloadInt.ts b/test/helpers/initPayloadInt.ts index 696c5039c63..54083ec6e01 100644 --- a/test/helpers/initPayloadInt.ts +++ b/test/helpers/initPayloadInt.ts @@ -1,15 +1,21 @@ import type { Payload, SanitizedConfig } from 'payload' import { getPayloadHMR } from '@payloadcms/next/utilities' +import path from 'path' +import { spawnInitProcess } from '../spawnInitProcess.js' import { NextRESTClient } from './NextRESTClient.js' /** * Initialize Payload configured for integration tests */ export async function initPayloadInt( - config: Promise, + dirname: string, ): Promise<{ config: SanitizedConfig; payload: Payload; restClient: NextRESTClient }> { + const testSuiteName = path.basename(dirname) + await spawnInitProcess(testSuiteName) + const { default: config } = await import(path.resolve(dirname, 'config.ts')) + const payload = await getPayloadHMR({ config }) const restClient = new NextRESTClient(payload.config) diff --git a/test/hooks/int.spec.ts b/test/hooks/int.spec.ts index e365fd9b4f5..fdf12f95aa7 100644 --- a/test/hooks/int.spec.ts +++ b/test/hooks/int.spec.ts @@ -1,6 +1,8 @@ import type { Payload } from 'payload' +import path from 'path' import { AuthenticationError } from 'payload' +import { fileURLToPath } from 'url' import type { NextRESTClient } from '../helpers/NextRESTClient.js' @@ -19,15 +21,18 @@ import { import { relationsSlug } from './collections/Relations/index.js' import { transformSlug } from './collections/Transform/index.js' import { hooksUsersSlug } from './collections/Users/index.js' -import configPromise, { HooksConfig } from './config.js' +import { HooksConfig } from './config.js' import { dataHooksGlobalSlug } from './globals/Data/index.js' let restClient: NextRESTClient let payload: Payload +const filename = fileURLToPath(import.meta.url) +const dirname = path.dirname(filename) + describe('Hooks', () => { beforeAll(async () => { - ;({ payload, restClient } = await initPayloadInt(configPromise)) + ;({ payload, restClient } = await initPayloadInt(dirname)) }) afterAll(async () => { diff --git a/test/live-preview/int.spec.ts b/test/live-preview/int.spec.ts index 3127b1b1aa3..f7854e0e13c 100644 --- a/test/live-preview/int.spec.ts +++ b/test/live-preview/int.spec.ts @@ -10,7 +10,6 @@ import type { NextRESTClient } from '../helpers/NextRESTClient.js' import type { Media, Page, Post, Tenant } from './payload-types.js' import { Pages } from './collections/Pages.js' -import configPromise from './config.js' import { postsSlug, tenantsSlug } from './shared.js' const filename = fileURLToPath(import.meta.url) @@ -35,7 +34,7 @@ describe('Collections - Live Preview', () => { let media: Media beforeAll(async () => { - ;({ payload, restClient } = await initPayloadInt(configPromise)) + ;({ payload, restClient } = await initPayloadInt(dirname)) tenant = await payload.create({ collection: tenantsSlug, diff --git a/test/localization/int.spec.ts b/test/localization/int.spec.ts index 9c012733256..f6fda137e06 100644 --- a/test/localization/int.spec.ts +++ b/test/localization/int.spec.ts @@ -1,5 +1,8 @@ import type { Payload, Where } from 'payload' +import path from 'path' +import { fileURLToPath } from 'url' + import type { NextRESTClient } from '../helpers/NextRESTClient.js' import type { LocalizedPost, WithLocalizedRelationship } from './payload-types.js' @@ -10,7 +13,6 @@ import { arrayCollectionSlug } from './collections/Array/index.js' import { groupSlug } from './collections/Group/index.js' import { nestedToArrayAndBlockCollectionSlug } from './collections/NestedToArrayAndBlock/index.js' import { tabSlug } from './collections/Tab/index.js' -import configPromise from './config.js' import { defaultLocale, englishTitle, @@ -33,12 +35,15 @@ const collection = localizedPostsSlug let payload: Payload let restClient: NextRESTClient +const filename = fileURLToPath(import.meta.url) +const dirname = path.dirname(filename) + describe('Localization', () => { let post1: LocalizedPost let postWithLocalizedData: LocalizedPost beforeAll(async () => { - ;({ payload, restClient } = await initPayloadInt(configPromise)) + ;({ payload, restClient } = await initPayloadInt(dirname)) post1 = await payload.create({ collection, diff --git a/test/plugin-cloud-storage/int.spec.ts b/test/plugin-cloud-storage/int.spec.ts index bb834e4104e..6d60b794055 100644 --- a/test/plugin-cloud-storage/int.spec.ts +++ b/test/plugin-cloud-storage/int.spec.ts @@ -8,7 +8,6 @@ import type { Config } from './payload-types.js' import { describeIfInCIOrHasLocalstack } from '../helpers.js' import { initPayloadInt } from '../helpers/initPayloadInt.js' -import configPromise from './config.js' import { mediaSlug, mediaWithPrefixSlug, prefix } from './shared.js' import { clearTestBucket, createTestBucket } from './utils.js' @@ -19,7 +18,7 @@ let payload: Payload describe('@payloadcms/plugin-cloud-storage', () => { beforeAll(async () => { - ;({ payload } = await initPayloadInt(configPromise)) + ;({ payload } = await initPayloadInt(dirname)) }) afterAll(async () => { diff --git a/test/plugin-cloud/int.spec.ts b/test/plugin-cloud/int.spec.ts index f04d3e63dbe..322d8c4d8f0 100644 --- a/test/plugin-cloud/int.spec.ts +++ b/test/plugin-cloud/int.spec.ts @@ -1,13 +1,18 @@ import type { Payload } from 'payload' +import path from 'path' +import { fileURLToPath } from 'url' + import { initPayloadInt } from '../helpers/initPayloadInt.js' -import configPromise from './config.js' let payload: Payload +const filename = fileURLToPath(import.meta.url) +const dirname = path.dirname(filename) + describe('@payloadcms/plugin-cloud', () => { beforeAll(async () => { - ;({ payload } = await initPayloadInt(configPromise)) + ;({ payload } = await initPayloadInt(dirname)) }) afterAll(async () => { diff --git a/test/plugin-form-builder/int.spec.ts b/test/plugin-form-builder/int.spec.ts index 428e0c4deca..df3aa3df6ef 100644 --- a/test/plugin-form-builder/int.spec.ts +++ b/test/plugin-form-builder/int.spec.ts @@ -1,21 +1,25 @@ import type { Payload } from 'payload' +import path from 'path' import { ValidationError } from 'payload' +import { fileURLToPath } from 'url' import type { Form } from './payload-types.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 { initPayloadInt } from '../helpers/initPayloadInt.js' -import configPromise from './config.js' import { formSubmissionsSlug, formsSlug } from './shared.js' let payload: Payload let form: Form +const filename = fileURLToPath(import.meta.url) +const dirname = path.dirname(filename) + describe('@payloadcms/plugin-form-builder', () => { beforeAll(async () => { - ;({ payload } = await initPayloadInt(configPromise)) + ;({ payload } = await initPayloadInt(dirname)) const formConfig: Omit = { confirmationMessage: [ diff --git a/test/plugin-nested-docs/int.spec.ts b/test/plugin-nested-docs/int.spec.ts index 01472a81b16..340913f59dd 100644 --- a/test/plugin-nested-docs/int.spec.ts +++ b/test/plugin-nested-docs/int.spec.ts @@ -1,13 +1,18 @@ import type { ArrayField, Payload, RelationshipField } from 'payload' +import path from 'path' +import { fileURLToPath } from 'url' + import { initPayloadInt } from '../helpers/initPayloadInt.js' -import configPromise from './config.js' let payload: Payload +const filename = fileURLToPath(import.meta.url) +const dirname = path.dirname(filename) + describe('@payloadcms/plugin-nested-docs', () => { beforeAll(async () => { - ;({ payload } = await initPayloadInt(configPromise)) + ;({ payload } = await initPayloadInt(dirname)) }) afterAll(async () => { diff --git a/test/plugin-redirects/int.spec.ts b/test/plugin-redirects/int.spec.ts index 5020590325d..7a61d5ed4d9 100644 --- a/test/plugin-redirects/int.spec.ts +++ b/test/plugin-redirects/int.spec.ts @@ -1,17 +1,22 @@ import type { Payload } from 'payload' +import path from 'path' +import { fileURLToPath } from 'url' + import type { Page } from './payload-types.js' import { initPayloadInt } from '../helpers/initPayloadInt.js' -import configPromise from './config.js' import { pagesSlug } from './shared.js' let payload: Payload let page: Page +const filename = fileURLToPath(import.meta.url) +const dirname = path.dirname(filename) + describe('@payloadcms/plugin-redirects', () => { beforeAll(async () => { - ;({ payload } = await initPayloadInt(configPromise)) + ;({ payload } = await initPayloadInt(dirname)) page = await payload.create({ collection: 'pages', diff --git a/test/plugin-relationship-object-ids/int.spec.ts b/test/plugin-relationship-object-ids/int.spec.ts index d0dd49e8e56..aab6ab1e9c9 100644 --- a/test/plugin-relationship-object-ids/int.spec.ts +++ b/test/plugin-relationship-object-ids/int.spec.ts @@ -1,9 +1,14 @@ import type { Payload } from 'payload' +import path from 'path' +import { fileURLToPath } from 'url' + import type { Post, Relation } from './payload-types.js' import { initPayloadInt } from '../helpers/initPayloadInt.js' -import configPromise from './config.js' + +const filename = fileURLToPath(import.meta.url) +const dirname = path.dirname(filename) describe('Relationship Object IDs Plugin', () => { let relations: Relation[] @@ -11,7 +16,7 @@ describe('Relationship Object IDs Plugin', () => { let payload: Payload beforeAll(async () => { - ;({ payload } = await initPayloadInt(configPromise)) + ;({ payload } = await initPayloadInt(dirname)) }) it('seeds data accordingly', async () => { diff --git a/test/plugin-search/int.spec.ts b/test/plugin-search/int.spec.ts index 32a29f66479..96580ee3050 100644 --- a/test/plugin-search/int.spec.ts +++ b/test/plugin-search/int.spec.ts @@ -1,15 +1,19 @@ import type { Payload } from 'payload' +import path from 'path' import { wait } from 'payload/shared' +import { fileURLToPath } from 'url' import { initPayloadInt } from '../helpers/initPayloadInt.js' -import configPromise from './config.js' let payload: Payload +const filename = fileURLToPath(import.meta.url) +const dirname = path.dirname(filename) + describe('@payloadcms/plugin-search', () => { beforeAll(async () => { - ;({ payload } = await initPayloadInt(configPromise)) + ;({ payload } = await initPayloadInt(dirname)) }) afterAll(async () => { diff --git a/test/plugin-sentry/int.spec.ts b/test/plugin-sentry/int.spec.ts index a293289712f..65908e269c7 100644 --- a/test/plugin-sentry/int.spec.ts +++ b/test/plugin-sentry/int.spec.ts @@ -1,13 +1,18 @@ import type { Payload } from 'payload' +import path from 'path' +import { fileURLToPath } from 'url' + import { initPayloadInt } from '../helpers/initPayloadInt.js' -import configPromise from './config.js' let payload: Payload +const filename = fileURLToPath(import.meta.url) +const dirname = path.dirname(filename) + describe('@payloadcms/plugin-sentry', () => { beforeAll(async () => { - ;({ payload } = await initPayloadInt(configPromise)) + ;({ payload } = await initPayloadInt(dirname)) }) afterAll(async () => { diff --git a/test/plugin-seo/int.spec.ts b/test/plugin-seo/int.spec.ts index 11a5d164b5e..5a04f776e49 100644 --- a/test/plugin-seo/int.spec.ts +++ b/test/plugin-seo/int.spec.ts @@ -6,7 +6,6 @@ import { fileURLToPath } from 'url' import { initPayloadInt } from '../helpers/initPayloadInt.js' import removeFiles from '../helpers/removeFiles.js' -import configPromise from './config.js' import { mediaSlug } from './shared.js' const filename = fileURLToPath(import.meta.url) @@ -21,7 +20,7 @@ describe('@payloadcms/plugin-seo', () => { beforeAll(async () => { const uploadsDir = path.resolve(dirname, './media') removeFiles(path.normalize(uploadsDir)) - ;({ payload } = await initPayloadInt(configPromise)) + ;({ payload } = await initPayloadInt(dirname)) // Create image const filePath = path.resolve(dirname, './image-1.jpg') diff --git a/test/plugin-stripe/int.spec.ts b/test/plugin-stripe/int.spec.ts index 82e3604bc6f..c875a3e9bf5 100644 --- a/test/plugin-stripe/int.spec.ts +++ b/test/plugin-stripe/int.spec.ts @@ -1,13 +1,18 @@ import type { Payload } from 'payload' +import path from 'path' +import { fileURLToPath } from 'url' + import { initPayloadInt } from '../helpers/initPayloadInt.js' -import configPromise from './config.js' let payload: Payload +const filename = fileURLToPath(import.meta.url) +const dirname = path.dirname(filename) + describe('Stripe Plugin', () => { beforeAll(async () => { - ;({ payload } = await initPayloadInt(configPromise)) + ;({ payload } = await initPayloadInt(dirname)) }) afterAll(async () => { diff --git a/test/plugins/int.spec.ts b/test/plugins/int.spec.ts index 637fe37ab8c..e185d369175 100644 --- a/test/plugins/int.spec.ts +++ b/test/plugins/int.spec.ts @@ -1,13 +1,19 @@ import type { Payload } from 'payload' +import path from 'path' +import { fileURLToPath } from 'url' + import { initPayloadInt } from '../helpers/initPayloadInt.js' -import configPromise, { pagesSlug } from './config.js' +import { pagesSlug } from './config.js' let payload: Payload +const filename = fileURLToPath(import.meta.url) +const dirname = path.dirname(filename) + describe('Collections - Plugins', () => { beforeAll(async () => { - ;({ payload } = await initPayloadInt(configPromise)) + ;({ payload } = await initPayloadInt(dirname)) }) afterAll(async () => { diff --git a/test/relationships/int.spec.ts b/test/relationships/int.spec.ts index 516b12b4fa3..3bc68e4a85d 100644 --- a/test/relationships/int.spec.ts +++ b/test/relationships/int.spec.ts @@ -1,6 +1,8 @@ import type { Payload, PayloadRequest } from 'payload' import { randomBytes } from 'crypto' +import path from 'path' +import { fileURLToPath } from 'url' import type { NextRESTClient } from '../helpers/NextRESTClient.js' import type { @@ -14,7 +16,6 @@ import type { } from './payload-types.js' import { initPayloadInt } from '../helpers/initPayloadInt.js' -import configPromise from './config.js' import { chainedRelSlug, customIdNumberSlug, @@ -31,11 +32,14 @@ import { let restClient: NextRESTClient let payload: Payload +const filename = fileURLToPath(import.meta.url) +const dirname = path.dirname(filename) + type EasierChained = { id: string; relation: EasierChained } describe('Relationships', () => { beforeAll(async () => { - ;({ payload, restClient } = await initPayloadInt(configPromise)) + ;({ payload, restClient } = await initPayloadInt(dirname)) await restClient.login({ slug: usersSlug }) }) diff --git a/test/storage-s3/int.spec.ts b/test/storage-s3/int.spec.ts index 2209fbe32a5..4bfa84576ca 100644 --- a/test/storage-s3/int.spec.ts +++ b/test/storage-s3/int.spec.ts @@ -5,7 +5,6 @@ import path from 'path' import { fileURLToPath } from 'url' import { initPayloadInt } from '../helpers/initPayloadInt.js' -import configPromise from './config.js' import { mediaSlug, mediaWithPrefixSlug, prefix } from './shared.js' const filename = fileURLToPath(import.meta.url) @@ -18,7 +17,7 @@ describe('@payloadcms/storage-s3', () => { let client: AWS.S3Client beforeAll(async () => { - ;({ payload } = await initPayloadInt(configPromise)) + ;({ payload } = await initPayloadInt(dirname)) client = new AWS.S3({ endpoint: process.env.S3_ENDPOINT, diff --git a/test/uploads/int.spec.ts b/test/uploads/int.spec.ts index 93d893da95f..ce7279347d7 100644 --- a/test/uploads/int.spec.ts +++ b/test/uploads/int.spec.ts @@ -10,7 +10,6 @@ import type { NextRESTClient } from '../helpers/NextRESTClient.js' import type { Enlarge, Media } from './payload-types.js' import { initPayloadInt } from '../helpers/initPayloadInt.js' -import configPromise from './config.js' import { createStreamableFile } from './createStreamableFile.js' import { enlargeSlug, @@ -32,7 +31,7 @@ let payload: Payload describe('Collections - Uploads', () => { beforeAll(async () => { - ;({ payload, restClient } = await initPayloadInt(configPromise)) + ;({ payload, restClient } = await initPayloadInt(dirname)) await restClient.login({ slug: usersSlug }) }) diff --git a/test/versions/int.spec.ts b/test/versions/int.spec.ts index c4c68cab6ca..3cba411547c 100644 --- a/test/versions/int.spec.ts +++ b/test/versions/int.spec.ts @@ -1,6 +1,8 @@ import type { Payload } from 'payload' +import path from 'path' import { ValidationError } from 'payload' +import { fileURLToPath } from 'url' import type { NextRESTClient } from '../helpers/NextRESTClient.js' @@ -8,7 +10,6 @@ import { devUser } from '../credentials.js' import { initPayloadInt } from '../helpers/initPayloadInt.js' import { clearAndSeedEverything } from './clearAndSeedEverything.js' import AutosavePosts from './collections/Autosave.js' -import configPromise from './config.js' import AutosaveGlobal from './globals/Autosave.js' import { autosaveCollectionSlug, draftCollectionSlug } from './slugs.js' @@ -32,13 +33,16 @@ let globalGraphQLVersionID const globalGraphQLOriginalTitle = 'updated global title' const updatedTitle = 'Here is an updated post title in EN' +const filename = fileURLToPath(import.meta.url) +const dirname = path.dirname(filename) + const formatGraphQLID = (id: number | string) => payload.db.defaultIDType === 'number' ? id : `"${id}"` describe('Versions', () => { beforeAll(async () => { process.env.SEED_IN_CONFIG_ONINIT = 'false' // Makes it so the payload config onInit seed is not run. Otherwise, the seed would be run unnecessarily twice for the initial test run - once for beforeEach and once for onInit - ;({ payload, restClient } = await initPayloadInt(configPromise)) + ;({ payload, restClient } = await initPayloadInt(dirname)) }) afterAll(async () => {