Files
payload/test/helpers/initPayloadInt.ts
James Mikrut 31b32ef941 feat: deprecates getPayloadHMR in favor of simpler getPayload (#9249)
Deprecates `getPayloadHMR` and simplifies this pattern into a single
`import { getPayload } from 'payload'`.

We will still retain the exported `getPayloadHMR` but it now will throw
a deprecation warning with instructions for how to migrate.
2024-11-16 15:30:05 -05:00

28 lines
996 B
TypeScript

import type { Payload, SanitizedConfig } from 'payload'
import path from 'path'
import { getPayload } from 'payload'
import { runInit } from '../runInit.js'
import { NextRESTClient } from './NextRESTClient.js'
/**
* Initialize Payload configured for integration tests
*/
export async function initPayloadInt(
dirname: string,
testSuiteNameOverride?: string,
): Promise<{ config: SanitizedConfig; payload: Payload; restClient: NextRESTClient }> {
const testSuiteName = testSuiteNameOverride ?? path.basename(dirname)
await runInit(testSuiteName, false, true)
console.log('importing config', path.resolve(dirname, 'config.ts'))
const { default: config } = await import(path.resolve(dirname, 'config.ts'))
console.log('starting payload')
const payload = await getPayload({ config })
console.log('initializing rest client')
const restClient = new NextRESTClient(payload.config)
console.log('initPayloadInt done')
return { config: payload.config, payload, restClient }
}