chore: use initPayloadInt consistently in all int test suites and do not init payload twice
This commit is contained in:
@@ -21,7 +21,7 @@ export const getPayloadHMR = async (options: InitOptions): Promise<Payload> => {
|
||||
}
|
||||
|
||||
if (cached.payload) {
|
||||
const config = await options.config
|
||||
const config = await options.config // TODO: check if we can move this inside the cached.reload === true condition
|
||||
|
||||
if (cached.reload === true) {
|
||||
let resolve
|
||||
@@ -65,6 +65,7 @@ export const getPayloadHMR = async (options: InitOptions): Promise<Payload> => {
|
||||
cached.payload = await cached.promise
|
||||
|
||||
if (process.env.NODE_ENV !== 'production' && process.env.NODE_ENV !== 'test') {
|
||||
console.log('6792364')
|
||||
try {
|
||||
const port = process.env.PORT || '3000'
|
||||
const ws = new WebSocket(`ws://localhost:${port}/_next/webpack-hmr`)
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import type { Payload } from 'payload'
|
||||
|
||||
import { getPayload } from 'payload'
|
||||
import type { NextRESTClient } from '../../helpers/NextRESTClient.js'
|
||||
|
||||
import { NextRESTClient } from '../../helpers/NextRESTClient.js'
|
||||
import { initPayloadInt } from '../../helpers/initPayloadInt.js'
|
||||
import config from './config.js'
|
||||
import { usersSlug } from './shared.js'
|
||||
|
||||
@@ -17,8 +17,7 @@ const headers = {
|
||||
|
||||
describe('AuthStrategies', () => {
|
||||
beforeAll(async () => {
|
||||
payload = await getPayload({ config })
|
||||
restClient = new NextRESTClient(payload.config)
|
||||
;({ payload, restClient } = await initPayloadInt(config))
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import type { Payload } from 'payload'
|
||||
|
||||
import { getPayload } from 'payload'
|
||||
import type { NextRESTClient } from '../../helpers/NextRESTClient.js'
|
||||
|
||||
import { devUser } from '../../credentials.js'
|
||||
import { NextRESTClient } from '../../helpers/NextRESTClient.js'
|
||||
import { initPayloadInt } from '../../helpers/initPayloadInt.js'
|
||||
import config, { collectionSlug } from './config.js'
|
||||
|
||||
let restClient: NextRESTClient
|
||||
@@ -11,8 +11,7 @@ let payload: Payload
|
||||
|
||||
describe('Remove token from auth responses', () => {
|
||||
beforeAll(async () => {
|
||||
payload = await getPayload({ config })
|
||||
restClient = new NextRESTClient(payload.config)
|
||||
;({ payload, restClient } = await initPayloadInt(config))
|
||||
|
||||
await restClient.POST(`/${collectionSlug}/first-register`, {
|
||||
body: JSON.stringify(devUser),
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
import type { Payload } from 'payload'
|
||||
|
||||
import { getPayload } from 'payload'
|
||||
import { mapAsync } from 'payload/utilities'
|
||||
|
||||
import type { NextRESTClient } from '../helpers/NextRESTClient.js'
|
||||
import type { Post } from './payload-types.js'
|
||||
|
||||
import { NextRESTClient } from '../helpers/NextRESTClient.js'
|
||||
import { idToString } from '../helpers/idToString.js'
|
||||
import { initPayloadInt } from '../helpers/initPayloadInt.js'
|
||||
import config, { errorOnHookSlug, pointSlug, relationSlug, slug } from './config.js'
|
||||
@@ -19,9 +18,6 @@ describe('collections-graphql', () => {
|
||||
beforeAll(async () => {
|
||||
;({ payload, restClient } = await initPayloadInt(config))
|
||||
|
||||
payload = await getPayload({ config })
|
||||
restClient = new NextRESTClient(payload.config)
|
||||
|
||||
// Wait for indexes to be created,
|
||||
// as we need them to query by point
|
||||
if (payload.db.name === 'mongoose') {
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import type { Payload } from 'payload'
|
||||
|
||||
import { randomBytes } from 'crypto'
|
||||
import { getPayload } from 'payload'
|
||||
import { mapAsync } from 'payload/utilities'
|
||||
|
||||
import type { NextRESTClient } from '../helpers/NextRESTClient.js'
|
||||
import type { Relation } from './config.js'
|
||||
import type { Post } from './payload-types.js'
|
||||
|
||||
import { NextRESTClient } from '../helpers/NextRESTClient.js'
|
||||
import { initPayloadInt } from '../helpers/initPayloadInt.js'
|
||||
import config, {
|
||||
customIdNumberSlug,
|
||||
customIdSlug,
|
||||
@@ -22,8 +22,7 @@ let payload: Payload
|
||||
|
||||
describe('collections-rest', () => {
|
||||
beforeAll(async () => {
|
||||
payload = await getPayload({ config })
|
||||
restClient = new NextRESTClient(payload.config)
|
||||
;({ payload, restClient } = await initPayloadInt(config))
|
||||
|
||||
// Wait for indexes to be created,
|
||||
// as we need them to query by point
|
||||
|
||||
@@ -8,12 +8,11 @@ import type { SerializedEditorState, SerializedParagraphNode } from 'lexical'
|
||||
import type { Payload } from 'payload'
|
||||
import type { PaginatedDocs } from 'payload/database'
|
||||
|
||||
import { getPayload } from 'payload'
|
||||
|
||||
import type { LexicalField, LexicalMigrateField, RichTextField } from './payload-types.js'
|
||||
|
||||
import { devUser } from '../credentials.js'
|
||||
import { NextRESTClient } from '../helpers/NextRESTClient.js'
|
||||
import { initPayloadInt } from '../helpers/initPayloadInt.js'
|
||||
import { arrayDoc } from './collections/Array/shared.js'
|
||||
import { lexicalDocData } from './collections/Lexical/data.js'
|
||||
import { lexicalMigrateDocData } from './collections/LexicalMigrate/data.js'
|
||||
@@ -44,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 = await getPayload({ config })
|
||||
;({ payload, restClient } = await initPayloadInt(config))
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import type { SanitizedConfig } from 'payload/config'
|
||||
|
||||
import { type Payload, getPayload } from 'payload'
|
||||
import { getPayloadHMR } from '@payloadcms/next/utilities'
|
||||
import { type Payload } from 'payload'
|
||||
|
||||
import { NextRESTClient } from './NextRESTClient.js'
|
||||
|
||||
@@ -10,7 +11,7 @@ import { NextRESTClient } from './NextRESTClient.js'
|
||||
export async function initPayloadInt(
|
||||
config: Promise<SanitizedConfig>,
|
||||
): Promise<{ config: SanitizedConfig; payload: Payload; restClient: NextRESTClient }> {
|
||||
const payload = await getPayload({ config })
|
||||
const payload = await getPayloadHMR({ config })
|
||||
const restClient = new NextRESTClient(payload.config)
|
||||
|
||||
return { config: payload.config, payload, restClient }
|
||||
|
||||
@@ -4,7 +4,6 @@ import { File as FileBuffer } from 'buffer'
|
||||
import NodeFormData from 'form-data'
|
||||
import fs from 'fs'
|
||||
import path from 'path'
|
||||
import { getPayload } from 'payload'
|
||||
import { getFileByPath } from 'payload/uploads'
|
||||
import { fileURLToPath } from 'url'
|
||||
import { promisify } from 'util'
|
||||
@@ -13,7 +12,6 @@ import type { NextRESTClient } from '../helpers/NextRESTClient.js'
|
||||
import type { Enlarge, Media } from './payload-types.js'
|
||||
|
||||
import { initPayloadInt } from '../helpers/initPayloadInt.js'
|
||||
import { startMemoryDB } from '../startMemoryDB.js'
|
||||
import configPromise from './config.js'
|
||||
import {
|
||||
enlargeSlug,
|
||||
|
||||
Reference in New Issue
Block a user