chore: fix payload HMR being run during e2e & int tests

This commit is contained in:
Alessio Gravili
2024-04-02 15:01:18 -04:00
parent 27dba7e4e1
commit 7f674f9861
6 changed files with 12 additions and 10 deletions

View File

@@ -64,8 +64,11 @@ export const getPayloadHMR = async (options: InitOptions): Promise<Payload> => {
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`)

View File

@@ -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)

View File

@@ -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 () => {

View File

@@ -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()

View File

@@ -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 () => {

View File

@@ -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') &&