From 7f674f98612ca2377a354fc01751a12f8ed4d34c Mon Sep 17 00:00:00 2001 From: Alessio Gravili Date: Tue, 2 Apr 2024 15:01:18 -0400 Subject: [PATCH] chore: fix payload HMR being run during e2e & int tests --- packages/next/src/utilities/getPayloadHMR.ts | 7 +++++-- test/admin/e2e.spec.ts | 3 +-- test/auth/custom-strategy/int.spec.ts | 4 ++-- test/fields/e2e.spec.ts | 3 +-- test/fields/lexical.int.spec.ts | 4 ++-- test/helpers/startMemoryDB.ts | 1 + 6 files changed, 12 insertions(+), 10 deletions(-) diff --git a/packages/next/src/utilities/getPayloadHMR.ts b/packages/next/src/utilities/getPayloadHMR.ts index b23a64d6b..d6ef9a35d 100644 --- a/packages/next/src/utilities/getPayloadHMR.ts +++ b/packages/next/src/utilities/getPayloadHMR.ts @@ -64,8 +64,11 @@ export const getPayloadHMR = async (options: InitOptions): Promise => { try { cached.payload = await cached.promise - if (process.env.NODE_ENV !== 'production' && process.env.NODE_ENV !== 'test') { - console.log('6792364') + if ( + process.env.NODE_ENV !== 'production' && + process.env.NODE_ENV !== 'test' && + process.env.DISABLE_PAYLOAD_HMR !== 'true' + ) { try { const port = process.env.PORT || '3000' const ws = new WebSocket(`ws://localhost:${port}/_next/webpack-hmr`) diff --git a/test/admin/e2e.spec.ts b/test/admin/e2e.spec.ts index d7cf726ee..89bbfe067 100644 --- a/test/admin/e2e.spec.ts +++ b/test/admin/e2e.spec.ts @@ -20,7 +20,6 @@ import { } from '../helpers.js' import { AdminUrlUtil } from '../helpers/adminUrlUtil.js' import { initPayloadE2E } from '../helpers/initPayloadE2E.js' -import config from './config.js' import { clearAndSeedEverything } from './seed.js' import { customEditLabel, @@ -68,7 +67,7 @@ describe('admin', () => { beforeAll(async ({ browser }) => { 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, serverURL } = await initPayloadE2E({ config, dirname })) + ;({ payload, serverURL } = await initPayloadE2E({ dirname })) geoUrl = new AdminUrlUtil(serverURL, geoCollectionSlug) url = new AdminUrlUtil(serverURL, postsCollectionSlug) customViewsURL = new AdminUrlUtil(serverURL, customViews2CollectionSlug) diff --git a/test/auth/custom-strategy/int.spec.ts b/test/auth/custom-strategy/int.spec.ts index cf87fe34c..2ce5d8ff0 100644 --- a/test/auth/custom-strategy/int.spec.ts +++ b/test/auth/custom-strategy/int.spec.ts @@ -3,7 +3,7 @@ import type { Payload } from 'payload' import type { NextRESTClient } from '../../helpers/NextRESTClient.js' import { initPayloadInt } from '../../helpers/initPayloadInt.js' -import config from './config.js' +import configPromise from './config.js' import { usersSlug } from './shared.js' let payload: Payload @@ -17,7 +17,7 @@ const headers = { describe('AuthStrategies', () => { beforeAll(async () => { - ;({ payload, restClient } = await initPayloadInt(config)) + ;({ payload, restClient } = await initPayloadInt(configPromise)) }) afterAll(async () => { diff --git a/test/fields/e2e.spec.ts b/test/fields/e2e.spec.ts index c0aa20926..605bf1cbb 100644 --- a/test/fields/e2e.spec.ts +++ b/test/fields/e2e.spec.ts @@ -21,7 +21,6 @@ import { POLL_TOPASS_TIMEOUT } from '../playwright.config.js' import { jsonDoc } from './collections/JSON/shared.js' import { numberDoc } from './collections/Number/shared.js' import { textDoc } from './collections/Text/shared.js' -import config from './config.js' import { clearAndSeedEverything } from './seed.js' import { collapsibleFieldsSlug, @@ -44,7 +43,7 @@ let serverURL: string describe('fields', () => { beforeAll(async ({ browser }) => { 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, serverURL } = await initPayloadE2E({ config, dirname })) + ;({ payload, serverURL } = await initPayloadE2E({ dirname })) const context = await browser.newContext() page = await context.newPage() diff --git a/test/fields/lexical.int.spec.ts b/test/fields/lexical.int.spec.ts index 1219ee8ed..86042cd37 100644 --- a/test/fields/lexical.int.spec.ts +++ b/test/fields/lexical.int.spec.ts @@ -20,7 +20,7 @@ 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 config from './config.js' +import configPromise from './config.js' import { clearAndSeedEverything } from './seed.js' import { arrayFieldsSlug, @@ -43,7 +43,7 @@ let createdRichTextDocID: number | string = null 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(config)) + ;({ payload, restClient } = await initPayloadInt(configPromise)) }) beforeEach(async () => { diff --git a/test/helpers/startMemoryDB.ts b/test/helpers/startMemoryDB.ts index 89e8091f7..7244302da 100644 --- a/test/helpers/startMemoryDB.ts +++ b/test/helpers/startMemoryDB.ts @@ -6,6 +6,7 @@ export default async () => { process.env.NODE_ENV = 'test' process.env.PAYLOAD_DROP_DATABASE = 'true' process.env.NODE_OPTIONS = '--no-deprecation' + process.env.DISABLE_PAYLOAD_HMR = 'true' if ( (!process.env.PAYLOAD_DATABASE || process.env.PAYLOAD_DATABASE === 'mongodb') &&